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 { 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 { env } from "@/env/server"
|
import { env } from "@/env/server"
|
||||||
import { badRequest } from "@/server/errors/next"
|
import { badRequest, internalServerError } from "@/server/errors/next"
|
||||||
|
|
||||||
import { signIn } from "@/auth"
|
import { signIn } from "@/auth"
|
||||||
|
|
||||||
@@ -26,17 +24,14 @@ export async function GET(
|
|||||||
request.cookies.get("redirectTo")?.value || // Cookie gets set by authRequired middleware
|
request.cookies.get("redirectTo")?.value || // Cookie gets set by authRequired middleware
|
||||||
request.headers.get("x-redirect-to") ||
|
request.headers.get("x-redirect-to") ||
|
||||||
request.nextUrl.searchParams.get("redirectTo") ||
|
request.nextUrl.searchParams.get("redirectTo") ||
|
||||||
request.headers.get("Referer") ||
|
|
||||||
""
|
""
|
||||||
|
|
||||||
// If above fails, always redirect to startpage
|
// If above fails, always redirect to startpage
|
||||||
if (!redirectTo) {
|
if (!redirectTo) {
|
||||||
const proto = request.headers.get("x-forwarded-proto") ?? "http"
|
if (!env.PUBLIC_URL) {
|
||||||
const host =
|
throw internalServerError("No value for env.PUBLIC_URL")
|
||||||
request.headers.get("x-forwarded-host") ??
|
}
|
||||||
request.headers.get("host") ??
|
redirectTo = env.PUBLIC_URL
|
||||||
env.URL
|
|
||||||
redirectTo = `${proto}://${host}/`
|
|
||||||
console.log({ login_fallback: redirectTo })
|
console.log({ login_fallback: redirectTo })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,20 +82,9 @@ export async function GET(
|
|||||||
* automatically redirecting to it inside of `signIn`.
|
* automatically redirecting to it inside of `signIn`.
|
||||||
* https://github.com/nextauthjs/next-auth/blob/3c035ec/packages/next-auth/src/lib/actions.ts#L76
|
* 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_NEXTAUTH_URL: process.env.NEXTAUTH_URL })
|
||||||
console.log({ login_env: process.env })
|
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 })
|
console.log({ login_redirectTo: redirectTo })
|
||||||
const redirectUrl = await signIn(
|
const redirectUrl = await signIn(
|
||||||
"curity",
|
"curity",
|
||||||
|
|||||||
Reference in New Issue
Block a user