azirid-react 0.10.3 → 0.10.4
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/README.md +1 -1
- package/dist/index.cjs +12 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +12 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -376,7 +376,7 @@ import { useBootstrap } from 'azirid-react'
|
|
|
376
376
|
const { bootstrap, isBootstrapping } = useBootstrap()
|
|
377
377
|
```
|
|
378
378
|
|
|
379
|
-
> **Note:** The automatic bootstrap
|
|
379
|
+
> **Note:** The automatic bootstrap uses request deduplication — if React 18 Strict Mode (or any other scenario) triggers multiple bootstrap calls, only **one HTTP request** is made and all callers await the same promise. This prevents token rotation conflicts that would otherwise invalidate the session on page reload in development mode. Hooks like `usePayphoneCheckout` and `<PayphoneCallback>` wait for bootstrap to complete before making authenticated requests.
|
|
380
380
|
|
|
381
381
|
### `useRefresh`
|
|
382
382
|
|
package/dist/index.cjs
CHANGED
|
@@ -165,6 +165,7 @@ function createAccessClient(config, appContext) {
|
|
|
165
165
|
let refreshToken = ssGet(storageKeyRt);
|
|
166
166
|
let csrfToken = ssGet(storageKeyCsrf);
|
|
167
167
|
let refreshPromise = null;
|
|
168
|
+
let bootstrapPromise = null;
|
|
168
169
|
let channel = null;
|
|
169
170
|
try {
|
|
170
171
|
if (typeof BroadcastChannel !== "undefined") {
|
|
@@ -264,6 +265,13 @@ function createAccessClient(config, appContext) {
|
|
|
264
265
|
});
|
|
265
266
|
return refreshPromise;
|
|
266
267
|
}
|
|
268
|
+
function deduplicatedBootstrap() {
|
|
269
|
+
if (bootstrapPromise) return bootstrapPromise;
|
|
270
|
+
bootstrapPromise = request("POST", paths.bootstrap).finally(() => {
|
|
271
|
+
bootstrapPromise = null;
|
|
272
|
+
});
|
|
273
|
+
return bootstrapPromise;
|
|
274
|
+
}
|
|
267
275
|
async function request(method, path, body) {
|
|
268
276
|
const headers = {
|
|
269
277
|
"Content-Type": "application/json",
|
|
@@ -365,7 +373,8 @@ function createAccessClient(config, appContext) {
|
|
|
365
373
|
getRefreshToken,
|
|
366
374
|
setCsrfToken,
|
|
367
375
|
getCsrfToken,
|
|
368
|
-
refreshSession: (opts) => refreshTokens(opts)
|
|
376
|
+
refreshSession: (opts) => refreshTokens(opts),
|
|
377
|
+
bootstrapSession: () => deduplicatedBootstrap()
|
|
369
378
|
};
|
|
370
379
|
}
|
|
371
380
|
|
|
@@ -768,20 +777,14 @@ function AziridProviderInner({
|
|
|
768
777
|
},
|
|
769
778
|
[client]
|
|
770
779
|
);
|
|
771
|
-
const bootstrapCalled = react.useRef(false);
|
|
772
780
|
react.useEffect(() => {
|
|
773
781
|
const autoBootstrap = props.autoBootstrap ?? true;
|
|
774
782
|
if (!autoBootstrap) return;
|
|
775
|
-
if (bootstrapCalled.current) {
|
|
776
|
-
setIsBootstrapping(false);
|
|
777
|
-
return;
|
|
778
|
-
}
|
|
779
|
-
bootstrapCalled.current = true;
|
|
780
783
|
let cancelled = false;
|
|
781
784
|
async function bootstrap() {
|
|
782
785
|
setIsBootstrapping(true);
|
|
783
786
|
try {
|
|
784
|
-
const response = await client.
|
|
787
|
+
const response = await client.bootstrapSession();
|
|
785
788
|
if (cancelled) return;
|
|
786
789
|
if (response.branding) {
|
|
787
790
|
setBranding(response.branding);
|
|
@@ -4355,7 +4358,7 @@ function usePasswordToggle() {
|
|
|
4355
4358
|
}
|
|
4356
4359
|
|
|
4357
4360
|
// src/index.ts
|
|
4358
|
-
var SDK_VERSION = "0.10.
|
|
4361
|
+
var SDK_VERSION = "0.10.4";
|
|
4359
4362
|
|
|
4360
4363
|
exports.AuthForm = AuthForm;
|
|
4361
4364
|
exports.AziridProvider = AziridProvider;
|