Skip to content

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

Open
MrHertal wants to merge 1 commit into
anomalyco: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 into
anomalyco: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().

andrewmd5 added a commit to 6over3/openauth that referenced this pull request Apr 26, 2026
Cherry-picks from anomalyco/openauth open PRs:

- anomalyco#305 spec-compliant redirect_uri (require `allow`, RFC 9700 §4.1)
- anomalyco#309 client-side JWT audience validation (RFC 7519 §4.1.3)
- anomalyco#318 token_type=Bearer on token responses
- anomalyco#304 implicit-flow no refresh token (RFC 6749 §4.2.2)
- anomalyco#258 iat claim (deterministic across reuse interval)
- anomalyco#323 fix Cloudflare KV runaway key creation under eventual consistency
- anomalyco#315 loosen CloudflareStorageOptions to structural KV shape
- anomalyco#319 refresh callback hook
- anomalyco#156 OAuth2 scope (authorize, token, well-known, JWT claim)
- anomalyco#236 basePath option
- anomalyco#278 allowRegistration / userExists / allowClaims
- anomalyco#221 configurable Select copy
- anomalyco#310 anomalyco#308 code UI resend action + sendCode types
- anomalyco#325 example actions: keep session when access token still valid
- anomalyco#317 add MIT license to package.json

Bump 0.3.12 -> 0.4.0 (breaking: `allow` is now required).
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