Skip to content

Commit

Permalink
Merge branch 'main' into rob/eco-222-port-vue-clerk-to-clerkvue
Browse files Browse the repository at this point in the history
  • Loading branch information
wobsoriano authored Nov 6, 2024
2 parents fead36b + 8a04ae4 commit 02a7159
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 78 deletions.
6 changes: 6 additions & 0 deletions .changeset/wicked-tomatoes-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@clerk/clerk-react": patch
"@clerk/shared": patch
---

Use shared `deriveState` function
2 changes: 1 addition & 1 deletion packages/react/src/contexts/ClerkContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { deriveState } from '@clerk/shared/deriveState';
import { ClientContext, OrganizationProvider, SessionContext, UserContext } from '@clerk/shared/react';
import type { ClientResource, InitialState, Resources } from '@clerk/types';
import React from 'react';

import { IsomorphicClerk } from '../isomorphicClerk';
import type { IsomorphicClerkOptions } from '../types';
import { deriveState } from '../utils/deriveState';
import { AuthContext } from './AuthContext';
import { IsomorphicClerkContext } from './IsomorphicClerkContext';

Expand Down
77 changes: 0 additions & 77 deletions packages/react/src/utils/deriveState.ts

This file was deleted.

9 changes: 9 additions & 0 deletions packages/shared/src/deriveState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import type {
UserResource,
} from '@clerk/types';

/**
* Derives authentication state based on the current rendering context (SSR or client-side).
*/
export const deriveState = (clerkLoaded: boolean, state: Resources, initialState: InitialState | undefined) => {
if (!clerkLoaded && initialState) {
return deriveFromSsrInitialState(initialState);
Expand All @@ -26,6 +29,7 @@ const deriveFromSsrInitialState = (initialState: InitialState) => {
const orgPermissions = initialState.orgPermissions as OrganizationCustomPermissionKey[];
const orgSlug = initialState.orgSlug;
const actor = initialState.actor;
const __experimental_factorVerificationAge = initialState.__experimental_factorVerificationAge;

return {
userId,
Expand All @@ -38,6 +42,7 @@ const deriveFromSsrInitialState = (initialState: InitialState) => {
orgPermissions,
orgSlug,
actor,
__experimental_factorVerificationAge,
};
};

Expand All @@ -46,6 +51,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, number] | null = state.session
? state.session.__experimental_factorVerificationAge
: null;
const actor = session?.actor;
const organization = state.organization;
const orgId: string | null | undefined = state.organization ? state.organization.id : state.organization;
Expand All @@ -67,5 +75,6 @@ const deriveFromClientSideState = (state: Resources) => {
orgSlug,
orgPermissions,
actor,
__experimental_factorVerificationAge,
};
};

0 comments on commit 02a7159

Please sign in to comment.