core: fix oauth login redirect url#1172
Conversation
|
Worried about impact? Review this PR in Change Stack to explore blast radius before you approve or request changes. WalkthroughThis PR implements redirect parameter threading throughout the OAuth login flow. UserLoginHandler now accepts an optional Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
packages/hydrooj/src/handler/user.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/hydrooj/src/handler/user.ts (1)
480-504:⚠️ Potential issue | 🔴 Critical | 🏗️ Heavy liftCritical: Registration flow doesn't preserve the redirect parameter.
The three early-return paths (bind, existing user, email match) correctly use
this.session.oauthRedirectand clean it up. However, when the flow continues past line 504 to handle new registrations, thesession.oauthRedirectis never transferred to the registration token created at lines 523-537.The registration token uses
this.domain.registerRedirect(line 529) instead ofthis.session.oauthRedirect, so after the user completes registration viaUserRegisterWithCodeHandler, they'll be redirected to the domain's default register redirect instead of their original page.🔧 Proposed fix
At line 529, use the session redirect with fallback:
{ mail: r.email, username, - redirect: this.domain.registerRedirect, + redirect: this.session.oauthRedirect || this.domain.registerRedirect, set, setInDomain: r.setInDomain, identity: {Then clean up the session after creating the token (around line 538):
}, ); + delete this.session.oauthRedirect; this.response.redirect = this.url('user_register_with_code', { code: t });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/hydrooj/src/handler/user.ts` around lines 480 - 504, The registration path currently sets the registration token's redirect to this.domain.registerRedirect instead of the per-request this.session.oauthRedirect; update the token creation to use (this.session.oauthRedirect || this.domain.registerRedirect) when constructing the registration token (the same place where the register token is created after the user.getByEmail check), then immediately delete this.session.oauthRedirect after the token is created so the session is cleaned up; keep all other behavior (ids mapping, token creation call) the same and locate changes around the registration token creation code that follows the existing successfulAuth / user.getByEmail logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@packages/hydrooj/src/handler/user.ts`:
- Around line 480-504: The registration path currently sets the registration
token's redirect to this.domain.registerRedirect instead of the per-request
this.session.oauthRedirect; update the token creation to use
(this.session.oauthRedirect || this.domain.registerRedirect) when constructing
the registration token (the same place where the register token is created after
the user.getByEmail check), then immediately delete this.session.oauthRedirect
after the token is created so the session is cleaned up; keep all other behavior
(ids mapping, token creation call) the same and locate changes around the
registration token creation code that follows the existing successfulAuth /
user.getByEmail logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9141559e-88d6-4b5d-af53-d3c1f84acf3f
📒 Files selected for processing (3)
packages/hydrooj/src/handler/user.tspackages/ui-default/templates/partials/login_dialog.htmlpackages/ui-default/templates/user_login.html
Summary by CodeRabbit