Preserve requested URL through Google sign-in - #6653
Conversation
There was a problem hiding this comment.
Pull request overview
Preserves deep-link destinations through Google authentication.
Changes:
- Adds the requested path as a
nextlogin parameter. - Uses a validated
nextpath for authentication callbacks.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
services/hackbot-ui/middleware.ts |
Preserves the requested URL during login redirects. |
services/hackbot-ui/app/login/page.tsx |
Validates and forwards the post-login destination. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| return raw; | ||
| } | ||
|
|
||
| export default function LoginPage() { |
There was a problem hiding this comment.
I would avoid using window.location.search, instead using nextjs native props:
| export default function LoginPage() { | |
| export default function LoginPage(props: { | |
| searchParams: Promise<{ callbackUrl?: string}>; | |
| }) { | |
| const searchParams = await props.searchParams; | |
| const callbackURL = searchParams.callbackUrl || "/"; |
There was a problem hiding this comment.
Yes, i updated to use Next.js searchParams. cause this is a client component, I unwrap it with React’s use().
| setError(null); | ||
| setLoading(true); | ||
| const params = new URLSearchParams(window.location.search); | ||
| const next = safeRedirectPath(params.get("next")); |
There was a problem hiding this comment.
Why do we need safeRedirectPath()? I do not think it is needed.
There was a problem hiding this comment.
Added it to prevent unsafe external redirects, but Better Auth already handles this, so I dropped it. 851c867
| // Remember the requested URL so the login page can send the user back here | ||
| const loginUrl = new URL("/login", req.url); | ||
| loginUrl.searchParams.set( | ||
| "next", |
There was a problem hiding this comment.
I would use callbackURL instead of next.
| const loginUrl = new URL("/login", req.url); | ||
| loginUrl.searchParams.set( | ||
| "next", | ||
| `${req.nextUrl.pathname}${req.nextUrl.search}` |
There was a problem hiding this comment.
why not req.nextUrl directly?
Tested locally ; users return to their original page after signing in.
FIxes #6645