Skip to content

fix(sdk): check token expiry in isAuthenticated()#80

Closed
aarushisingh04 wants to merge 1 commit into
stripe:mainfrom
aarushisingh04:fix/auth-expiry-check
Closed

fix(sdk): check token expiry in isAuthenticated()#80
aarushisingh04 wants to merge 1 commit into
stripe:mainfrom
aarushisingh04:fix/auth-expiry-check

Conversation

@aarushisingh04
Copy link
Copy Markdown

summary

identified and fixed a bug where isAuthenticated() in storage.ts returned true for expired tokens. expired sessions were treated as valid until the next API call returned a 401 meaning that any auth-gated command would proceed assuming a valid token.

changes made

  • updated isAuthenticated() in both Storage and MemoryStorage to check auth.expires_at against Date.now() returning false if the token has expired.
  • added packages/sdk/src/utils/__tests__/auth-expiry.test.ts covering: valid tokens, expired tokens, the exact expiry boundary (>=), pre-set expires_at taking precedence over expires_in and both clearAuth() and clearAll() resetting authenticated state.
  • also added a constructor comment to MemoryStorage warning that withComputedExpiry stamps expires_at at construction time, so tests using vi.useFakeTimers() should call setAuth() after installing fake timers rather than passing initialAuth directly.

testing

  • ran npx turbo run test --filter @stripe/link-sdk (all pass).
  • verified formatting and linting with biome check.

@aarushisingh04 aarushisingh04 requested a review from a team as a code owner May 7, 2026 14:18
Copy link
Copy Markdown
Contributor

@danhill-stripe danhill-stripe left a comment

Choose a reason for hiding this comment

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

Good catch, thanks!

Copy link
Copy Markdown
Contributor

@danhill-stripe danhill-stripe left a comment

Choose a reason for hiding this comment

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

Actually, looking more closely. The expires_at is only when the refresh token is needed for a new access token, not when the user needs to re-authenticate.

@aarushisingh04
Copy link
Copy Markdown
Author

@danhill-stripe oh right, checked session.ts after your comment, it's handled correctly there. thanks, and you can close the pr if no further discussion is needed.

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.

2 participants