mirror of
https://github.com/DerTyp7/f1r3wave-website.git
synced 2025-10-29 13:02:09 +01:00
first commit
This commit is contained in:
30
src/lib/actions.ts
Normal file
30
src/lib/actions.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
'use server';
|
||||
|
||||
import { signIn } from '@/auth';
|
||||
import { AuthError } from 'next-auth';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
export async function authenticate(_prevState: string | undefined, formData: FormData): Promise<string> {
|
||||
try {
|
||||
await signIn('credentials', formData);
|
||||
return 'success';
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError) {
|
||||
switch (error.type) {
|
||||
case 'CredentialsSignin':
|
||||
return 'Invalid token';
|
||||
default:
|
||||
return 'Something went wrong';
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function logout() {
|
||||
const c = await cookies();
|
||||
|
||||
c.delete('authjs.session-token');
|
||||
c.delete('authjs.csrf-token');
|
||||
c.delete('authjs.callback-url');
|
||||
}
|
||||
Reference in New Issue
Block a user