Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { db } from '@/lib/db'
import { randomUUID } from 'crypto';
import { redirect } from 'next/navigation'
import { NextRequest } from 'next/server'
export async function GET(
_request: NextRequest,
{
params,
}: {
params: { token: string }
}
) {
const { token } = params
const user = await db.user.findFirst({
where: {
ActivationToken: {
some: {
AND: [
{
activationDate: null,
},
{
createdAt: {
gt: new Date(Date.now() - 24 * 60 * 60 * 1000), // 24 hours ago
},
},
{
token
},
],
},
},
},
})
if (!user) {
throw new Error('Token is invalid or expired')
}
await db.user.update({
where: {
id: user.id,
},
data: {
},
})
await db.activationToken.update({
where: {
token,
},
data: {
activationDate: new Date(),
},
})