- lib/auth.ts: hashPassword(password) geëxporteerd (bcrypt, rounds=12) - actions/auth.ts: resetPasswordAction met Zod-validatie (min 8, superRefine gelijkheid), prisma.user.update (password_hash + must_reset_password=false), redirect /dashboard - app/(auth)/reset-password/page.tsx: server guard (userId check + must_reset_password check) - app/(auth)/reset-password/reset-form.tsx: client form (nieuw wachtwoord + bevestiging) - __tests__/actions/auth.test.ts: 3 tests voor resetPasswordAction
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { redirect } from 'next/navigation'
|
|
import { getSession } from '@/lib/auth'
|
|
import { prisma } from '@/lib/prisma'
|
|
import { ResetPasswordForm } from './reset-form'
|
|
|
|
export default async function ResetPasswordPage() {
|
|
const session = await getSession()
|
|
if (!session.userId) {
|
|
redirect('/login')
|
|
}
|
|
|
|
const user = await prisma.user.findUnique({
|
|
where: { id: session.userId },
|
|
select: { must_reset_password: true },
|
|
})
|
|
|
|
if (!user?.must_reset_password) {
|
|
redirect('/dashboard')
|
|
}
|
|
|
|
return (
|
|
<main className="min-h-screen bg-background flex items-center justify-center p-4">
|
|
<div className="w-full max-w-sm space-y-6">
|
|
<div className="text-center space-y-1">
|
|
<h1 className="text-2xl font-medium text-foreground">Wachtwoord wijzigen</h1>
|
|
<p className="text-sm text-muted-foreground">
|
|
Kies een nieuw wachtwoord om verder te gaan.
|
|
</p>
|
|
</div>
|
|
|
|
<div className="bg-surface-container-low rounded-xl p-6 space-y-4 border border-border">
|
|
<ResetPasswordForm />
|
|
</div>
|
|
</div>
|
|
</main>
|
|
)
|
|
}
|