azirid-react 0.9.9 → 0.10.0
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.cjs +69 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +69 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -165,6 +165,31 @@ function createAccessClient(config, appContext) {
|
|
|
165
165
|
let refreshToken = ssGet(storageKeyRt);
|
|
166
166
|
let csrfToken = ssGet(storageKeyCsrf);
|
|
167
167
|
let refreshPromise = null;
|
|
168
|
+
let channel = null;
|
|
169
|
+
try {
|
|
170
|
+
if (typeof BroadcastChannel !== "undefined") {
|
|
171
|
+
channel = new BroadcastChannel("azirid-auth");
|
|
172
|
+
channel.onmessage = (event) => {
|
|
173
|
+
if (event.data?.type === "token-refreshed") {
|
|
174
|
+
accessToken = event.data.accessToken;
|
|
175
|
+
if (event.data.refreshToken) setRefreshToken(event.data.refreshToken);
|
|
176
|
+
if (event.data.csrfToken) setCsrfToken(event.data.csrfToken);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
} catch {
|
|
181
|
+
}
|
|
182
|
+
function broadcastTokens() {
|
|
183
|
+
try {
|
|
184
|
+
channel?.postMessage({
|
|
185
|
+
type: "token-refreshed",
|
|
186
|
+
accessToken,
|
|
187
|
+
refreshToken,
|
|
188
|
+
csrfToken
|
|
189
|
+
});
|
|
190
|
+
} catch {
|
|
191
|
+
}
|
|
192
|
+
}
|
|
168
193
|
function setAccessToken(token) {
|
|
169
194
|
accessToken = token;
|
|
170
195
|
}
|
|
@@ -226,6 +251,7 @@ function createAccessClient(config, appContext) {
|
|
|
226
251
|
const xc = json.xc ?? json.csrfToken;
|
|
227
252
|
if (rt) setRefreshToken(rt);
|
|
228
253
|
if (xc) setCsrfToken(xc);
|
|
254
|
+
broadcastTokens();
|
|
229
255
|
}
|
|
230
256
|
function refreshTokens(opts) {
|
|
231
257
|
if (opts?.tenantId) {
|
|
@@ -775,6 +801,27 @@ function AziridProviderInner({
|
|
|
775
801
|
}, [client, props.autoBootstrap, updateAccessToken, saveSessionTokens]);
|
|
776
802
|
const silentRefresh = react.useCallback(async () => {
|
|
777
803
|
if (!client.getAccessToken()) return;
|
|
804
|
+
if (typeof navigator !== "undefined" && "locks" in navigator) {
|
|
805
|
+
let acquired = false;
|
|
806
|
+
try {
|
|
807
|
+
await navigator.locks.request(
|
|
808
|
+
"azirid-token-refresh",
|
|
809
|
+
{ ifAvailable: true },
|
|
810
|
+
async (lock) => {
|
|
811
|
+
if (!lock) return;
|
|
812
|
+
acquired = true;
|
|
813
|
+
await client.refreshSession();
|
|
814
|
+
updateAccessToken(client.getAccessToken());
|
|
815
|
+
}
|
|
816
|
+
);
|
|
817
|
+
} catch (err) {
|
|
818
|
+
if (acquired && isAuthError(err)) {
|
|
819
|
+
clearSession();
|
|
820
|
+
props.onSessionExpired?.();
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
778
825
|
try {
|
|
779
826
|
await client.refreshSession();
|
|
780
827
|
updateAccessToken(client.getAccessToken());
|
|
@@ -785,6 +832,27 @@ function AziridProviderInner({
|
|
|
785
832
|
}
|
|
786
833
|
}
|
|
787
834
|
}, [client, updateAccessToken, clearSession, props]);
|
|
835
|
+
react.useEffect(() => {
|
|
836
|
+
let channel = null;
|
|
837
|
+
try {
|
|
838
|
+
if (typeof BroadcastChannel !== "undefined") {
|
|
839
|
+
channel = new BroadcastChannel("azirid-auth");
|
|
840
|
+
channel.onmessage = (event) => {
|
|
841
|
+
if (event.data?.type === "token-refreshed" && event.data.accessToken) {
|
|
842
|
+
client.setAccessToken(event.data.accessToken);
|
|
843
|
+
updateAccessToken(event.data.accessToken);
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
} catch {
|
|
848
|
+
}
|
|
849
|
+
return () => {
|
|
850
|
+
try {
|
|
851
|
+
channel?.close();
|
|
852
|
+
} catch {
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
}, [client, updateAccessToken]);
|
|
788
856
|
react.useEffect(() => {
|
|
789
857
|
const intervalMs = props.refreshInterval ?? 5e4;
|
|
790
858
|
if (intervalMs <= 0) return;
|
|
@@ -4275,7 +4343,7 @@ function usePasswordToggle() {
|
|
|
4275
4343
|
}
|
|
4276
4344
|
|
|
4277
4345
|
// src/index.ts
|
|
4278
|
-
var SDK_VERSION = "0.
|
|
4346
|
+
var SDK_VERSION = "0.10.0";
|
|
4279
4347
|
|
|
4280
4348
|
exports.AuthForm = AuthForm;
|
|
4281
4349
|
exports.AziridProvider = AziridProvider;
|