feat: SW-158 Optimized code
This commit is contained in:
@@ -123,11 +123,6 @@ export async function GET(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (redirectUrl) {
|
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, {
|
return NextResponse.redirect(redirectUrl, {
|
||||||
headers: redirectHeaders,
|
headers: redirectHeaders,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from "next/server"
|
|||||||
import { AuthError } from "next-auth"
|
import { AuthError } from "next-auth"
|
||||||
|
|
||||||
import { Lang } from "@/constants/languages"
|
import { Lang } from "@/constants/languages"
|
||||||
|
import { login } from "@/constants/routes/handleAuth"
|
||||||
import { env } from "@/env/server"
|
import { env } from "@/env/server"
|
||||||
import { internalServerError } from "@/server/errors/next"
|
import { internalServerError } from "@/server/errors/next"
|
||||||
|
|
||||||
@@ -11,12 +12,10 @@ export async function GET(
|
|||||||
request: NextRequest,
|
request: NextRequest,
|
||||||
context: { params: { lang: Lang } }
|
context: { params: { lang: Lang } }
|
||||||
) {
|
) {
|
||||||
let redirectHeaders: Headers | undefined = undefined
|
|
||||||
let redirectTo: string
|
let redirectTo: string
|
||||||
let loginKey: string
|
let loginKey: string | null
|
||||||
|
|
||||||
redirectTo =
|
redirectTo = request.cookies.get("Scandic-auth.callback-url")?.value || "/" // Cookie gets set by NextAuth from login initiation
|
||||||
request.cookies.get("Scandic-auth.callback-url")?.value || "/" // Cookie gets set by NextAuth from login initiation
|
|
||||||
|
|
||||||
// Make relative URL to absolute URL
|
// Make relative URL to absolute URL
|
||||||
if (redirectTo.startsWith("/")) {
|
if (redirectTo.startsWith("/")) {
|
||||||
@@ -33,7 +32,17 @@ export async function GET(
|
|||||||
redirectTo.substring(redirectTo.indexOf("returnurl") + 10)
|
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 {
|
try {
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user