Skip to content

fix: redirect to original resource URL after SSO login with expired session #3411

Open
Adityakk9031 wants to merge 1 commit into
fosrl:mainfrom
Adityakk9031:#3365
Open

fix: redirect to original resource URL after SSO login with expired session #3411
Adityakk9031 wants to merge 1 commit into
fosrl:mainfrom
Adityakk9031:#3365

Conversation

@Adityakk9031

@Adityakk9031 Adityakk9031 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #3365

When a user's session expired and they attempted to access a deep link of an SSO-protected resource, they were incorrectly redirected to the dashboard/panel after logging back in instead of their original destination URL.

Root Cause

Two separate issues caused the redirect context to be lost:

  1. router.refresh() does not follow server redirects: In ResourceAuthPortal.tsx, after successfully authenticating via SSO, the client called router.refresh(). In Next.js App Router, this performs a client-side component re-fetch but does not trigger full-page browser navigation or follow server-side redirect() calls returned during re-rendering. This left the user stuck on the auth portal page, eventually defaulting to the dashboard panel.
  2. postAuthPath overriding target URL: In src/app/auth/resource/[resourceGuid]/page.tsx, if a resource had a custom postAuthPath configured, it unconditionally overrode the searchParams.redirect target URL, always redirecting users to the default post-auth path rather than their requested deep link.

Changes

1. src/components/ResourceAuthPortal.tsx

  • Replaced router.refresh() with window.location.reload(). This forces a full browser reload, maintaining the query parameters (including ?redirect=...). The server then processes the request, performs the SSO token exchange, and successfully issues a 302 redirect that the browser follows to the deep link.
  • Removed a stray debug console.log.

2. src/app/auth/resource/[resourceGuid]/page.tsx

  • Modified the logic to only apply postAuthPath if there is no ?redirect= parameter present in the request. The user's requested deep link now has priority, and the postAuthPath acts as a fallback.

Testing

  1. Access an SSO-protected resource deep link with an expired session or in an incognito window: https://app.company.org/some/deep/path.
  2. Enter credentials and complete the login (including MFA if configured).
  3. Confirm that you are correctly redirected back to https://app.company.org/some/deep/path and not the main Pangolin panel.

@Adityakk9031 Adityakk9031 changed the title fix: prevent incorrect redirect to setup wizard on login rate limit (… fix: redirect to original resource URL after SSO login with expired session Jul 8, 2026
@AstralDestiny

AstralDestiny commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Was this accidently flipped? 3365 mentions when your session expires it'll not direct you back to the resource, a bit confused on the changes and testing parts.

Cheers.

@Adityakk9031

Copy link
Copy Markdown
Contributor Author

Oh whoops, good catch! I got my commit messages mixed up when pushing this branch.

The PR title, description, and the actual code files are correct for #3365 (redirecting back to the resource). I'll fix the commit message on merge. Sorry about that!

@Adityakk9031

Copy link
Copy Markdown
Contributor Author

@miloschwartz have a look please

@Adityakk9031

Copy link
Copy Markdown
Contributor Author

@oschwartz10612 have a look

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.

Redirect to the first link accessed after logging in

2 participants