feat(core): support isProviderConnected in stateful strategy#235
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
📝 WalkthroughWalkthroughAdds ChangesProvider connection status
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Sequence Diagram(s)sequenceDiagram
participant Client
participant isProviderConnected
participant SessionStrategy
participant SessionStore
Client->>isProviderConnected: Request provider connection status
isProviderConnected->>SessionStrategy: Validate OAuth headers and check provider
SessionStrategy->>SessionStore: Read session and account data
SessionStore-->>SessionStrategy: Session and account records
SessionStrategy-->>isProviderConnected: connected boolean
isProviderConnected-->>Client: success, connected, and headers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
Actionable comments posted: 3
🤖 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.
Inline comments:
In `@packages/core/src/session/stateful.ts`:
- Around line 990-998: Update the expired-session branch in isProviderConnected
to call config.adapter.revokeSession with sessionByToken.id and "user_logout"
before logging and returning false, matching the cleanup behavior of getSession,
refreshSession, getProviderTokens, and revokeToken. Keep inactive-session
handling unchanged and avoid revoking sessions that are not expired.
In `@packages/core/src/session/stateless.ts`:
- Around line 363-378: Update isProviderConnected to catch errors from
jwt.verifyToken(cookieValue) and return false for malformed, tampered, or
expired provider tokens, matching the existing getCookie failure behavior and
getSession’s authentication-error handling.
In `@packages/core/test/actions/providers/connected/stateful.test.ts`:
- Around line 130-306: Correct the affected tests around the stateful
isProviderConnected flow so getSessionByTokenMock supplies a session for both
verifySession and the strategy, using two mockResolvedValueOnce calls or
persistent mockResolvedValue. Update “handles expired session token” to exercise
the intended session-expiry behavior rather than mock exhaustion, and replace
the malformed/expired provider-token cookie tests because stateful
isProviderConnected does not read provider access-token cookies. Preserve the
provider-matching coverage in “handles multiple providers” with a valid second
session response.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 02d67df4-c062-4943-8838-06d4ff60136b
📒 Files selected for processing (8)
packages/core/src/@types/session.tspackages/core/src/api/isProviderConnected.tspackages/core/src/session/stateful.tspackages/core/src/session/stateless.tspackages/core/test/actions/providers/connected/stateful.test.tspackages/core/test/actions/providers/tokens/revoke/stateful.test.tspackages/core/test/api/stateful/isProviderConnected.test.tspackages/core/test/presets.ts
Description
This pull request adds Stateful session support for the
isProviderConnected()API and theGET /providers/:providerendpoint.With this change, the provider connection APIs now support both available session strategies:
The implementation ensures consistent behavior across both strategies, allowing applications to verify whether an OAuth or OpenID Connect (OIDC) provider is connected to the current session regardless of the configured session storage mechanism.
Key Changes
api.isProviderConnected().GET /providers/:providerendpoint.Note
This PR is part of the ongoing effort to implement the Stateful session strategy. To keep reviews focused and manageable, the implementation has been split into a series of smaller pull requests, each covering a specific aspect of the feature.
Related PRs
@coderabbitai ignore