feat: SW-158 Optimized code
This commit is contained in:
@@ -123,11 +123,6 @@ export async function GET(
|
||||
)
|
||||
|
||||
if (redirectUrl) {
|
||||
// Remove nonce for User to be able to login via Magic Link, but normal login fails as nonce becomes absent in the token response
|
||||
// if (redirectUrl.indexOf("nonce") != -1) {
|
||||
// redirectUrl = redirectUrl.replace(/nonce=.*&code_challenge=/gi, "&code_challenge=");
|
||||
// redirectUrl = redirectUrl.replace(/&nonce=.*/gi, "");
|
||||
// }
|
||||
return NextResponse.redirect(redirectUrl, {
|
||||
headers: redirectHeaders,
|
||||
})
|
||||
|
||||
@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from "next/server"
|
||||
import { AuthError } from "next-auth"
|
||||
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { login } from "@/constants/routes/handleAuth"
|
||||
import { env } from "@/env/server"
|
||||
import { internalServerError } from "@/server/errors/next"
|
||||
|
||||
@@ -11,12 +12,10 @@ export async function GET(
|
||||
request: NextRequest,
|
||||
context: { params: { lang: Lang } }
|
||||
) {
|
||||
let redirectHeaders: Headers | undefined = undefined
|
||||
let redirectTo: string
|
||||
let loginKey: string
|
||||
let loginKey: string | null
|
||||
|
||||
redirectTo =
|
||||
request.cookies.get("Scandic-auth.callback-url")?.value || "/" // Cookie gets set by NextAuth from login initiation
|
||||
redirectTo = request.cookies.get("Scandic-auth.callback-url")?.value || "/" // Cookie gets set by NextAuth from login initiation
|
||||
|
||||
// Make relative URL to absolute URL
|
||||
if (redirectTo.startsWith("/")) {
|
||||
@@ -33,7 +32,17 @@ export async function GET(
|
||||
redirectTo.substring(redirectTo.indexOf("returnurl") + 10)
|
||||
)
|
||||
}
|
||||
loginKey = "" + request.nextUrl.searchParams.get("loginKey")?.toString()
|
||||
|
||||
loginKey = request.nextUrl.searchParams.get("loginKey")
|
||||
|
||||
if (!loginKey) {
|
||||
if (!env.PUBLIC_URL) {
|
||||
throw internalServerError("No value for env.PUBLIC_URL")
|
||||
}
|
||||
const publicUrl = new URL(env.PUBLIC_URL)
|
||||
const loginUrl = login[context.params.lang]
|
||||
return NextResponse.redirect(new URL(loginUrl, publicUrl))
|
||||
}
|
||||
|
||||
try {
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user