mirror of
https://github.com/DerTyp7/f1r3wave-website.git
synced 2025-10-29 21:17:09 +01:00
Removed next-auth and refactored authentication
This commit is contained in:
@@ -1,35 +1,8 @@
|
||||
'use server';
|
||||
|
||||
import { signIn, signOut } from '@/auth';
|
||||
import { AuthError } from 'next-auth';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
export async function authenticate(_prevState: string | undefined, formData: FormData): Promise<string> {
|
||||
try {
|
||||
const result = await signIn('credentials', {
|
||||
redirect: false,
|
||||
token: formData.get('token'),
|
||||
});
|
||||
|
||||
if (result?.error) {
|
||||
return 'Invalid token';
|
||||
}
|
||||
|
||||
redirect('/admin');
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError) {
|
||||
switch (error.type) {
|
||||
case 'CredentialsSignin':
|
||||
return 'Invalid token';
|
||||
default:
|
||||
return 'Something went wrong';
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function performLogout() {
|
||||
await signOut({ redirectTo: '/', redirect: true });
|
||||
redirect('/');
|
||||
export async function deleteSessionCookie() {
|
||||
const cookieStore = await cookies();
|
||||
cookieStore.delete('session');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user