Skip to content

Preserve requested URL through Google sign-in - #6653

Open
ayoubdiourin7 wants to merge 5 commits into
mozilla:masterfrom
ayoubdiourin7:fix/hackbot-ui-login-redirect
Open

Preserve requested URL through Google sign-in#6653
ayoubdiourin7 wants to merge 5 commits into
mozilla:masterfrom
ayoubdiourin7:fix/hackbot-ui-login-redirect

Conversation

@ayoubdiourin7

Copy link
Copy Markdown
Collaborator

Tested locally ; users return to their original page after signing in.

FIxes #6645

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Preserves deep-link destinations through Google authentication.

Changes:

  • Adds the requested path as a next login parameter.
  • Uses a validated next path 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.

Comment thread services/hackbot-ui/app/login/page.tsx Outdated
Comment thread services/hackbot-ui/app/login/page.tsx Outdated
return raw;
}

export default function LoginPage() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid using window.location.search, instead using nextjs native props:

Suggested change
export default function LoginPage() {
export default function LoginPage(props: {
searchParams: Promise<{ callbackUrl?: string}>;
}) {
const searchParams = await props.searchParams;
const callbackURL = searchParams.callbackUrl || "/";

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i updated to use Next.js searchParams. cause this is a client component, I unwrap it with React’s use().

Comment thread services/hackbot-ui/app/login/page.tsx Outdated
setError(null);
setLoading(true);
const params = new URLSearchParams(window.location.search);
const next = safeRedirectPath(params.get("next"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need safeRedirectPath()? I do not think it is needed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it to prevent unsafe external redirects, but Better Auth already handles this, so I dropped it. 851c867

Comment thread services/hackbot-ui/middleware.ts Outdated
// 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",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use callbackURL instead of next.

@ayoubdiourin7 ayoubdiourin7 Aug 20, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 851c867

Comment thread services/hackbot-ui/middleware.ts Outdated
const loginUrl = new URL("/login", req.url);
loginUrl.searchParams.set(
"next",
`${req.nextUrl.pathname}${req.nextUrl.search}`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not req.nextUrl directly?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we can , fix it in 851c867

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix hackbot-ui redirect after login

3 participants