Spaces:
Build error
Build error
File size: 737 Bytes
7e5cb25 |
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 |
import jwt from "jsonwebtoken"
import db from "@/utils/db"
export async function GET(request) {
const searchParams = request.nextUrl.searchParams
const token = searchParams.get("token")
console.log("token", token)
const { userId } = jwt.verify(token, process.env.JWT_SECRET)
const [userObj] =
await db`UPDATE users SET confirmed = true WHERE id = ${userId} RETURNING *`
const longLivedToken = jwt.sign(
{
userId: userObj.id,
exp: Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 30, // 1 month
},
process.env.JWT_SECRET
)
return new Response(null, {
status: 302,
headers: {
"Set-Cookie": `token=${longLivedToken}; path=/; HttpOnly`,
Location: `/prompts`,
},
})
}
|