feat: integrate NextAuth.js for authentication, update database service to use better-sqlite3 adapter, and enhance header component with user session management
This commit is contained in:
4
src/app/api/auth/[...nextauth]/route.ts
Normal file
4
src/app/api/auth/[...nextauth]/route.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { handlers } from '@/lib/auth';
|
||||
|
||||
export const { GET, POST } = handlers;
|
||||
|
||||
25
src/app/api/auth/register/route.ts
Normal file
25
src/app/api/auth/register/route.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { registerUser } from '@/services/auth';
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { email, password, name } = body;
|
||||
|
||||
if (!email || !password) {
|
||||
return NextResponse.json({ error: 'Email et mot de passe requis' }, { status: 400 });
|
||||
}
|
||||
|
||||
const result = await registerUser({ email, password, name });
|
||||
|
||||
if (!result.success) {
|
||||
return NextResponse.json({ error: result.error }, { status: 400 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ user: result.user }, { status: 201 });
|
||||
} catch (error) {
|
||||
console.error('Registration error:', error);
|
||||
return NextResponse.json({ error: 'Erreur lors de la création du compte' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user