From 3542b7247fb7ec8d63bcca3a59786cef24799262 Mon Sep 17 00:00:00 2001 From: ijxy <32483798+ijxy@users.noreply.github.com> Date: Fri, 20 Dec 2024 10:11:33 +0000 Subject: [PATCH 1/4] feat: add `sessionClaims` to derived auth state --- .../shared/src/__tests__/deriveState.test.ts | 22 +++++++++++++++---- packages/shared/src/deriveState.ts | 7 ++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/shared/src/__tests__/deriveState.test.ts b/packages/shared/src/__tests__/deriveState.test.ts index 244cb3fe857..8b11141e29a 100644 --- a/packages/shared/src/__tests__/deriveState.test.ts +++ b/packages/shared/src/__tests__/deriveState.test.ts @@ -3,17 +3,27 @@ import type { InitialState, Resources } from '@clerk/types'; import { deriveState } from '../deriveState'; describe('deriveState', () => { + const mockSessionClaims = { + sid: 'sess_2j1R7g3AUeKMx9M23dBO0XLEQGY', + sub: 'user_2U330vGHg3llBga8Oi0fzzeNAaG', + org_id: 'org_2U330vGHg3llBga8Oi0fzzeNAaG', + } as InitialState['sessionClaims']; + const mockInitialState = { - userId: 'user_2U330vGHg3llBga8Oi0fzzeNAaG', - sessionId: 'sess_2j1R7g3AUeKMx9M23dBO0XLEQGY', - orgId: 'org_2U330vGHg3llBga8Oi0fzzeNAaG', + userId: mockSessionClaims.sub, + orgId: mockSessionClaims.org_id, + sessionId: mockSessionClaims.sid, + sessionClaims: mockSessionClaims, } as InitialState; const mockResources = { client: {}, user: { id: mockInitialState.userId }, - session: { id: mockInitialState.sessionId }, organization: { id: mockInitialState.orgId }, + session: { + id: mockInitialState.sessionId, + lastActiveToken: { jwt: { claims: mockSessionClaims } }, + }, } as Resources; it('uses SSR state when !clerkLoaded and initialState is provided', () => { @@ -25,6 +35,9 @@ describe('deriveState', () => { expect(result.userId).toBe(mockInitialState.userId); expect(result.sessionId).toBe(mockInitialState.sessionId); expect(result.orgId).toBe(mockInitialState.orgId); + expect(result.sessionClaims?.sid).toBe(mockInitialState.sessionId); + expect(result.sessionClaims?.sub).toBe(mockInitialState.userId); + expect(result.sessionClaims?.org_id).toBe(mockInitialState.orgId); }); it('handles !clerkLoaded and undefined initialState', () => { @@ -32,5 +45,6 @@ describe('deriveState', () => { expect(result.userId).toBeUndefined(); expect(result.sessionId).toBeUndefined(); expect(result.orgId).toBeUndefined(); + expect(result.sessionClaims).toBeUndefined(); }); }); diff --git a/packages/shared/src/deriveState.ts b/packages/shared/src/deriveState.ts index 771c8040839..9573e446bdd 100644 --- a/packages/shared/src/deriveState.ts +++ b/packages/shared/src/deriveState.ts @@ -1,6 +1,7 @@ import type { ActiveSessionResource, InitialState, + JwtPayload, OrganizationCustomPermissionKey, OrganizationCustomRoleKey, OrganizationResource, @@ -23,6 +24,7 @@ const deriveFromSsrInitialState = (initialState: InitialState) => { const user = initialState.user as UserResource; const sessionId = initialState.sessionId; const session = initialState.session as ActiveSessionResource; + const sessionClaims = initialState.sessionClaims; const organization = initialState.organization as OrganizationResource; const orgId = initialState.orgId; const orgRole = initialState.orgRole as OrganizationCustomRoleKey; @@ -36,6 +38,7 @@ const deriveFromSsrInitialState = (initialState: InitialState) => { user, sessionId, session, + sessionClaims, organization, orgId, orgRole, @@ -51,6 +54,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 sessionClaims: JwtPayload | null | undefined = state.session + ? state.session.lastActiveToken?.jwt?.claims + : state.session; const factorVerificationAge: [number, number] | null = state.session ? state.session.factorVerificationAge : null; const actor = session?.actor; const organization = state.organization; @@ -67,6 +73,7 @@ const deriveFromClientSideState = (state: Resources) => { user, sessionId, session, + sessionClaims, organization, orgId, orgRole, From 32561489a0ff703c1470e1d2416deeb7f46aff98 Mon Sep 17 00:00:00 2001 From: ijxy <32483798+ijxy@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:14:06 +0000 Subject: [PATCH 2/4] refactor(astro): use `UseAuthReturn` type from `@clerk/types` --- packages/astro/src/react/hooks.ts | 70 ++----------------------------- 1 file changed, 3 insertions(+), 67 deletions(-) diff --git a/packages/astro/src/react/hooks.ts b/packages/astro/src/react/hooks.ts index e8b99e1c358..6acc982a932 100644 --- a/packages/astro/src/react/hooks.ts +++ b/packages/astro/src/react/hooks.ts @@ -1,11 +1,4 @@ -import type { - ActJWTClaim, - CheckAuthorizationWithCustomPermissions, - Clerk, - GetToken, - OrganizationCustomRoleKey, - SignOut, -} from '@clerk/types'; +import type { Clerk, GetToken, SignOut, UseAuthReturn } from '@clerk/types'; import type { Store, StoreValue } from 'nanostores'; import { useCallback, useSyncExternalStore } from 'react'; @@ -15,9 +8,6 @@ import { authAsyncStorage } from '#async-local-storage'; import { $authStore } from '../stores/external'; import { $clerk, $csrState } from '../stores/internal'; -type CheckAuthorizationSignedOut = undefined; -type CheckAuthorizationWithoutOrgOrUser = (params?: Parameters[0]) => false; - /** * @internal */ @@ -54,60 +44,6 @@ const createSignOut = () => { }; }; -type UseAuthReturn = - | { - isLoaded: false; - isSignedIn: undefined; - userId: undefined; - sessionId: undefined; - actor: undefined; - orgId: undefined; - orgRole: undefined; - orgSlug: undefined; - has: CheckAuthorizationSignedOut; - signOut: SignOut; - getToken: GetToken; - } - | { - isLoaded: true; - isSignedIn: false; - userId: null; - sessionId: null; - actor: null; - orgId: null; - orgRole: null; - orgSlug: null; - has: CheckAuthorizationWithoutOrgOrUser; - signOut: SignOut; - getToken: GetToken; - } - | { - isLoaded: true; - isSignedIn: true; - userId: string; - sessionId: string; - actor: ActJWTClaim | null; - orgId: null; - orgRole: null; - orgSlug: null; - has: CheckAuthorizationWithoutOrgOrUser; - signOut: SignOut; - getToken: GetToken; - } - | { - isLoaded: true; - isSignedIn: true; - userId: string; - sessionId: string; - actor: ActJWTClaim | null; - orgId: string; - orgRole: OrganizationCustomRoleKey; - orgSlug: string | null; - has: CheckAuthorizationWithCustomPermissions; - signOut: SignOut; - getToken: GetToken; - }; - type UseAuth = () => UseAuthReturn; /** @@ -147,8 +83,8 @@ export const useAuth: UseAuth = () => { const getToken: GetToken = useCallback(createGetToken(), []); const signOut: SignOut = useCallback(createSignOut(), []); - const has = useCallback( - (params: Parameters[0]) => { + const has = useCallback>( + params => { if (!params?.permission && !params?.role) { throw new Error( 'Missing parameters. `has` from `useAuth` requires a permission or role key to be passed. Example usage: `has({permission: "org:posts:edit"`', From 46e1b3dffadf7aace98f0d528330aab1b239e5b1 Mon Sep 17 00:00:00 2001 From: ijxy <32483798+ijxy@users.noreply.github.com> Date: Fri, 20 Dec 2024 12:13:59 +0000 Subject: [PATCH 3/4] feat(astro,clerk-react,types,vue): expose `sessionClaims` from `useAuth` hook --- .changeset/honest-oranges-accept.md | 8 +++ packages/astro/src/react/hooks.ts | 10 +++- packages/react/src/contexts/AuthContext.ts | 3 +- .../src/hooks/__tests__/useAuth.test.tsx | 60 +++++++++++++------ packages/react/src/hooks/useAuth.ts | 13 +++- packages/types/src/hooks.ts | 10 +++- packages/vue/src/composables/useAuth.ts | 10 +++- packages/vue/src/plugin.ts | 4 +- packages/vue/src/types.ts | 2 + 9 files changed, 86 insertions(+), 34 deletions(-) create mode 100644 .changeset/honest-oranges-accept.md diff --git a/.changeset/honest-oranges-accept.md b/.changeset/honest-oranges-accept.md new file mode 100644 index 00000000000..94e7dfa4f38 --- /dev/null +++ b/.changeset/honest-oranges-accept.md @@ -0,0 +1,8 @@ +--- +'@clerk/astro': patch +'@clerk/clerk-react': patch +'@clerk/types': patch +'@clerk/vue': patch +--- + +Expose `sessionClaims` from `useAuth` hooks diff --git a/packages/astro/src/react/hooks.ts b/packages/astro/src/react/hooks.ts index 6acc982a932..7950377d58e 100644 --- a/packages/astro/src/react/hooks.ts +++ b/packages/astro/src/react/hooks.ts @@ -78,7 +78,7 @@ type UseAuth = () => UseAuthReturn; * } */ export const useAuth: UseAuth = () => { - const { sessionId, userId, actor, orgId, orgRole, orgSlug, orgPermissions } = useStore($authStore); + const { sessionId, sessionClaims, userId, actor, orgId, orgRole, orgSlug, orgPermissions } = useStore($authStore); const getToken: GetToken = useCallback(createGetToken(), []); const signOut: SignOut = useCallback(createSignOut(), []); @@ -113,6 +113,7 @@ export const useAuth: UseAuth = () => { isLoaded: false, isSignedIn: undefined, sessionId, + sessionClaims: undefined, userId, actor: undefined, orgId: undefined, @@ -129,6 +130,7 @@ export const useAuth: UseAuth = () => { isLoaded: true, isSignedIn: false, sessionId, + sessionClaims: null, userId, actor: null, orgId: null, @@ -140,11 +142,12 @@ export const useAuth: UseAuth = () => { }; } - if (!!sessionId && !!userId && !!orgId && !!orgRole) { + if (!!sessionId && !!sessionClaims && !!userId && !!orgId && !!orgRole) { return { isLoaded: true, isSignedIn: true, sessionId, + sessionClaims, userId, actor: actor || null, orgId, @@ -156,11 +159,12 @@ export const useAuth: UseAuth = () => { }; } - if (!!sessionId && !!userId && !orgId) { + if (!!sessionId && !!sessionClaims && !!userId && !orgId) { return { isLoaded: true, isSignedIn: true, sessionId, + sessionClaims, userId, actor: actor || null, orgId: null, diff --git a/packages/react/src/contexts/AuthContext.ts b/packages/react/src/contexts/AuthContext.ts index 02d39196200..bed3baf52bd 100644 --- a/packages/react/src/contexts/AuthContext.ts +++ b/packages/react/src/contexts/AuthContext.ts @@ -1,9 +1,10 @@ import { createContextAndHook } from '@clerk/shared/react'; -import type { ActJWTClaim, OrganizationCustomPermissionKey, OrganizationCustomRoleKey } from '@clerk/types'; +import type { ActJWTClaim, JwtPayload, OrganizationCustomPermissionKey, OrganizationCustomRoleKey } from '@clerk/types'; export type AuthContextValue = { userId: string | null | undefined; sessionId: string | null | undefined; + sessionClaims: JwtPayload | null | undefined; actor: ActJWTClaim | null | undefined; orgId: string | null | undefined; orgRole: OrganizationCustomRoleKey | null | undefined; diff --git a/packages/react/src/hooks/__tests__/useAuth.test.tsx b/packages/react/src/hooks/__tests__/useAuth.test.tsx index c4272cff3b4..03bc16519ce 100644 --- a/packages/react/src/hooks/__tests__/useAuth.test.tsx +++ b/packages/react/src/hooks/__tests__/useAuth.test.tsx @@ -1,6 +1,6 @@ import { createCheckAuthorization } from '@clerk/shared/authorization'; import { ClerkInstanceContext } from '@clerk/shared/react'; -import type { LoadedClerk } from '@clerk/types'; +import type { LoadedClerk, UseAuthReturn } from '@clerk/types'; import { render, renderHook } from '@testing-library/react'; import React from 'react'; import { afterAll, beforeAll, beforeEach, describe, expect, it, test, vi } from 'vitest'; @@ -24,6 +24,21 @@ vi.mock('../../errors/errorThrower', () => ({ }, })); +const stubSessionClaims = (input: { + sessionId: string; + userId: string; + orgId?: string; +}): NonNullable => ({ + __raw: '', + exp: 1, + iat: 1, + iss: '', + nbf: 1, + sid: input.sessionId, + sub: input.userId, + org_id: input.orgId, +}); + const TestComponent = () => { const { isLoaded, isSignedIn } = useAuth(); return ( @@ -77,6 +92,7 @@ describe('useDerivedAuth', () => { expect(current.isLoaded).toBe(false); expect(current.isSignedIn).toBeUndefined(); expect(current.sessionId).toBeUndefined(); + expect(current.sessionClaims).toBeUndefined(); expect(current.userId).toBeUndefined(); expect(current.actor).toBeUndefined(); expect(current.orgId).toBeUndefined(); @@ -92,6 +108,7 @@ describe('useDerivedAuth', () => { expect(current.isLoaded).toBe(true); expect(current.isSignedIn).toBe(false); expect(current.sessionId).toBeNull(); + expect(current.sessionClaims).toBeNull(); expect(current.userId).toBeNull(); expect(current.actor).toBeNull(); expect(current.orgId).toBeNull(); @@ -104,14 +121,15 @@ describe('useDerivedAuth', () => { it('returns signed in with org context when sessionId, userId, orgId, and orgRole are present', () => { const authObject = { sessionId: 'session123', + sessionClaims: stubSessionClaims({ sessionId: 'session123', userId: 'user123' }), userId: 'user123', - actor: 'actor123', + actor: { sub: 'actor123' }, orgId: 'org123', orgRole: 'admin', orgSlug: 'my-org', signOut: vi.fn(), getToken: vi.fn(), - }; + } satisfies Partial; const { result: { current }, @@ -119,12 +137,13 @@ describe('useDerivedAuth', () => { expect(current.isLoaded).toBe(true); expect(current.isSignedIn).toBe(true); - expect(current.sessionId).toBe('session123'); - expect(current.userId).toBe('user123'); - expect(current.actor).toBe('actor123'); - expect(current.orgId).toBe('org123'); - expect(current.orgRole).toBe('admin'); - expect(current.orgSlug).toBe('my-org'); + expect(current.sessionId).toBe(authObject.sessionId); + expect(current.userId).toBe(authObject.userId); + expect(current.sessionClaims).toBe(authObject.sessionClaims); + expect(current.actor?.sub).toBe(authObject.actor.sub); + expect(current.orgId).toBe(authObject.orgId); + expect(current.orgRole).toBe(authObject.orgRole); + expect(current.orgSlug).toBe(authObject.orgSlug); expect(typeof current.has).toBe('function'); expect(current.signOut).toBe(authObject.signOut); expect(current.getToken).toBe(authObject.getToken); @@ -136,21 +155,23 @@ describe('useDerivedAuth', () => { it('returns signed in without org context when sessionId and userId are present but no orgId', () => { const authObject = { - sessionId: 'session123', userId: 'user123', - actor: 'actor123', + sessionId: 'session123', + sessionClaims: stubSessionClaims({ sessionId: 'session123', userId: 'user123' }), + actor: { sub: 'actor123' }, signOut: vi.fn(), getToken: vi.fn(), - }; + } satisfies Partial; const { result: { current }, } = renderHook(() => useDerivedAuth(authObject)); expect(current.isLoaded).toBe(true); expect(current.isSignedIn).toBe(true); - expect(current.sessionId).toBe('session123'); - expect(current.userId).toBe('user123'); - expect(current.actor).toBe('actor123'); + expect(current.sessionId).toBe(authObject.sessionId); + expect(current.userId).toBe(authObject.userId); + expect(current.sessionClaims).toBe(authObject.sessionClaims); + expect(current.actor?.sub).toBe(authObject.actor.sub); expect(current.orgId).toBeNull(); expect(current.orgRole).toBeNull(); expect(current.orgSlug).toBeNull(); @@ -165,9 +186,9 @@ describe('useDerivedAuth', () => { it('throws invalid state error if none of the conditions match', () => { const authObject = { - sessionId: true, userId: undefined, - }; + sessionId: 'session123', + } satisfies Partial; renderHook(() => useDerivedAuth(authObject)); // eslint-disable-next-line @typescript-eslint/unbound-method @@ -177,10 +198,11 @@ describe('useDerivedAuth', () => { it('uses provided has function if available', () => { const mockHas = vi.fn().mockReturnValue('mocked-result'); const authObject = { - sessionId: 'session123', userId: 'user123', + sessionId: 'session123', + sessionClaims: stubSessionClaims({ sessionId: 'session123', userId: 'user123' }), has: mockHas, - }; + } satisfies Partial; const { result: { current }, } = renderHook(() => useDerivedAuth(authObject)); diff --git a/packages/react/src/hooks/useAuth.ts b/packages/react/src/hooks/useAuth.ts index 4598fd4226b..6af4d5020bb 100644 --- a/packages/react/src/hooks/useAuth.ts +++ b/packages/react/src/hooks/useAuth.ts @@ -57,7 +57,8 @@ export const useAuth: UseAuth = (initialAuthState = {}) => { authContext = initialAuthState != null ? initialAuthState : {}; } - const { sessionId, userId, actor, orgId, orgRole, orgSlug, orgPermissions, factorVerificationAge } = authContext; + const { sessionId, sessionClaims, userId, actor, orgId, orgRole, orgSlug, orgPermissions, factorVerificationAge } = + authContext; const isomorphicClerk = useIsomorphicClerkContext(); const getToken: GetToken = useCallback(createGetToken(isomorphicClerk), [isomorphicClerk]); @@ -65,6 +66,7 @@ export const useAuth: UseAuth = (initialAuthState = {}) => { return useDerivedAuth({ sessionId, + sessionClaims, userId, actor, orgId, @@ -106,6 +108,7 @@ export const useAuth: UseAuth = (initialAuthState = {}) => { export function useDerivedAuth(authObject: any): UseAuthReturn { const { sessionId, + sessionClaims, userId, actor, orgId, @@ -139,6 +142,7 @@ export function useDerivedAuth(authObject: any): UseAuthReturn { isLoaded: false, isSignedIn: undefined, sessionId, + sessionClaims: undefined, userId, actor: undefined, orgId: undefined, @@ -155,6 +159,7 @@ export function useDerivedAuth(authObject: any): UseAuthReturn { isLoaded: true, isSignedIn: false, sessionId, + sessionClaims: null, userId, actor: null, orgId: null, @@ -166,11 +171,12 @@ export function useDerivedAuth(authObject: any): UseAuthReturn { }; } - if (!!sessionId && !!userId && !!orgId && !!orgRole) { + if (!!sessionId && !!sessionClaims && !!userId && !!orgId && !!orgRole) { return { isLoaded: true, isSignedIn: true, sessionId, + sessionClaims, userId, actor: actor || null, orgId, @@ -182,11 +188,12 @@ export function useDerivedAuth(authObject: any): UseAuthReturn { }; } - if (!!sessionId && !!userId && !orgId) { + if (!!sessionId && !!sessionClaims && !!userId && !orgId) { return { isLoaded: true, isSignedIn: true, sessionId, + sessionClaims, userId, actor: actor || null, orgId: null, diff --git a/packages/types/src/hooks.ts b/packages/types/src/hooks.ts index 1b5d4ab0b0c..1e02915c735 100644 --- a/packages/types/src/hooks.ts +++ b/packages/types/src/hooks.ts @@ -1,14 +1,14 @@ -import type { OrganizationCustomRoleKey } from 'organizationMembership'; -import type { SignInResource } from 'signIn'; - import type { SetActive, SignOut } from './clerk'; import type { ActJWTClaim } from './jwt'; +import type { JwtPayload } from './jwtv2'; +import type { OrganizationCustomRoleKey } from './organizationMembership'; import type { ActiveSessionResource, CheckAuthorizationWithCustomPermissions, GetToken, SessionResource, } from './session'; +import type { SignInResource } from './signIn'; import type { SignUpResource } from './signUp'; import type { UserResource } from './user'; @@ -21,6 +21,7 @@ export type UseAuthReturn = isSignedIn: undefined; userId: undefined; sessionId: undefined; + sessionClaims: undefined; actor: undefined; orgId: undefined; orgRole: undefined; @@ -34,6 +35,7 @@ export type UseAuthReturn = isSignedIn: false; userId: null; sessionId: null; + sessionClaims: null; actor: null; orgId: null; orgRole: null; @@ -47,6 +49,7 @@ export type UseAuthReturn = isSignedIn: true; userId: string; sessionId: string; + sessionClaims: JwtPayload; actor: ActJWTClaim | null; orgId: null; orgRole: null; @@ -60,6 +63,7 @@ export type UseAuthReturn = isSignedIn: true; userId: string; sessionId: string; + sessionClaims: JwtPayload; actor: ActJWTClaim | null; orgId: string; orgRole: OrganizationCustomRoleKey; diff --git a/packages/vue/src/composables/useAuth.ts b/packages/vue/src/composables/useAuth.ts index 3a39de0734a..d9854f7285c 100644 --- a/packages/vue/src/composables/useAuth.ts +++ b/packages/vue/src/composables/useAuth.ts @@ -74,7 +74,7 @@ export const useAuth: UseAuth = () => { const { clerk, authCtx } = useClerkContext(); const result = computed(() => { - const { sessionId, userId, actor, orgId, orgRole, orgSlug, orgPermissions } = authCtx.value; + const { sessionId, sessionClaims, userId, actor, orgId, orgRole, orgSlug, orgPermissions } = authCtx.value; const getToken: GetToken = createGetToken(clerk); const signOut: SignOut = createSignOut(clerk); @@ -103,6 +103,7 @@ export const useAuth: UseAuth = () => { isLoaded: false, isSignedIn: undefined, sessionId, + sessionClaims: undefined, userId, actor: undefined, orgId: undefined, @@ -119,6 +120,7 @@ export const useAuth: UseAuth = () => { isLoaded: true, isSignedIn: false, sessionId, + sessionClaims: null, userId, actor: null, orgId: null, @@ -130,11 +132,12 @@ export const useAuth: UseAuth = () => { }; } - if (!!sessionId && !!userId && !!orgId && !!orgRole) { + if (!!sessionId && !!sessionClaims && !!userId && !!orgId && !!orgRole) { return { isLoaded: true, isSignedIn: true, sessionId, + sessionClaims, userId, actor: actor || null, orgId, @@ -146,11 +149,12 @@ export const useAuth: UseAuth = () => { }; } - if (!!sessionId && !!userId && !orgId) { + if (!!sessionId && !!sessionClaims && !!userId && !orgId) { return { isLoaded: true, isSignedIn: true, sessionId, + sessionClaims, userId, actor: actor || null, orgId: null, diff --git a/packages/vue/src/plugin.ts b/packages/vue/src/plugin.ts index ab5acddaffc..92b97e0e294 100644 --- a/packages/vue/src/plugin.ts +++ b/packages/vue/src/plugin.ts @@ -70,8 +70,8 @@ export const clerkPlugin: Plugin = { const derivedState = computed(() => deriveState(loaded.value, resources.value, initialState)); const authCtx = computed(() => { - const { sessionId, userId, orgId, actor, orgRole, orgSlug, orgPermissions } = derivedState.value; - return { sessionId, userId, actor, orgId, orgRole, orgSlug, orgPermissions }; + const { sessionId, sessionClaims, userId, orgId, actor, orgRole, orgSlug, orgPermissions } = derivedState.value; + return { sessionId, sessionClaims, userId, actor, orgId, orgRole, orgSlug, orgPermissions }; }); const clientCtx = computed(() => resources.value.client); const userCtx = computed(() => derivedState.value.user); diff --git a/packages/vue/src/types.ts b/packages/vue/src/types.ts index 213c909b658..beb66959411 100644 --- a/packages/vue/src/types.ts +++ b/packages/vue/src/types.ts @@ -6,6 +6,7 @@ import type { ClientResource, CustomMenuItem, CustomPage, + JwtPayload, OrganizationCustomPermissionKey, OrganizationCustomRoleKey, OrganizationResource, @@ -19,6 +20,7 @@ export interface VueClerkInjectionKeyType { authCtx: ComputedRef<{ userId: string | null | undefined; sessionId: string | null | undefined; + sessionClaims: JwtPayload | null | undefined; actor: ActJWTClaim | null | undefined; orgId: string | null | undefined; orgRole: OrganizationCustomRoleKey | null | undefined; From 108527f0fa43dae638bb52ba9961251b93131e2d Mon Sep 17 00:00:00 2001 From: ijxy <32483798+ijxy@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:04:48 +0000 Subject: [PATCH 4/4] refactor(types): consistent import paths --- packages/types/src/authConfig.ts | 3 +-- packages/types/src/clerk.ts | 5 ++--- packages/types/src/client.ts | 3 +-- packages/types/src/displayConfig.ts | 3 +-- packages/types/src/emailAddress.ts | 3 +-- packages/types/src/enterpriseAccount.ts | 9 ++++----- packages/types/src/environment.ts | 3 +-- packages/types/src/externalAccount.ts | 3 +-- packages/types/src/identificationLink.ts | 3 +-- packages/types/src/organization.ts | 3 +-- packages/types/src/organizationMembership.ts | 3 +-- packages/types/src/organizationSettings.ts | 3 +-- packages/types/src/passkey.ts | 3 +-- packages/types/src/phoneNumber.ts | 3 +-- packages/types/src/samlAccount.ts | 3 +-- packages/types/src/samlConnection.ts | 3 +-- packages/types/src/session.ts | 3 +-- packages/types/src/signIn.ts | 3 +-- packages/types/src/signUp.ts | 3 +-- packages/types/src/telemetry.ts | 2 +- packages/types/src/token.ts | 3 +-- packages/types/src/user.ts | 3 +-- packages/types/src/userSettings.ts | 3 +-- packages/types/src/verification.ts | 3 +-- packages/types/src/web3Wallet.ts | 3 +-- 25 files changed, 29 insertions(+), 53 deletions(-) diff --git a/packages/types/src/authConfig.ts b/packages/types/src/authConfig.ts index 529f1e6fd79..35962a9a46c 100644 --- a/packages/types/src/authConfig.ts +++ b/packages/types/src/authConfig.ts @@ -1,6 +1,5 @@ -import type { AuthConfigJSONSnapshot } from 'snapshots'; - import type { ClerkResource } from './resource'; +import type { AuthConfigJSONSnapshot } from './snapshots'; export interface AuthConfigResource extends ClerkResource { /** diff --git a/packages/types/src/clerk.ts b/packages/types/src/clerk.ts index 464886a76fa..6dee956da43 100644 --- a/packages/types/src/clerk.ts +++ b/packages/types/src/clerk.ts @@ -1,6 +1,3 @@ -import type { ClientJSONSnapshot, EnvironmentJSONSnapshot } from 'snapshots'; -import type { TelemetryCollector } from 'telemetry'; - import type { Appearance, CreateOrganizationTheme, @@ -39,7 +36,9 @@ import type { ActiveSessionResource } from './session'; import type { SessionVerificationLevel } from './sessionVerification'; import type { SignInResource } from './signIn'; import type { SignUpResource } from './signUp'; +import type { ClientJSONSnapshot, EnvironmentJSONSnapshot } from './snapshots'; import type { Web3Strategy } from './strategies'; +import type { TelemetryCollector } from './telemetry'; import type { UserResource } from './user'; import type { Autocomplete, DeepPartial, DeepSnakeToCamel } from './utils'; import type { WaitlistResource } from './waitlist'; diff --git a/packages/types/src/client.ts b/packages/types/src/client.ts index beee5f5baa7..2169e312c9e 100644 --- a/packages/types/src/client.ts +++ b/packages/types/src/client.ts @@ -1,9 +1,8 @@ -import type { ClientJSONSnapshot } from 'snapshots'; - import type { ClerkResource } from './resource'; import type { ActiveSessionResource, SessionResource } from './session'; import type { SignInResource } from './signIn'; import type { SignUpResource } from './signUp'; +import type { ClientJSONSnapshot } from './snapshots'; export interface ClientResource extends ClerkResource { sessions: SessionResource[]; diff --git a/packages/types/src/displayConfig.ts b/packages/types/src/displayConfig.ts index 301e86b43ee..9f7c5b07ea5 100644 --- a/packages/types/src/displayConfig.ts +++ b/packages/types/src/displayConfig.ts @@ -1,7 +1,6 @@ -import type { DisplayConfigJSONSnapshot } from 'snapshots'; - import type { DisplayThemeJSON } from './json'; import type { ClerkResource } from './resource'; +import type { DisplayConfigJSONSnapshot } from './snapshots'; import type { OAuthStrategy } from './strategies'; export type PreferredSignInStrategy = 'password' | 'otp'; diff --git a/packages/types/src/emailAddress.ts b/packages/types/src/emailAddress.ts index d257860afb0..58a1c0d1e34 100644 --- a/packages/types/src/emailAddress.ts +++ b/packages/types/src/emailAddress.ts @@ -1,7 +1,6 @@ -import type { EmailAddressJSONSnapshot } from 'snapshots'; - import type { IdentificationLinkResource } from './identificationLink'; import type { ClerkResource } from './resource'; +import type { EmailAddressJSONSnapshot } from './snapshots'; import type { EmailCodeStrategy, EmailLinkStrategy } from './strategies'; import type { CreateEmailLinkFlowReturn, StartEmailLinkFlowParams, VerificationResource } from './verification'; diff --git a/packages/types/src/enterpriseAccount.ts b/packages/types/src/enterpriseAccount.ts index f43e405f00f..27db38807e1 100644 --- a/packages/types/src/enterpriseAccount.ts +++ b/packages/types/src/enterpriseAccount.ts @@ -1,9 +1,8 @@ -import type { OAuthProvider } from 'oauth'; -import type { SamlIdpSlug } from 'saml'; -import type { EnterpriseAccountConnectionJSONSnapshot, EnterpriseAccountJSONSnapshot } from 'snapshots'; -import type { VerificationResource } from 'verification'; - +import type { OAuthProvider } from './oauth'; import type { ClerkResource } from './resource'; +import type { SamlIdpSlug } from './saml'; +import type { EnterpriseAccountConnectionJSONSnapshot, EnterpriseAccountJSONSnapshot } from './snapshots'; +import type { VerificationResource } from './verification'; export type EnterpriseProtocol = 'saml' | 'oauth'; diff --git a/packages/types/src/environment.ts b/packages/types/src/environment.ts index 320fa78bf2f..a6aff8ca83b 100644 --- a/packages/types/src/environment.ts +++ b/packages/types/src/environment.ts @@ -1,9 +1,8 @@ -import type { EnvironmentJSONSnapshot } from 'snapshots'; - import type { AuthConfigResource } from './authConfig'; import type { DisplayConfigResource } from './displayConfig'; import type { OrganizationSettingsResource } from './organizationSettings'; import type { ClerkResource } from './resource'; +import type { EnvironmentJSONSnapshot } from './snapshots'; import type { UserSettingsResource } from './userSettings'; export interface EnvironmentResource extends ClerkResource { diff --git a/packages/types/src/externalAccount.ts b/packages/types/src/externalAccount.ts index b2ab7b6a0be..6f30d3f8e75 100644 --- a/packages/types/src/externalAccount.ts +++ b/packages/types/src/externalAccount.ts @@ -1,7 +1,6 @@ -import type { ExternalAccountJSONSnapshot } from 'snapshots'; - import type { OAuthProvider, OAuthScope } from './oauth'; import type { ClerkResource } from './resource'; +import type { ExternalAccountJSONSnapshot } from './snapshots'; import type { VerificationResource } from './verification'; export type ReauthorizeExternalAccountParams = { diff --git a/packages/types/src/identificationLink.ts b/packages/types/src/identificationLink.ts index 462587b85ea..0181397713f 100644 --- a/packages/types/src/identificationLink.ts +++ b/packages/types/src/identificationLink.ts @@ -1,6 +1,5 @@ -import type { IdentificationLinkJSONSnapshot } from 'snapshots'; - import type { ClerkResource } from './resource'; +import type { IdentificationLinkJSONSnapshot } from './snapshots'; export interface IdentificationLinkResource extends ClerkResource { id: string; diff --git a/packages/types/src/organization.ts b/packages/types/src/organization.ts index ed51567472e..a749bb6d9b5 100644 --- a/packages/types/src/organization.ts +++ b/packages/types/src/organization.ts @@ -1,5 +1,3 @@ -import type { OrganizationJSONSnapshot } from 'snapshots'; - import type { OrganizationDomainResource, OrganizationEnrollmentMode } from './organizationDomain'; import type { OrganizationInvitationResource, OrganizationInvitationStatus } from './organizationInvitation'; import type { OrganizationCustomRoleKey, OrganizationMembershipResource } from './organizationMembership'; @@ -7,6 +5,7 @@ import type { OrganizationMembershipRequestResource } from './organizationMember import type { ClerkPaginatedResponse, ClerkPaginationParams } from './pagination'; import type { ClerkResource } from './resource'; import type { RoleResource } from './role'; +import type { OrganizationJSONSnapshot } from './snapshots'; declare global { /** diff --git a/packages/types/src/organizationMembership.ts b/packages/types/src/organizationMembership.ts index 8a010d19911..4c3bb68fc5f 100644 --- a/packages/types/src/organizationMembership.ts +++ b/packages/types/src/organizationMembership.ts @@ -1,8 +1,7 @@ -import type { OrganizationMembershipJSONSnapshot } from 'snapshots'; - import type { OrganizationResource } from './organization'; import type { ClerkResource } from './resource'; import type { PublicUserData } from './session'; +import type { OrganizationMembershipJSONSnapshot } from './snapshots'; import type { Autocomplete } from './utils'; interface Base { diff --git a/packages/types/src/organizationSettings.ts b/packages/types/src/organizationSettings.ts index 6cadacebca7..0e5041508c4 100644 --- a/packages/types/src/organizationSettings.ts +++ b/packages/types/src/organizationSettings.ts @@ -1,8 +1,7 @@ -import type { OrganizationSettingsJSONSnapshot } from 'snapshots'; - import type { ClerkResourceJSON } from './json'; import type { OrganizationEnrollmentMode } from './organizationDomain'; import type { ClerkResource } from './resource'; +import type { OrganizationSettingsJSONSnapshot } from './snapshots'; export interface OrganizationSettingsJSON extends ClerkResourceJSON { id: never; diff --git a/packages/types/src/passkey.ts b/packages/types/src/passkey.ts index f8a9a879a6b..55ec879e33a 100644 --- a/packages/types/src/passkey.ts +++ b/packages/types/src/passkey.ts @@ -1,8 +1,7 @@ -import type { PasskeyJSONSnapshot } from 'snapshots'; - import type { DeletedObjectResource } from './deletedObject'; import type { PasskeyJSON } from './json'; import type { ClerkResource } from './resource'; +import type { PasskeyJSONSnapshot } from './snapshots'; import type { SnakeToCamel } from './utils'; import type { PasskeyVerificationResource } from './verification'; diff --git a/packages/types/src/phoneNumber.ts b/packages/types/src/phoneNumber.ts index 36bb32574ee..a36f0fb4d94 100644 --- a/packages/types/src/phoneNumber.ts +++ b/packages/types/src/phoneNumber.ts @@ -1,7 +1,6 @@ -import type { PhoneNumberJSONSnapshot } from 'snapshots'; - import type { IdentificationLinkResource } from './identificationLink'; import type { ClerkResource } from './resource'; +import type { PhoneNumberJSONSnapshot } from './snapshots'; import type { PhoneCodeStrategy } from './strategies'; import type { VerificationResource } from './verification'; diff --git a/packages/types/src/samlAccount.ts b/packages/types/src/samlAccount.ts index 8bfa969ff21..8b557def659 100644 --- a/packages/types/src/samlAccount.ts +++ b/packages/types/src/samlAccount.ts @@ -1,8 +1,7 @@ -import type { SamlAccountJSONSnapshot } from 'snapshots'; - import type { ClerkResource } from './resource'; import type { SamlIdpSlug } from './saml'; import type { SamlAccountConnectionResource } from './samlConnection'; +import type { SamlAccountJSONSnapshot } from './snapshots'; import type { VerificationResource } from './verification'; export interface SamlAccountResource extends ClerkResource { diff --git a/packages/types/src/samlConnection.ts b/packages/types/src/samlConnection.ts index 678878c8c2d..072c521d4ef 100644 --- a/packages/types/src/samlConnection.ts +++ b/packages/types/src/samlConnection.ts @@ -1,6 +1,5 @@ -import type { SamlAccountConnectionJSONSnapshot } from 'snapshots'; - import type { ClerkResource } from './resource'; +import type { SamlAccountConnectionJSONSnapshot } from './snapshots'; export interface SamlAccountConnectionResource extends ClerkResource { id: string; diff --git a/packages/types/src/session.ts b/packages/types/src/session.ts index 028ceacee31..3504df41da9 100644 --- a/packages/types/src/session.ts +++ b/packages/types/src/session.ts @@ -1,5 +1,3 @@ -import type { SessionJSONSnapshot } from 'snapshots'; - import type { BackupCodeAttempt, EmailCodeAttempt, @@ -22,6 +20,7 @@ import type { SessionVerificationLevel, SessionVerificationResource, } from './sessionVerification'; +import type { SessionJSONSnapshot } from './snapshots'; import type { TokenResource } from './token'; import type { UserResource } from './user'; diff --git a/packages/types/src/signIn.ts b/packages/types/src/signIn.ts index cca2951dcf2..6579bcbaf4b 100644 --- a/packages/types/src/signIn.ts +++ b/packages/types/src/signIn.ts @@ -1,5 +1,3 @@ -import type { SignInJSONSnapshot } from 'snapshots'; - import type { BackupCodeAttempt, BackupCodeFactor, @@ -51,6 +49,7 @@ import type { import type { ValidatePasswordCallbacks } from './passwords'; import type { AuthenticateWithRedirectParams } from './redirects'; import type { ClerkResource } from './resource'; +import type { SignInJSONSnapshot } from './snapshots'; import type { BackupCodeStrategy, EmailCodeStrategy, diff --git a/packages/types/src/signUp.ts b/packages/types/src/signUp.ts index 8dd84f5a4d7..9498533a349 100644 --- a/packages/types/src/signUp.ts +++ b/packages/types/src/signUp.ts @@ -1,5 +1,3 @@ -import type { SignUpJSONSnapshot, SignUpVerificationJSONSnapshot, SignUpVerificationsJSONSnapshot } from 'snapshots'; - import type { FirstNameAttribute, LastNameAttribute, LegalAcceptedAttribute, PasswordAttribute } from './attributes'; import type { AttemptEmailAddressVerificationParams, PrepareEmailAddressVerificationParams } from './emailAddress'; import type { @@ -13,6 +11,7 @@ import type { ValidatePasswordCallbacks } from './passwords'; import type { AttemptPhoneNumberVerificationParams, PreparePhoneNumberVerificationParams } from './phoneNumber'; import type { AuthenticateWithRedirectParams } from './redirects'; import type { ClerkResource } from './resource'; +import type { SignUpJSONSnapshot, SignUpVerificationJSONSnapshot, SignUpVerificationsJSONSnapshot } from './snapshots'; import type { EmailCodeStrategy, EmailLinkStrategy, diff --git a/packages/types/src/telemetry.ts b/packages/types/src/telemetry.ts index a6db48b5f72..3b7f945deff 100644 --- a/packages/types/src/telemetry.ts +++ b/packages/types/src/telemetry.ts @@ -1,4 +1,4 @@ -import type { InstanceType } from 'instance'; +import type { InstanceType } from './instance'; /** * @internal diff --git a/packages/types/src/token.ts b/packages/types/src/token.ts index 2101452df11..f5ed50fa5ae 100644 --- a/packages/types/src/token.ts +++ b/packages/types/src/token.ts @@ -1,7 +1,6 @@ -import type { TokenJSONSnapshot } from 'snapshots'; - import type { JWT } from './jwt'; import type { ClerkResource } from './resource'; +import type { TokenJSONSnapshot } from './snapshots'; export interface TokenResource extends ClerkResource { jwt?: JWT; diff --git a/packages/types/src/user.ts b/packages/types/src/user.ts index a6cc92aef91..1dbfa73a147 100644 --- a/packages/types/src/user.ts +++ b/packages/types/src/user.ts @@ -1,5 +1,3 @@ -import type { UserJSONSnapshot } from 'snapshots'; - import type { BackupCodeResource } from './backupCode'; import type { DeletedObjectResource } from './deletedObject'; import type { EmailAddressResource } from './emailAddress'; @@ -17,6 +15,7 @@ import type { PhoneNumberResource } from './phoneNumber'; import type { ClerkResource } from './resource'; import type { SamlAccountResource } from './samlAccount'; import type { SessionWithActivitiesResource } from './session'; +import type { UserJSONSnapshot } from './snapshots'; import type { OAuthStrategy } from './strategies'; import type { TOTPResource } from './totp'; import type { UserOrganizationInvitationResource } from './userOrganizationInvitation'; diff --git a/packages/types/src/userSettings.ts b/packages/types/src/userSettings.ts index f8dab67246c..14f61143d5b 100644 --- a/packages/types/src/userSettings.ts +++ b/packages/types/src/userSettings.ts @@ -1,7 +1,6 @@ -import type { UserSettingsJSONSnapshot } from 'snapshots'; - import type { ClerkResourceJSON } from './json'; import type { ClerkResource } from './resource'; +import type { UserSettingsJSONSnapshot } from './snapshots'; import type { OAuthStrategy, Web3Strategy } from './strategies'; export type Attribute = diff --git a/packages/types/src/verification.ts b/packages/types/src/verification.ts index 9cb143cb3f0..f4e5e40b3f1 100644 --- a/packages/types/src/verification.ts +++ b/packages/types/src/verification.ts @@ -1,8 +1,7 @@ -import type { VerificationJSONSnapshot } from 'snapshots'; - import type { ClerkAPIError } from './api'; import type { PublicKeyCredentialCreationOptionsWithoutExtensions } from './passkey'; import type { ClerkResource } from './resource'; +import type { VerificationJSONSnapshot } from './snapshots'; export interface VerificationResource extends ClerkResource { attempts: number | null; diff --git a/packages/types/src/web3Wallet.ts b/packages/types/src/web3Wallet.ts index 5921b91c569..62dec1eb68d 100644 --- a/packages/types/src/web3Wallet.ts +++ b/packages/types/src/web3Wallet.ts @@ -1,6 +1,5 @@ -import type { Web3WalletJSONSnapshot } from 'snapshots'; - import type { ClerkResource } from './resource'; +import type { Web3WalletJSONSnapshot } from './snapshots'; import type { Web3Strategy } from './strategies'; import type { VerificationResource } from './verification'; import type { Web3Provider } from './web3';