@@ -8,6 +8,7 @@ import { useSeamQueryContext } from './SeamQueryProvider.js'
88export function useSeamClient ( ) : {
99 client : SeamHttp | null
1010 endpointClient : SeamHttpEndpoints | null
11+ queryKeyPrefix : string [ ]
1112 isPending : boolean
1213 isError : boolean
1314 error : unknown
@@ -17,6 +18,7 @@ export function useSeamClient(): {
1718 clientOptions,
1819 publishableKey,
1920 clientSessionToken,
21+ queryKeyPrefix,
2022 ...context
2123 } = useSeamQueryContext ( )
2224 const userIdentifierKey = useUserIdentifierKeyOrFingerprint (
@@ -27,6 +29,7 @@ export function useSeamClient(): {
2729 [ SeamHttp , SeamHttpEndpoints ]
2830 > ( {
2931 queryKey : [
32+ 'seam' ,
3033 'client' ,
3134 {
3235 client,
@@ -73,6 +76,15 @@ export function useSeamClient(): {
7376 return {
7477 client : data ?. [ 0 ] ?? null ,
7578 endpointClient : data ?. [ 1 ] ?? null ,
79+ queryKeyPrefix : [
80+ 'seam' ,
81+ queryKeyPrefix ??
82+ getQueryKeyPrefix ( {
83+ userIdentifierKey,
84+ publishableKey,
85+ clientSessionToken,
86+ } ) ,
87+ ] ,
7688 isPending,
7789 isError,
7890 error,
@@ -117,3 +129,23 @@ This is not recommended because the client session is now bound to this machine
117129
118130 return fingerprint
119131}
132+
133+ const getQueryKeyPrefix = ( {
134+ userIdentifierKey,
135+ publishableKey,
136+ clientSessionToken,
137+ } : {
138+ userIdentifierKey : string
139+ publishableKey : string | undefined
140+ clientSessionToken : string | undefined
141+ } ) : string => {
142+ if ( clientSessionToken != null ) {
143+ return clientSessionToken
144+ }
145+
146+ if ( publishableKey != null ) {
147+ return [ publishableKey , userIdentifierKey ] . join ( ':' )
148+ }
149+
150+ throw new Error ( 'Could not determine a queryKeyPrefix' )
151+ }
0 commit comments