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
8 changes: 8 additions & 0 deletions .changeset/moody-clocks-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@clerk/clerk-js": patch
"@clerk/backend": patch
"@clerk/clerk-react": patch
"@clerk/types": patch
---

Update type of `__experimental_factorVerificationAge` to be `[number, number] | null`.
11 changes: 7 additions & 4 deletions packages/backend/src/tokens/authObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type SignedInAuthObject = {
* [fistFactorAge, secondFactorAge]
* @experimental This API is experimental and may change at any moment.
*/
__experimental_factorVerificationAge: [number | null, number | null];
__experimental_factorVerificationAge: [number, number] | null;
getToken: ServerGetToken;
has: CheckAuthorizationWithCustomPermissions;
debug: AuthObjectDebug;
Expand All @@ -64,7 +64,7 @@ export type SignedOutAuthObject = {
* [fistFactorAge, secondFactorAge]
* @experimental This API is experimental and may change at any moment.
*/
__experimental_factorVerificationAge: [null, null];
__experimental_factorVerificationAge: null;
getToken: ServerGetToken;
has: CheckAuthorizationWithCustomPermissions;
debug: AuthObjectDebug;
Expand Down Expand Up @@ -100,7 +100,7 @@ export function signedInAuthObject(
org_slug: orgSlug,
org_permissions: orgPermissions,
sub: userId,
fva: __experimental_factorVerificationAge,
fva,
} = sessionClaims;
const apiClient = createBackendApiClient(authenticateContext);
const getToken = createGetToken({
Expand All @@ -109,6 +109,9 @@ export function signedInAuthObject(
fetcher: async (...args) => (await apiClient.sessions.getToken(...args)).jwt,
});

// fva can be undefined for instances that have not opt-in
const __experimental_factorVerificationAge = fva ?? null;

return {
actor,
sessionClaims,
Expand Down Expand Up @@ -138,7 +141,7 @@ export function signedOutAuthObject(debugData?: AuthObjectDebugData): SignedOutA
orgRole: null,
orgSlug: null,
orgPermissions: null,
__experimental_factorVerificationAge: [null, null],
__experimental_factorVerificationAge: null,
getToken: () => Promise.resolve(null),
has: () => false,
debug: createDebug(debugData),
Expand Down
2 changes: 1 addition & 1 deletion packages/clerk-js/src/core/resources/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class Session extends BaseResource implements SessionResource {
actor!: ActJWTClaim | null;
user!: UserResource | null;
publicUserData!: PublicUserData;
__experimental_factorVerificationAge: [number | null, number | null] = [null, null];
__experimental_factorVerificationAge: [number, number] | null = null;
expireAt!: Date;
abandonAt!: Date;
createdAt!: Date;
Expand Down
10 changes: 6 additions & 4 deletions packages/clerk-js/src/utils/memoizeStateListenerCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ function userMembershipsChanged(prev: UserResource, next: UserResource): boolean
}

function sessionFVAChanged(prev: SessionResource, next: SessionResource): boolean {
return (
prev.__experimental_factorVerificationAge[0] !== next.__experimental_factorVerificationAge[0] ||
prev.__experimental_factorVerificationAge[1] !== next.__experimental_factorVerificationAge[1]
);
const prevFVA = prev.__experimental_factorVerificationAge;
const nextFVA = next.__experimental_factorVerificationAge;
if (prevFVA !== null && nextFVA !== null) {
return prevFVA[0] !== nextFVA[0] || prevFVA[1] !== nextFVA[1];
}
return prevFVA !== nextFVA;
}

function sessionUserMembershipPermissionsChanged(prev: SessionResource, next: SessionResource): boolean {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/contexts/AuthContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export const [AuthContext, useAuthContext] = createContextAndHook<{
orgRole: OrganizationCustomRoleKey | null | undefined;
orgSlug: string | null | undefined;
orgPermissions: OrganizationCustomPermissionKey[] | null | undefined;
__experimental_factorVerificationAge: [number | null, number | null];
__experimental_factorVerificationAge: [number, number] | null;
}>('AuthContext');
4 changes: 2 additions & 2 deletions packages/react/src/utils/deriveState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ const deriveFromClientSideState = (state: Resources) => {
const user = state.user;
const sessionId: string | null | undefined = state.session ? state.session.id : state.session;
const session = state.session;
const __experimental_factorVerificationAge: [number | null, number | null] = state.session
const __experimental_factorVerificationAge: [number, number] | null = state.session
? state.session.__experimental_factorVerificationAge
: [null, null];
: null;
const actor = session?.actor;
const organization = state.organization;
const orgId: string | null | undefined = state.organization ? state.organization.id : state.organization;
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export interface SessionJSON extends ClerkResourceJSON {
* [fistFactorAge, secondFactorAge]
* @experimental This API is experimental and may change at any moment.
*/
factor_verification_age: [number | null, number | null];
factor_verification_age: [number, number] | null;
expire_at: number;
abandon_at: number;
last_active_at: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/jwtv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export interface JwtPayload extends CustomJwtSessionClaims {
* [fistFactorAge, secondFactorAge]
* @experimental This API is experimental and may change at any moment.
*/
fva: [number | null, number | null];
fva?: [number, number];

/**
* Any other JWT Claim Set member.
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface SessionResource extends ClerkResource {
* [fistFactorAge, secondFactorAge]
* @experimental This API is experimental and may change at any moment.
*/
__experimental_factorVerificationAge: [number | null, number | null];
__experimental_factorVerificationAge: [number, number] | null;
lastActiveToken: TokenResource | null;
lastActiveOrganizationId: string | null;
lastActiveAt: Date;
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export type InitialState = Serializable<{
orgSlug: string | undefined;
orgPermissions: OrganizationCustomPermissionKey[] | undefined;
organization: OrganizationResource | undefined;
__experimental_factorVerificationAge: [number | null, number | null];
__experimental_factorVerificationAge: [number, number];
}>;