Skip to content
Open
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
6 changes: 6 additions & 0 deletions packages/shared/src/react/hooks/createCacheKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export function createCacheKeys<
U extends Record<string, unknown> | undefined = undefined,
>(params: {
stablePrefix: ResourceCacheStableKey | __internal_ResourceCacheStableKey;
/**
* Describes queries that will contain data that require a user to be authenticated.
*
* `authenticated` should be not be resolved at runtime.
* When`authenticated: true` use it with `useClearQueriesOnSignOut` to automatically clear the cache entries associated with the cache key when a user signs out.
*/
authenticated: boolean;
tracked: T;
untracked: U extends { args: Params } ? U : never;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export function useOrganizationCreationDefaultsCacheKeys(params: { userId: strin
return useMemo(() => {
return createCacheKeys({
stablePrefix: STABLE_KEYS.ORGANIZATION_CREATION_DEFAULTS_KEY,
authenticated: Boolean(userId),
authenticated: true,
tracked: {
userId: userId ?? null,
userId,
},
untracked: {
args: {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useClearQueriesOnSignOut } from '@/react/hooks/useClearQueriesOnSignOut';

import { eventMethodCalled } from '../../telemetry/events/method-called';
import type { EnvironmentResource } from '../../types/environment';
import { defineKeepPreviousDataFn } from '../clerk-rq/keep-previous-data';
Expand Down Expand Up @@ -50,7 +52,13 @@ export function useOrganizationCreationDefaults(

clerk.telemetry?.record(eventMethodCalled(HOOK_NAME));

const { queryKey } = useOrganizationCreationDefaultsCacheKeys({ userId: user?.id ?? null });
const { queryKey, authenticated, stableKey } = useOrganizationCreationDefaultsCacheKeys({ userId: user?.id ?? null });

useClearQueriesOnSignOut({
isSignedOut: user === null, // works with the transitive state
authenticated,
stableKeys: stableKey,
});

const queryEnabled = Boolean(user) && enabled && featureEnabled && clerk.loaded;

Expand Down
Loading