-
Notifications
You must be signed in to change notification settings - Fork 419
chore(clerk-js): Trigger Next.js hooks on session status transition to pending
#6511
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/clerk-js': patch | ||
| --- | ||
|
|
||
| Trigger Next.js hooks on session status transition from `active` to `pending` to update authentication context state |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2258,6 +2258,23 @@ export class Clerk implements ClerkInterface { | |
| if (this.session) { | ||
| const session = this.#getSessionFromClient(this.session.id); | ||
|
|
||
| const hasTransitionedToPendingStatus = this.session.status === 'active' && session?.status === 'pending'; | ||
| if (hasTransitionedToPendingStatus) { | ||
| const onBeforeSetActive: SetActiveHook = | ||
| typeof window !== 'undefined' && typeof window.__unstable__onBeforeSetActive === 'function' | ||
| ? window.__unstable__onBeforeSetActive | ||
| : noop; | ||
|
|
||
| const onAfterSetActive: SetActiveHook = | ||
| typeof window !== 'undefined' && typeof window.__unstable__onAfterSetActive === 'function' | ||
| ? window.__unstable__onAfterSetActive | ||
| : noop; | ||
|
|
||
| // Execute hooks to update server authentication context and trigger | ||
| // page protections in clerkMiddleware or server components | ||
| void onBeforeSetActive()?.then?.(() => void onAfterSetActive()); | ||
| } | ||
LauraBeatris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Note: this might set this.session to null | ||
| this.#setAccessors(session); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @LauraBeatris I found this PR when trying to understand the Nice catch fixing this btw! |
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.