fix(auth): clean up
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
import { createActionURL } from "@auth/core"
|
||||
import { headers as nextHeaders } from "next/headers"
|
||||
import { NextRequest, NextResponse } from "next/server"
|
||||
import { AuthError } from "next-auth"
|
||||
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { env } from "@/env/server"
|
||||
import { badRequest } from "@/server/errors/next"
|
||||
import { badRequest, internalServerError } from "@/server/errors/next"
|
||||
|
||||
import { signIn } from "@/auth"
|
||||
|
||||
@@ -26,17 +24,14 @@ export async function GET(
|
||||
request.cookies.get("redirectTo")?.value || // Cookie gets set by authRequired middleware
|
||||
request.headers.get("x-redirect-to") ||
|
||||
request.nextUrl.searchParams.get("redirectTo") ||
|
||||
request.headers.get("Referer") ||
|
||||
""
|
||||
|
||||
// If above fails, always redirect to startpage
|
||||
if (!redirectTo) {
|
||||
const proto = request.headers.get("x-forwarded-proto") ?? "http"
|
||||
const host =
|
||||
request.headers.get("x-forwarded-host") ??
|
||||
request.headers.get("host") ??
|
||||
env.URL
|
||||
redirectTo = `${proto}://${host}/`
|
||||
if (!env.PUBLIC_URL) {
|
||||
throw internalServerError("No value for env.PUBLIC_URL")
|
||||
}
|
||||
redirectTo = env.PUBLIC_URL
|
||||
console.log({ login_fallback: redirectTo })
|
||||
}
|
||||
|
||||
@@ -87,20 +82,9 @@ export async function GET(
|
||||
* automatically redirecting to it inside of `signIn`.
|
||||
* https://github.com/nextauthjs/next-auth/blob/3c035ec/packages/next-auth/src/lib/actions.ts#L76
|
||||
*/
|
||||
console.log({ login_AUTH_URL: process.env.AUTH_URL })
|
||||
console.log({ login_NEXTAUTH_URL: process.env.NEXTAUTH_URL })
|
||||
console.log({ login_env: process.env })
|
||||
|
||||
const headers = new Headers(nextHeaders())
|
||||
const signInURL = createActionURL(
|
||||
"signin",
|
||||
// @ts-expect-error `x-forwarded-proto` is not nullable, next.js sets it by default
|
||||
headers.get("x-forwarded-proto"),
|
||||
headers,
|
||||
process.env
|
||||
)
|
||||
console.log({ login_signInURL: signInURL })
|
||||
|
||||
console.log({ login_redirectTo: redirectTo })
|
||||
const redirectUrl = await signIn(
|
||||
"curity",
|
||||
|
||||
Reference in New Issue
Block a user