-
Notifications
You must be signed in to change notification settings - Fork 330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(clerk-js): Handle new session pending
status as authenticated state
#5136
Merged
LauraBeatris
merged 17 commits into
main
from
laura/orgs-544-sdk-handle-pending-session-status-as-authenticated
Feb 18, 2025
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ba87fc6
Add `pending` to `SessionStatus` union
LauraBeatris 918bcd1
Plug pending session into main Client resource
LauraBeatris 1a6dffb
Add test coverage for `pending` and `active` statuses
LauraBeatris 99a782f
Update handshake tests
LauraBeatris 7fe2081
Update device section to list for pending
LauraBeatris 76cbf8d
Fix sign in account switcher to look for pending sessions
LauraBeatris 523e920
Consider `pending` as authenticate state for client UAT
LauraBeatris a22328f
Save JWT token on Expo for pending session status
LauraBeatris cf8d19a
Add `isAuthenticated` property to main Clerk instance
LauraBeatris 8c88903
Update `SignIn.SessionList` to include pending sessions
LauraBeatris 0b7e5fe
Deprecate `activeSessions`
LauraBeatris 6f3a0a7
Add changeset
LauraBeatris b344ea5
Introduce separate changesets
LauraBeatris a79b339
Refactor from `isAuthenticated` to `isSignedIn`
LauraBeatris 760434f
Update changeset
LauraBeatris 4ac18aa
Update clerk-js change to include deprecate property
LauraBeatris e69c175
Update `isSignedIn` to check against initialized session
LauraBeatris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
'@clerk/elements': minor | ||
'@clerk/shared': minor | ||
'@clerk/astro': minor | ||
'@clerk/clerk-react': minor | ||
'@clerk/types': minor | ||
'@clerk/clerk-expo': minor | ||
'@clerk/vue': minor | ||
--- | ||
|
||
Surface new `pending` session as a signed-in state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
'@clerk/clerk-js': minor | ||
--- | ||
|
||
- Initialize new `pending` session status as an signed-in state | ||
- Deprecate `Clerk.client.activeSessions` in favor of `Clerk.client.signedInSessions` | ||
- Introduce `Clerk.isSignedIn` property as an explicit signed-in state check, instead of `!!Clerk.session` or `!!Clerk.user`: | ||
|
||
```ts | ||
- if (Clerk.user) { | ||
+ if (Clerk.isSignedIn) { | ||
// Mount user button component | ||
document.getElementById('signed-in').innerHTML = ` | ||
<div id="user-button"></div> | ||
` | ||
|
||
const userbuttonDiv = document.getElementById('user-button') | ||
|
||
clerk.mountUserButton(userbuttonDiv) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
isSignedIn
property makes sense to me!In the PR description, you mention that:
But the logic in the
Client
resource tells me thatisSignedIn
is going to be true if the current session isactive
orpending
, meaning that currently,isSignedIn
cannot be used to check if the user is fully authenticated or not.Is this intentional? If yes, could you please provide an example where
Clerk.isSignedIn !== !!Clerk.user
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user has fully authenticated even with a
pending
status. Still, they have pending tasks to complete, eg: After sign-in, complete all factors but FAPI returns a pending session for tasks such as having to select an org.Currently, they are the same. This PR treats
pending
exactly likeactive
to maintain current functionality and to incrementally add protections for it since the feature is gated on FAPI and toggled via Dashboard.That property was added to avoid relying only on the
user
object, orClerk.activeSessions.length > 0
for our internal "signed-in" state checks.Once we introduce tasks (#5170) -> I'd add another property that specifically checks if the user has a session that resolved all pending tasks, something like:
As a syntax sugar so that developers don't have to manually check for the session statuses on custom flows as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually acknowledged that I misplaced "Clerk.user shouldn't be used to determine if the user has fully authenticated or not" statement and updated the changeset here
isSignedIn
doesn't necessarily replaceClerk.user
, but it does act like a syntax sugar to deprecate any manual references toClerk.client.activeSessions.length > 0
,!!Clerk.user
or!!Clerk.session