@hipnation-truth/sdk 0.26.10 → 0.26.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react.d.ts +12 -1
- package/dist/react.js +50 -9
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/react.d.ts
CHANGED
|
@@ -2853,6 +2853,17 @@ interface TruthProviderProps {
|
|
|
2853
2853
|
* a ref on every call.
|
|
2854
2854
|
*/
|
|
2855
2855
|
getAuthToken?: AuthTokenFetcher;
|
|
2856
|
+
/**
|
|
2857
|
+
* Whether the caller's identity provider reports a signed-in user.
|
|
2858
|
+
* Optional but RECOMMENDED when `getAuthToken` is wired — pass
|
|
2859
|
+
* `useAuth().isSignedIn` (Clerk). It lets the provider settle to a
|
|
2860
|
+
* signed-out state instantly (no token to fetch) and, crucially,
|
|
2861
|
+
* re-resolve the token the moment the user signs in. When omitted, the
|
|
2862
|
+
* provider falls back to probing `getAuthToken` with a bounded retry to
|
|
2863
|
+
* decide signed-in vs. signed-out, which is robust at load but not
|
|
2864
|
+
* reactive to a later sign-in without a remount.
|
|
2865
|
+
*/
|
|
2866
|
+
isSignedIn?: boolean;
|
|
2856
2867
|
/**
|
|
2857
2868
|
* Synchronous encrypted KV mirror for durable offline reads, injected
|
|
2858
2869
|
* by the consuming app (e.g. MMKV on `ch/`). Omit on web — the SDK
|
|
@@ -2870,7 +2881,7 @@ interface TruthProviderProps {
|
|
|
2870
2881
|
offlineEnabled?: boolean;
|
|
2871
2882
|
children: ReactNode;
|
|
2872
2883
|
}
|
|
2873
|
-
declare function TruthProvider({ environment, convexUrl, apiBaseUrl, apiKey, source, sourceVersion, tenantId, getAuthToken, offlineStore, offlineEnabled, children, }: TruthProviderProps): react.FunctionComponentElement<react.ProviderProps<TruthSdkContextValue | null>>;
|
|
2884
|
+
declare function TruthProvider({ environment, convexUrl, apiBaseUrl, apiKey, source, sourceVersion, tenantId, getAuthToken, isSignedIn, offlineStore, offlineEnabled, children, }: TruthProviderProps): react.FunctionComponentElement<react.ProviderProps<TruthSdkContextValue | null>>;
|
|
2874
2885
|
|
|
2875
2886
|
/**
|
|
2876
2887
|
* React hooks for conversation reminders — bulk lookup keyed by
|
package/dist/react.js
CHANGED
|
@@ -2285,6 +2285,7 @@ function TruthProvider({
|
|
|
2285
2285
|
sourceVersion,
|
|
2286
2286
|
tenantId,
|
|
2287
2287
|
getAuthToken,
|
|
2288
|
+
isSignedIn,
|
|
2288
2289
|
offlineStore = NOOP_STORE,
|
|
2289
2290
|
offlineEnabled = false,
|
|
2290
2291
|
children
|
|
@@ -2310,10 +2311,47 @@ function TruthProvider({
|
|
|
2310
2311
|
}) : void 0,
|
|
2311
2312
|
[hasAuthFetcher]
|
|
2312
2313
|
);
|
|
2313
|
-
const [
|
|
2314
|
+
const [tokenPhase, setTokenPhase] = (0, import_react2.useState)(
|
|
2315
|
+
hasAuthFetcher ? "pending" : "anon"
|
|
2316
|
+
);
|
|
2314
2317
|
(0, import_react2.useEffect)(() => {
|
|
2315
|
-
|
|
2316
|
-
|
|
2318
|
+
if (!hasAuthFetcher) {
|
|
2319
|
+
setTokenPhase("anon");
|
|
2320
|
+
return;
|
|
2321
|
+
}
|
|
2322
|
+
if (isSignedIn === false) {
|
|
2323
|
+
setTokenPhase("anon");
|
|
2324
|
+
return;
|
|
2325
|
+
}
|
|
2326
|
+
let cancelled = false;
|
|
2327
|
+
setTokenPhase("pending");
|
|
2328
|
+
void (() => __async(null, null, function* () {
|
|
2329
|
+
var _a2, _b2;
|
|
2330
|
+
for (let attempt = 0; attempt < 8 && !cancelled; attempt++) {
|
|
2331
|
+
let token = null;
|
|
2332
|
+
try {
|
|
2333
|
+
token = (_b2 = yield (_a2 = getAuthTokenRef.current) == null ? void 0 : _a2.call(getAuthTokenRef, { forceRefreshToken: false })) != null ? _b2 : null;
|
|
2334
|
+
} catch (e) {
|
|
2335
|
+
}
|
|
2336
|
+
if (cancelled) {
|
|
2337
|
+
return;
|
|
2338
|
+
}
|
|
2339
|
+
if (token) {
|
|
2340
|
+
setTokenPhase("authed");
|
|
2341
|
+
return;
|
|
2342
|
+
}
|
|
2343
|
+
yield new Promise(
|
|
2344
|
+
(resolve) => setTimeout(resolve, 300 + attempt * 300)
|
|
2345
|
+
);
|
|
2346
|
+
}
|
|
2347
|
+
if (!cancelled) {
|
|
2348
|
+
setTokenPhase("anon");
|
|
2349
|
+
}
|
|
2350
|
+
}))();
|
|
2351
|
+
return () => {
|
|
2352
|
+
cancelled = true;
|
|
2353
|
+
};
|
|
2354
|
+
}, [hasAuthFetcher, isSignedIn, stableGetAuthToken]);
|
|
2317
2355
|
const fetchAccessToken = (0, import_react2.useCallback)(
|
|
2318
2356
|
(_0) => __async(null, [_0], function* ({
|
|
2319
2357
|
forceRefreshToken
|
|
@@ -2321,7 +2359,6 @@ function TruthProvider({
|
|
|
2321
2359
|
var _a2;
|
|
2322
2360
|
const fetcher = stableGetAuthToken;
|
|
2323
2361
|
if (!fetcher) {
|
|
2324
|
-
setTokenAttempted(true);
|
|
2325
2362
|
return null;
|
|
2326
2363
|
}
|
|
2327
2364
|
let token = null;
|
|
@@ -2331,20 +2368,24 @@ function TruthProvider({
|
|
|
2331
2368
|
if (token) break;
|
|
2332
2369
|
} catch (e) {
|
|
2333
2370
|
}
|
|
2334
|
-
yield new Promise(
|
|
2371
|
+
yield new Promise(
|
|
2372
|
+
(resolve) => setTimeout(resolve, 200 + attempt * 150)
|
|
2373
|
+
);
|
|
2335
2374
|
}
|
|
2336
|
-
setTokenAttempted(true);
|
|
2337
2375
|
return token;
|
|
2338
2376
|
}),
|
|
2339
2377
|
[stableGetAuthToken]
|
|
2340
2378
|
);
|
|
2341
2379
|
const useConvexAuthAdapter = (0, import_react2.useCallback)(
|
|
2342
2380
|
() => ({
|
|
2343
|
-
isLoading: hasAuthFetcher &&
|
|
2344
|
-
|
|
2381
|
+
isLoading: hasAuthFetcher && tokenPhase === "pending",
|
|
2382
|
+
// REAL token presence — see `tokenPhase` above. Flipping this true
|
|
2383
|
+
// only once a token exists is what stops `setAuth` from resuming the
|
|
2384
|
+
// socket unauthenticated on web.
|
|
2385
|
+
isAuthenticated: hasAuthFetcher && tokenPhase === "authed",
|
|
2345
2386
|
fetchAccessToken
|
|
2346
2387
|
}),
|
|
2347
|
-
[hasAuthFetcher,
|
|
2388
|
+
[hasAuthFetcher, tokenPhase, fetchAccessToken]
|
|
2348
2389
|
);
|
|
2349
2390
|
const convexQueryClient = (0, import_react2.useMemo)(
|
|
2350
2391
|
() => new import_react_query.ConvexQueryClient(convexClient),
|