implemented login

This commit is contained in:
2024-01-06 10:50:27 +01:00
parent 60a89b88ac
commit 52d4c35c2e
14 changed files with 257 additions and 35 deletions

21
app/lib/loginActions.ts Normal file
View File

@@ -0,0 +1,21 @@
import { signIn } from '@/auth';
import { AuthError } from 'next-auth';
export async function authenticate(
prevState: string | undefined,
formData: FormData,
) {
try {
await signIn('credentials', formData);
} catch (error) {
if (error instanceof AuthError) {
switch (error.type) {
case 'CredentialsSignin':
return 'Invalid credentials.';
default:
return 'Something went wrong.';
}
}
throw error;
}
}