21 lines
509 B
TypeScript
21 lines
509 B
TypeScript
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;
|
|
}
|
|
} |