feat: implement authentication system with email verification, user management dashboard, and administrative business controls
Some checks failed
Build and Push App / build (push) Failing after 1m9s
Some checks failed
Build and Push App / build (push) Failing after 1m9s
This commit is contained in:
35
app/api/auth/verify/route.ts
Normal file
35
app/api/auth/verify/route.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import prisma from '@/lib/prisma';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const token = searchParams.get('token');
|
||||
|
||||
if (!token) {
|
||||
return NextResponse.redirect(new URL('/login?error=Token manquant', request.url));
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { verificationToken: token }
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
return NextResponse.redirect(new URL('/login?error=Token invalide ou expiré', request.url));
|
||||
}
|
||||
|
||||
await prisma.user.update({
|
||||
where: { id: user.id },
|
||||
data: {
|
||||
emailVerified: true,
|
||||
verificationToken: null
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.redirect(new URL('/login?verified=true', request.url));
|
||||
|
||||
} catch (error) {
|
||||
console.error('Verification error:', error);
|
||||
return NextResponse.redirect(new URL('/login?error=Erreur de vérification', request.url));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user