refactor: Simplify cookie management in authentication handling
- Removed unnecessary comments and code related to secure cookie management in `auth.ts`, as Auth.js now correctly handles cookies. - Streamlined the authentication route in `route.ts` by directly exporting handlers without additional wrappers.
This commit is contained in:
parent
bc4a6b93b6
commit
1e7a47ad31
@ -1,4 +1,3 @@
|
|||||||
import { handlers } from "@/lib/auth"
|
import { handlers } from "@/lib/auth"
|
||||||
|
|
||||||
// No wrapper needed - Auth.js now handles cookies correctly via useSecureCookies
|
|
||||||
export const { GET, POST } = handlers
|
export const { GET, POST } = handlers
|
||||||
|
|||||||
19
lib/auth.ts
19
lib/auth.ts
@ -12,29 +12,10 @@ if (!nextAuthSecret) {
|
|||||||
// Determine if we should use secure cookies based on AUTH_URL/NEXTAUTH_URL
|
// Determine if we should use secure cookies based on AUTH_URL/NEXTAUTH_URL
|
||||||
// Auth.js v5 derives this from the origin it detects, so we need to be explicit
|
// Auth.js v5 derives this from the origin it detects, so we need to be explicit
|
||||||
const authUrl = process.env.AUTH_URL || process.env.NEXTAUTH_URL || "http://localhost:3000"
|
const authUrl = process.env.AUTH_URL || process.env.NEXTAUTH_URL || "http://localhost:3000"
|
||||||
const isDev = process.env.NODE_ENV === "development"
|
|
||||||
const isHttp = authUrl.startsWith("http://")
|
const isHttp = authUrl.startsWith("http://")
|
||||||
|
|
||||||
// Explicitly control useSecureCookies - only true when URL is https://
|
|
||||||
// This prevents Auth.js from auto-detecting HTTPS and adding prefixes on HTTP
|
|
||||||
const useSecureCookies = !isHttp
|
|
||||||
|
|
||||||
// Log cookie configuration for debugging (only in development)
|
|
||||||
if (isDev) {
|
|
||||||
logger.debug("NextAuth cookie configuration", {
|
|
||||||
authUrl,
|
|
||||||
isDev,
|
|
||||||
isHttp,
|
|
||||||
useSecureCookies,
|
|
||||||
nodeEnv: process.env.NODE_ENV,
|
|
||||||
hasVercelEnv: !!process.env.VERCEL,
|
|
||||||
hasAuthTrustHost: !!process.env.AUTH_TRUST_HOST,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export const { handlers, auth, signIn, signOut } = NextAuth({
|
export const { handlers, auth, signIn, signOut } = NextAuth({
|
||||||
// trustHost must be true for NextAuth v5 to work, even on localhost
|
// trustHost must be true for NextAuth v5 to work, even on localhost
|
||||||
// We control HTTPS detection via cookie configuration instead
|
|
||||||
trustHost: true,
|
trustHost: true,
|
||||||
debug: process.env.NODE_ENV !== "production",
|
debug: process.env.NODE_ENV !== "production",
|
||||||
basePath: "/api/auth",
|
basePath: "/api/auth",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user