@hipnation-truth/sdk 0.26.6 → 0.26.7
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/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.ts +8 -1
- package/dist/react.js +19 -11
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/react.d.ts
CHANGED
|
@@ -1245,8 +1245,15 @@ type Environment = (typeof ENVIRONMENTS)[keyof typeof ENVIRONMENTS];
|
|
|
1245
1245
|
* your identity provider's Clerk JWT template named "convex"
|
|
1246
1246
|
* (e.g. `getToken({ template: "convex" })` from `@clerk/expo`), or
|
|
1247
1247
|
* `null` when no user is signed in.
|
|
1248
|
+
*
|
|
1249
|
+
* Convex invokes this with `{ forceRefreshToken: true }` when the cached
|
|
1250
|
+
* token has expired — forward it to your provider (e.g. Clerk's
|
|
1251
|
+
* `getToken({ template: "convex", skipCache: opts?.forceRefreshToken })`)
|
|
1252
|
+
* so the refresh returns a fresh token rather than a stale cached one.
|
|
1248
1253
|
*/
|
|
1249
|
-
type AuthTokenFetcher = (
|
|
1254
|
+
type AuthTokenFetcher = (opts?: {
|
|
1255
|
+
forceRefreshToken?: boolean;
|
|
1256
|
+
}) => Promise<string | null | undefined>;
|
|
1250
1257
|
/**
|
|
1251
1258
|
* Configuration for initializing a TruthClient.
|
|
1252
1259
|
*/
|
package/dist/react.js
CHANGED
|
@@ -2296,26 +2296,34 @@ function TruthProvider({
|
|
|
2296
2296
|
getAuthTokenRef.current = getAuthToken;
|
|
2297
2297
|
const hasAuthFetcher = Boolean(getAuthToken);
|
|
2298
2298
|
const stableGetAuthToken = (0, import_react2.useMemo)(
|
|
2299
|
-
() => hasAuthFetcher ? () => __async(null, null, function* () {
|
|
2299
|
+
() => hasAuthFetcher ? (opts) => __async(null, null, function* () {
|
|
2300
2300
|
var _a2, _b2;
|
|
2301
|
-
return (_b2 = yield (_a2 = getAuthTokenRef.current) == null ? void 0 : _a2.call(getAuthTokenRef)) != null ? _b2 : null;
|
|
2301
|
+
return (_b2 = yield (_a2 = getAuthTokenRef.current) == null ? void 0 : _a2.call(getAuthTokenRef, opts)) != null ? _b2 : null;
|
|
2302
2302
|
}) : void 0,
|
|
2303
2303
|
[hasAuthFetcher]
|
|
2304
2304
|
);
|
|
2305
2305
|
const [convexAuthed, setConvexAuthed] = (0, import_react2.useState)(false);
|
|
2306
2306
|
(0, import_react2.useEffect)(() => {
|
|
2307
|
-
if (stableGetAuthToken) {
|
|
2308
|
-
convexClient.setAuth(
|
|
2309
|
-
() => __async(null, null, function* () {
|
|
2310
|
-
var _a2;
|
|
2311
|
-
return (_a2 = yield stableGetAuthToken()) != null ? _a2 : null;
|
|
2312
|
-
}),
|
|
2313
|
-
(isAuthenticated) => setConvexAuthed(isAuthenticated)
|
|
2314
|
-
);
|
|
2315
|
-
} else {
|
|
2307
|
+
if (!stableGetAuthToken) {
|
|
2316
2308
|
convexClient.clearAuth();
|
|
2317
2309
|
setConvexAuthed(false);
|
|
2310
|
+
return;
|
|
2318
2311
|
}
|
|
2312
|
+
const fetchToken = (opts) => __async(null, null, function* () {
|
|
2313
|
+
for (let attempt = 0; attempt < 6; attempt++) {
|
|
2314
|
+
try {
|
|
2315
|
+
const token = yield stableGetAuthToken(opts);
|
|
2316
|
+
if (token) return token;
|
|
2317
|
+
} catch (e) {
|
|
2318
|
+
}
|
|
2319
|
+
yield new Promise((resolve) => setTimeout(resolve, 200 + attempt * 150));
|
|
2320
|
+
}
|
|
2321
|
+
return null;
|
|
2322
|
+
});
|
|
2323
|
+
convexClient.setAuth(
|
|
2324
|
+
fetchToken,
|
|
2325
|
+
(isAuthenticated) => setConvexAuthed(isAuthenticated)
|
|
2326
|
+
);
|
|
2319
2327
|
}, [convexClient, stableGetAuthToken]);
|
|
2320
2328
|
const convexQueryClient = (0, import_react2.useMemo)(
|
|
2321
2329
|
() => new import_react_query.ConvexQueryClient(convexClient),
|