Skip to content

fix(examples): prevent unnecessary IdP redirect when session is still valid#325

Open
MrHertal wants to merge 1 commit intoanomalyco:masterfrom
MrHertal:fix/unnecessary-idp-redirect-on-valid-session
Open

fix(examples): prevent unnecessary IdP redirect when session is still valid#325
MrHertal wants to merge 1 commit intoanomalyco:masterfrom
MrHertal:fix/unnecessary-idp-redirect-on-valid-session

Conversation

@MrHertal
Copy link
Copy Markdown

Summary

The login() function in the examples checks for an existing valid session before redirecting to the IdP. However, client.verify() only populates verified.tokens when a token refresh actually occurs — when the access token is still valid, tokens is undefined. The original condition !verified.err && verified.tokens evaluates to false for valid (non-expired) sessions, causing the code to fall through to client.authorize() and trigger an unnecessary full OAuth round-trip.

The fix checks !verified.err alone to determine session validity, and only calls setTokens when verified.tokens is present (i.e., a refresh occurred).

Files changed

  • examples/quickstart/sst/app/actions.ts
  • examples/quickstart/standalone/app/actions.ts
  • examples/client/nextjs/app/actions.ts
  • www/src/content/docs/docs/start/sst.mdx
  • www/src/content/docs/docs/start/standalone.mdx

Note: the auth() function in those same files already handled this correctly with separate checks. The bug only affected login().

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.

1 participant