refactor: Update login redirection method for session handling

- Replaced router.push with window.location.href to ensure a full page reload after login, allowing the session cookie to be read correctly before authentication checks.
- Updated comments to clarify the reason for this change in the login flow.
This commit is contained in:
ilia 2026-01-04 13:14:16 -05:00
parent 98fe3513dd
commit f9bfa5febb

View File

@ -2,10 +2,8 @@
import { useState } from "react" import { useState } from "react"
import { signIn } from "next-auth/react" import { signIn } from "next-auth/react"
import { useRouter } from "next/navigation"
export default function LoginPage() { export default function LoginPage() {
const router = useRouter()
const [email, setEmail] = useState("") const [email, setEmail] = useState("")
const [password, setPassword] = useState("") const [password, setPassword] = useState("")
const [error, setError] = useState("") const [error, setError] = useState("")
@ -32,8 +30,9 @@ export default function LoginPage() {
const params = new URLSearchParams(window.location.search) const params = new URLSearchParams(window.location.search)
const callbackUrl = params.get("callbackUrl") || "/photos" const callbackUrl = params.get("callbackUrl") || "/photos"
console.log("Redirecting to:", callbackUrl) console.log("Redirecting to:", callbackUrl)
router.push(callbackUrl) // Use window.location.href to force a full page reload
router.refresh() // This ensures the session cookie is read before middleware checks authentication
window.location.href = callbackUrl
} else { } else {
setError("Login failed. Please try again.") setError("Login failed. Please try again.")
} }