Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/clean-grapes-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@clerk/clerk-js': patch
'@clerk/clerk-react': patch
'@clerk/types': patch
---

Introduce `__internal_hasAfterAuthFlows` flag
4 changes: 4 additions & 0 deletions packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2524,6 +2524,10 @@ export class Clerk implements ClerkInterface {
this.#emit();
};

get __internal_hasAfterAuthFlows() {
return !!this.environment?.organizationSettings?.forceOrganizationSelection;
}

#defaultSession = (client: ClientResource): SignedInSessionResource | null => {
if (client.lastActiveSessionId) {
const currentSession = client.signedInSessions.find(s => s.id === client.lastActiveSessionId);
Expand Down
5 changes: 2 additions & 3 deletions packages/clerk-js/src/core/resources/SignIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,10 @@ export class SignIn extends BaseResource implements SignInResource {

const redirectUrlWithAuthToken = SignIn.clerk.buildUrlWithAuth(redirectUrl);

// When force organization selection is enabled, redirect to SSO callback route.
// When after-auth is enabled, redirect to SSO callback route.
// This ensures organization selection tasks are displayed after sign-in,
// rather than redirecting to potentially unprotected pages while the session is pending.
const actionCompleteRedirectUrl = SignIn.clerk.__unstable__environment?.organizationSettings
.forceOrganizationSelection
const actionCompleteRedirectUrl = SignIn.clerk.__internal_hasAfterAuthFlows
? redirectUrlWithAuthToken
: redirectUrlComplete;

Expand Down
5 changes: 2 additions & 3 deletions packages/clerk-js/src/core/resources/SignUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,10 @@ export class SignUp extends BaseResource implements SignUpResource {

const redirectUrlWithAuthToken = SignUp.clerk.buildUrlWithAuth(redirectUrl);

// When force organization selection is enabled, redirect to SSO callback route.
// When force after-auth is enabled, redirect to SSO callback route.
// This ensures organization selection tasks are displayed after sign-up,
// rather than redirecting to potentially unprotected pages while the session is pending.
const actionCompleteRedirectUrl = SignUp.clerk.__unstable__environment?.organizationSettings
.forceOrganizationSelection
const actionCompleteRedirectUrl = SignUp.clerk.__internal_hasAfterAuthFlows
? redirectUrlWithAuthToken
: redirectUrlComplete;

Expand Down
1 change: 1 addition & 0 deletions packages/react/src/isomorphicClerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type IsomorphicLoadedClerk = Without<
| 'apiKeys'
| '__internal_setComponentNavigationContext'
| '__internal_setActiveInProgress'
| '__internal_hasAfterAuthFlows'
> & {
client: ClientResource | undefined;
billing: CommerceBillingNamespace | undefined;
Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,12 @@ export interface Clerk {
*/
__internal_setActiveInProgress: boolean;

/**
* Internal flag indicating whether after-auth flows are enabled based on instance settings.
* @internal
*/
__internal_hasAfterAuthFlows: boolean;

/**
* API Keys Object
* @experimental
Expand Down
Loading