azirid-react 0.9.9 → 0.10.1
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 +72 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +72 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -235,6 +235,17 @@ interface AziridProviderProps {
|
|
|
235
235
|
onError?: (error: string) => void;
|
|
236
236
|
/** Callback when session expires and refresh fails */
|
|
237
237
|
onSessionExpired?: () => void;
|
|
238
|
+
/**
|
|
239
|
+
* Called after any auth state change (login, signup, logout, token refresh).
|
|
240
|
+
* Use this in Next.js to call `router.refresh()` so server actions see updated cookies.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```tsx
|
|
244
|
+
* const router = useRouter()
|
|
245
|
+
* <AziridProvider onAuthStateChange={() => router.refresh()} />
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
onAuthStateChange?: () => void;
|
|
238
249
|
/** Auto-bootstrap session on mount (default: true) */
|
|
239
250
|
autoBootstrap?: boolean;
|
|
240
251
|
/** Interval in ms for proactive token refresh (default: 50000 = 50 seconds). Set to 0 to disable. */
|
package/dist/index.d.ts
CHANGED
|
@@ -235,6 +235,17 @@ interface AziridProviderProps {
|
|
|
235
235
|
onError?: (error: string) => void;
|
|
236
236
|
/** Callback when session expires and refresh fails */
|
|
237
237
|
onSessionExpired?: () => void;
|
|
238
|
+
/**
|
|
239
|
+
* Called after any auth state change (login, signup, logout, token refresh).
|
|
240
|
+
* Use this in Next.js to call `router.refresh()` so server actions see updated cookies.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```tsx
|
|
244
|
+
* const router = useRouter()
|
|
245
|
+
* <AziridProvider onAuthStateChange={() => router.refresh()} />
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
onAuthStateChange?: () => void;
|
|
238
249
|
/** Auto-bootstrap session on mount (default: true) */
|
|
239
250
|
autoBootstrap?: boolean;
|
|
240
251
|
/** Interval in ms for proactive token refresh (default: 50000 = 50 seconds). Set to 0 to disable. */
|
package/dist/index.js
CHANGED
|
@@ -163,6 +163,31 @@ function createAccessClient(config, appContext) {
|
|
|
163
163
|
let refreshToken = ssGet(storageKeyRt);
|
|
164
164
|
let csrfToken = ssGet(storageKeyCsrf);
|
|
165
165
|
let refreshPromise = null;
|
|
166
|
+
let channel = null;
|
|
167
|
+
try {
|
|
168
|
+
if (typeof BroadcastChannel !== "undefined") {
|
|
169
|
+
channel = new BroadcastChannel("azirid-auth");
|
|
170
|
+
channel.onmessage = (event) => {
|
|
171
|
+
if (event.data?.type === "token-refreshed") {
|
|
172
|
+
accessToken = event.data.accessToken;
|
|
173
|
+
if (event.data.refreshToken) setRefreshToken(event.data.refreshToken);
|
|
174
|
+
if (event.data.csrfToken) setCsrfToken(event.data.csrfToken);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
} catch {
|
|
179
|
+
}
|
|
180
|
+
function broadcastTokens() {
|
|
181
|
+
try {
|
|
182
|
+
channel?.postMessage({
|
|
183
|
+
type: "token-refreshed",
|
|
184
|
+
accessToken,
|
|
185
|
+
refreshToken,
|
|
186
|
+
csrfToken
|
|
187
|
+
});
|
|
188
|
+
} catch {
|
|
189
|
+
}
|
|
190
|
+
}
|
|
166
191
|
function setAccessToken(token) {
|
|
167
192
|
accessToken = token;
|
|
168
193
|
}
|
|
@@ -224,6 +249,7 @@ function createAccessClient(config, appContext) {
|
|
|
224
249
|
const xc = json.xc ?? json.csrfToken;
|
|
225
250
|
if (rt) setRefreshToken(rt);
|
|
226
251
|
if (xc) setCsrfToken(xc);
|
|
252
|
+
broadcastTokens();
|
|
227
253
|
}
|
|
228
254
|
function refreshTokens(opts) {
|
|
229
255
|
if (opts?.tenantId) {
|
|
@@ -576,6 +602,7 @@ function useAuthMutations(deps) {
|
|
|
576
602
|
updateAccessToken(normalizeToken(data));
|
|
577
603
|
saveSessionTokens(data);
|
|
578
604
|
setError(null);
|
|
605
|
+
props.onAuthStateChange?.();
|
|
579
606
|
props.onLoginSuccess?.(data);
|
|
580
607
|
},
|
|
581
608
|
onError: (err) => {
|
|
@@ -593,6 +620,7 @@ function useAuthMutations(deps) {
|
|
|
593
620
|
updateAccessToken(normalizeToken(data));
|
|
594
621
|
saveSessionTokens(data);
|
|
595
622
|
setError(null);
|
|
623
|
+
props.onAuthStateChange?.();
|
|
596
624
|
props.onSignupSuccess?.(data);
|
|
597
625
|
},
|
|
598
626
|
onError: (err) => {
|
|
@@ -606,6 +634,7 @@ function useAuthMutations(deps) {
|
|
|
606
634
|
clearSession();
|
|
607
635
|
setError(null);
|
|
608
636
|
queryClient.clear();
|
|
637
|
+
props.onAuthStateChange?.();
|
|
609
638
|
props.onLogoutSuccess?.();
|
|
610
639
|
}
|
|
611
640
|
});
|
|
@@ -773,6 +802,27 @@ function AziridProviderInner({
|
|
|
773
802
|
}, [client, props.autoBootstrap, updateAccessToken, saveSessionTokens]);
|
|
774
803
|
const silentRefresh = useCallback(async () => {
|
|
775
804
|
if (!client.getAccessToken()) return;
|
|
805
|
+
if (typeof navigator !== "undefined" && "locks" in navigator) {
|
|
806
|
+
let acquired = false;
|
|
807
|
+
try {
|
|
808
|
+
await navigator.locks.request(
|
|
809
|
+
"azirid-token-refresh",
|
|
810
|
+
{ ifAvailable: true },
|
|
811
|
+
async (lock) => {
|
|
812
|
+
if (!lock) return;
|
|
813
|
+
acquired = true;
|
|
814
|
+
await client.refreshSession();
|
|
815
|
+
updateAccessToken(client.getAccessToken());
|
|
816
|
+
}
|
|
817
|
+
);
|
|
818
|
+
} catch (err) {
|
|
819
|
+
if (acquired && isAuthError(err)) {
|
|
820
|
+
clearSession();
|
|
821
|
+
props.onSessionExpired?.();
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
776
826
|
try {
|
|
777
827
|
await client.refreshSession();
|
|
778
828
|
updateAccessToken(client.getAccessToken());
|
|
@@ -783,6 +833,27 @@ function AziridProviderInner({
|
|
|
783
833
|
}
|
|
784
834
|
}
|
|
785
835
|
}, [client, updateAccessToken, clearSession, props]);
|
|
836
|
+
useEffect(() => {
|
|
837
|
+
let channel = null;
|
|
838
|
+
try {
|
|
839
|
+
if (typeof BroadcastChannel !== "undefined") {
|
|
840
|
+
channel = new BroadcastChannel("azirid-auth");
|
|
841
|
+
channel.onmessage = (event) => {
|
|
842
|
+
if (event.data?.type === "token-refreshed" && event.data.accessToken) {
|
|
843
|
+
client.setAccessToken(event.data.accessToken);
|
|
844
|
+
updateAccessToken(event.data.accessToken);
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
} catch {
|
|
849
|
+
}
|
|
850
|
+
return () => {
|
|
851
|
+
try {
|
|
852
|
+
channel?.close();
|
|
853
|
+
} catch {
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
}, [client, updateAccessToken]);
|
|
786
857
|
useEffect(() => {
|
|
787
858
|
const intervalMs = props.refreshInterval ?? 5e4;
|
|
788
859
|
if (intervalMs <= 0) return;
|
|
@@ -4273,7 +4344,7 @@ function usePasswordToggle() {
|
|
|
4273
4344
|
}
|
|
4274
4345
|
|
|
4275
4346
|
// src/index.ts
|
|
4276
|
-
var SDK_VERSION = "0.
|
|
4347
|
+
var SDK_VERSION = "0.10.1";
|
|
4277
4348
|
|
|
4278
4349
|
export { AuthForm, AziridProvider, BASE_PATHS, CheckoutButton, ForgotPasswordForm, InvoiceList, LoginForm, PATHS, PayButton, PayphoneCallback, PayphoneWidgetRenderer, PricingTable, ReferralCard, ReferralStats, ResetPasswordForm, SDK_VERSION, SignupForm, SubscriptionBadge, buildPaths, changePasswordSchema, cn, createAccessClient, createForgotPasswordSchema, createLoginSchema, createMutationHook, createResetPasswordConfirmSchema, createSignupSchema, en, es, forgotPasswordSchema, isAuthError, loginSchema, magicLinkRequestSchema, magicLinkVerifySchema, passkeyRegisterStartSchema, removeStyles, resetPasswordConfirmSchema, resolveMessages, signupSchema, socialLoginSchema, useAccessClient, useAzirid, useBootstrap, useBranding, useChangePassword, useCheckout, useFormState, useInvoices, useLogin, useLogout, useMagicLink, useMessages, usePasskeys, usePasswordReset, usePasswordToggle, usePayButton, usePaymentProviders, usePayphoneCheckout, usePayphoneConfirm, usePlans, useReferral, useReferralStats, useRefresh, useSession, useSignup, useSocialLogin, useSubmitTransferProof, useSubscription, useSwitchTenant, useTenantMembers, useTenants, useTransferPayment, useTransferProofs };
|
|
4279
4350
|
//# sourceMappingURL=index.js.map
|