feat: SW-158 Magic Link login support

This commit is contained in:
Hrishikesh Vaipurkar
2024-07-10 11:34:09 +02:00
parent 2ce21626b9
commit e14e3aaffa
2 changed files with 28 additions and 15 deletions

View File

@@ -1,3 +1,4 @@
import { encode } from "@auth/core/jwt"
import { NextRequest, NextResponse } from "next/server"
import { AuthError } from "next-auth"
@@ -6,7 +7,6 @@ import { env } from "@/env/server"
import { internalServerError } from "@/server/errors/next"
import { signIn } from "@/auth"
// import { encode } from "@auth/core/jwt"
export async function GET(
request: NextRequest,
@@ -59,19 +59,26 @@ export async function GET(
if (redirectUrl) {
// Check if needed based on discussion with Curity support for custom nonce
// const token = { value };
// const secret = env.NEXTAUTH_SECRET;
// const maxAge = 60 * 15;
// const name = "authjs.nonce";
// const testingCookie = await encode({ secret, maxAge, token, salt: name });
// console.log(testingCookie);
// const expires = new Date();
// expires.setTime(expires.getTime() + maxAge * 1000);
// redirectHeaders.append(
// "set-cookie",
// "authjs.nonce=" + testingCookie + "; Expires=" + expires + "; Path=/; HttpOnly; SameSite=Lax"
// )
// redirectUrl = redirectUrl.replace(/nonce=.*&code_challenge=/gi, "nonce="+value+"&code_challenge=");
const token = { value }
const secret = env.NEXTAUTH_SECRET
const maxAge = 60 * 15
const name = "authjs.nonce"
const testingCookie = await encode({ secret, maxAge, token, salt: name })
console.log(testingCookie)
const expires = new Date()
expires.setTime(expires.getTime() + maxAge * 1000)
redirectHeaders.append(
"set-cookie",
"authjs.nonce=" +
testingCookie +
"; Expires=" +
expires +
"; Path=/; HttpOnly; SameSite=Lax"
)
redirectUrl = redirectUrl.replace(
/nonce=.*&code_challenge=/gi,
"nonce=" + value + "&code_challenge="
)
return NextResponse.redirect(redirectUrl, {
headers: redirectHeaders,