chore: track Payload web application

This commit is contained in:
AHMED
2026-10-09 15:44:19 +03:00
parent e10491ad1c
commit 690c2deed7
124 changed files with 20205 additions and 0 deletions
@@ -0,0 +1,34 @@
import { NextResponse } from 'next/server'
import { getPayload } from 'payload'
import { headers } from 'next/headers'
import { randomBytes } from 'crypto'
import configPromise from '@payload-config'
import { sendVerificationEmail } from '@/lib/mail'
export const dynamic = 'force-dynamic'
/* POST /api/auth/resend-verification — logged-in user asks for a fresh
verification email. Regenerates the token so old links die. */
export async function POST() {
const payload = await getPayload({ config: configPromise })
const { user } = await payload.auth({ headers: await headers() })
if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
if (user.emailVerified) return NextResponse.json({ already: true })
const token = randomBytes(32).toString('hex')
await payload.update({
collection: 'users',
id: user.id,
data: { verificationToken: token },
overrideAccess: true,
})
const { sent } = await sendVerificationEmail(user.email, token)
if (!sent) {
return NextResponse.json(
{ error: 'خدمة البريد غير مربوطة بعد — ستعمل تلقائياً بعد ضبط SMTP على الاستضافة.' },
{ status: 503 },
)
}
return NextResponse.json({ sent: true })
}