add authentication with next-auth

This commit is contained in:
Michi 2025-04-26 16:56:09 +02:00
parent 5487bccd8d
commit 759acde045
11 changed files with 318 additions and 98 deletions

View file

@ -4,9 +4,30 @@ import { z } from 'zod';
import { revalidatePath } from 'next/cache';
import { redirect } from 'next/navigation';
import postgres from 'postgres';
import { signIn } from '@/auth';
import { AuthError } from 'next-auth';
const sql = postgres(process.env.POSTGRES_URL!, {ssl: 'require'});
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;
}
}
const FormSchema = z.object({
id: z.string(),
customerId: z.string({