azirid-react 0.11.0 → 0.11.2
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 +25 -8
- package/dist/index.cjs +34 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -3
- package/dist/index.d.ts +33 -3
- package/dist/index.js +33 -6
- package/dist/index.js.map +1 -1
- package/dist/next-handlers.cjs +148 -0
- package/dist/next-handlers.cjs.map +1 -0
- package/dist/next-handlers.js +138 -0
- package/dist/next-handlers.js.map +1 -0
- package/dist/next-proxy.cjs +45 -0
- package/dist/next-proxy.cjs.map +1 -0
- package/dist/next-proxy.d.cts +79 -0
- package/dist/next-proxy.d.ts +79 -0
- package/dist/next-proxy.js +40 -0
- package/dist/next-proxy.js.map +1 -0
- package/dist/next.cjs +1 -3
- package/dist/next.cjs.map +1 -1
- package/dist/next.d.cts +44 -25
- package/dist/next.d.ts +44 -25
- package/dist/next.js +1 -3
- package/dist/next.js.map +1 -1
- package/package.json +21 -1
- package/dist/server.d.cts +0 -102
- package/dist/server.d.ts +0 -102
package/README.md
CHANGED
|
@@ -60,10 +60,10 @@ Requests go directly to the Azirid API. Requires CORS to be configured on the AP
|
|
|
60
60
|
|
|
61
61
|
```ts
|
|
62
62
|
// app/api/auth/[...path]/route.ts
|
|
63
|
-
export { GET, POST, PUT, PATCH, DELETE } from 'azirid-react/next'
|
|
63
|
+
export { GET, POST, PUT, PATCH, DELETE } from 'azirid-react/next/handlers'
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
That's it. The SDK handles proxy logic, cookie fixing, and header forwarding internally. Works with Next.js 14, 15, and 16+ automatically.
|
|
66
|
+
That's it. The SDK handles proxy logic, cookie fixing, and header forwarding internally. Works with Next.js 14, 15, and 16+ automatically — including `output: 'standalone'` builds.
|
|
67
67
|
|
|
68
68
|
### 2. Set the API URL (optional)
|
|
69
69
|
|
|
@@ -266,6 +266,23 @@ function Navbar() {
|
|
|
266
266
|
}
|
|
267
267
|
```
|
|
268
268
|
|
|
269
|
+
> **`isLoading`** is `true` during session bootstrap (page load/refresh), login, and signup. Use it to show a loading state and prevent rendering authenticated UI before the session is ready. This ensures no API calls are made without a valid token.
|
|
270
|
+
|
|
271
|
+
#### Auth Guard pattern (Next.js)
|
|
272
|
+
|
|
273
|
+
```tsx
|
|
274
|
+
import { useAzirid } from 'azirid-react'
|
|
275
|
+
|
|
276
|
+
function AuthGuard({ children }: { children: React.ReactNode }) {
|
|
277
|
+
const { isAuthenticated, isLoading } = useAzirid()
|
|
278
|
+
|
|
279
|
+
if (isLoading) return <LoadingSpinner />
|
|
280
|
+
if (!isAuthenticated) return <RedirectToLogin />
|
|
281
|
+
|
|
282
|
+
return <>{children}</>
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
269
286
|
### `useLogin`
|
|
270
287
|
|
|
271
288
|
```tsx
|
|
@@ -376,7 +393,7 @@ import { useBootstrap } from 'azirid-react'
|
|
|
376
393
|
const { bootstrap, isBootstrapping } = useBootstrap()
|
|
377
394
|
```
|
|
378
395
|
|
|
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.
|
|
396
|
+
> **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. During bootstrap, `isLoading` from `useAzirid()` is `true`, so components using the Auth Guard pattern will show a loading state until the session is restored. Hooks like `usePayphoneCheckout`, `useSession`, and `<PayphoneCallback>` also wait for bootstrap to complete before making authenticated requests.
|
|
380
397
|
|
|
381
398
|
### `useRefresh`
|
|
382
399
|
|
|
@@ -1373,17 +1390,17 @@ Create the file `app/api/auth/[...path]/route.ts` — one line is all you need:
|
|
|
1373
1390
|
|
|
1374
1391
|
```ts
|
|
1375
1392
|
// app/api/auth/[...path]/route.ts
|
|
1376
|
-
export { GET, POST, PUT, PATCH, DELETE } from 'azirid-react/next'
|
|
1393
|
+
export { GET, POST, PUT, PATCH, DELETE } from 'azirid-react/next/handlers'
|
|
1377
1394
|
```
|
|
1378
1395
|
|
|
1379
1396
|
That's it. The SDK handles all the proxy logic, cookie fixing, and header forwarding internally.
|
|
1380
|
-
It works with Next.js 14, 15, and 16+ automatically.
|
|
1397
|
+
It works with Next.js 14, 15, and 16+ automatically — including `output: 'standalone'` builds.
|
|
1381
1398
|
|
|
1382
1399
|
### Custom API URL or debug logging
|
|
1383
1400
|
|
|
1384
1401
|
```ts
|
|
1385
1402
|
// app/api/auth/[...path]/route.ts
|
|
1386
|
-
import { createAziridRouteHandlers } from 'azirid-react/next'
|
|
1403
|
+
import { createAziridRouteHandlers } from 'azirid-react/next/handlers'
|
|
1387
1404
|
|
|
1388
1405
|
export const { GET, POST, PUT, PATCH, DELETE } = createAziridRouteHandlers({
|
|
1389
1406
|
apiUrl: 'https://my-custom-api.com',
|
|
@@ -1439,7 +1456,7 @@ module.exports = withAziridProxy()({
|
|
|
1439
1456
|
|
|
1440
1457
|
```ts
|
|
1441
1458
|
// proxy.ts — only needed if you want route protection
|
|
1442
|
-
import { createAziridProxy } from 'azirid-react/next'
|
|
1459
|
+
import { createAziridProxy } from 'azirid-react/next/proxy'
|
|
1443
1460
|
|
|
1444
1461
|
export const proxy = createAziridProxy({
|
|
1445
1462
|
protectedRoutes: ['/dashboard', '/settings'],
|
|
@@ -1456,7 +1473,7 @@ export const config = {
|
|
|
1456
1473
|
|
|
1457
1474
|
```ts
|
|
1458
1475
|
// middleware.ts — only needed if you want route protection
|
|
1459
|
-
import { createAziridMiddleware } from 'azirid-react/next'
|
|
1476
|
+
import { createAziridMiddleware } from 'azirid-react/next/proxy'
|
|
1460
1477
|
|
|
1461
1478
|
export default createAziridMiddleware({
|
|
1462
1479
|
protectedRoutes: ['/dashboard', '/settings'],
|
package/dist/index.cjs
CHANGED
|
@@ -127,7 +127,9 @@ var SUFFIXES = {
|
|
|
127
127
|
passwordResetConfirm: "password/reset/confirm",
|
|
128
128
|
referralMe: "referrals/me",
|
|
129
129
|
referralStats: "referrals/stats",
|
|
130
|
-
userTenants: "tenants"
|
|
130
|
+
userTenants: "tenants",
|
|
131
|
+
branches: "branches",
|
|
132
|
+
paymentMethods: "payment-methods"
|
|
131
133
|
};
|
|
132
134
|
var BASE_PATHS = {
|
|
133
135
|
/** Proxy mode (Next.js): requests go to the same origin via route handler */
|
|
@@ -911,7 +913,7 @@ function AziridProviderInner({
|
|
|
911
913
|
user,
|
|
912
914
|
accessToken,
|
|
913
915
|
isAuthenticated: user !== null,
|
|
914
|
-
isLoading: loginMutation.isPending || signupMutation.isPending,
|
|
916
|
+
isLoading: isBootstrapping || loginMutation.isPending || signupMutation.isPending,
|
|
915
917
|
error,
|
|
916
918
|
login,
|
|
917
919
|
signup,
|
|
@@ -3012,6 +3014,8 @@ var PP_CONTAINER_ID = "pp-paybtn-azirid";
|
|
|
3012
3014
|
function usePayButton({
|
|
3013
3015
|
intentId,
|
|
3014
3016
|
planId,
|
|
3017
|
+
branchId,
|
|
3018
|
+
merchantAccountId,
|
|
3015
3019
|
onSuccess,
|
|
3016
3020
|
onError
|
|
3017
3021
|
}) {
|
|
@@ -3076,12 +3080,14 @@ function usePayButton({
|
|
|
3076
3080
|
doCheckout({
|
|
3077
3081
|
intentId,
|
|
3078
3082
|
planId,
|
|
3083
|
+
branchId,
|
|
3084
|
+
merchantAccountId,
|
|
3079
3085
|
provider,
|
|
3080
3086
|
successUrl: currentUrl,
|
|
3081
3087
|
cancelUrl: currentUrl
|
|
3082
3088
|
});
|
|
3083
3089
|
},
|
|
3084
|
-
[doCheckout, intentId, planId]
|
|
3090
|
+
[doCheckout, intentId, planId, branchId, merchantAccountId]
|
|
3085
3091
|
);
|
|
3086
3092
|
const { mutate: confirmPayphone } = usePayphoneConfirm({
|
|
3087
3093
|
onSuccess: (data) => {
|
|
@@ -3784,6 +3790,8 @@ function TransferModal2({ data, onClose, onProofSubmitted, labels }) {
|
|
|
3784
3790
|
function PayButton({
|
|
3785
3791
|
planId,
|
|
3786
3792
|
intentId,
|
|
3793
|
+
branchId,
|
|
3794
|
+
merchantAccountId,
|
|
3787
3795
|
successUrl,
|
|
3788
3796
|
cancelUrl,
|
|
3789
3797
|
className,
|
|
@@ -3809,6 +3817,8 @@ function PayButton({
|
|
|
3809
3817
|
} = usePayButton({
|
|
3810
3818
|
intentId,
|
|
3811
3819
|
planId,
|
|
3820
|
+
branchId,
|
|
3821
|
+
merchantAccountId,
|
|
3812
3822
|
onSuccess: (data) => {
|
|
3813
3823
|
if (data.provider === "MANUAL_TRANSFER") {
|
|
3814
3824
|
setShowTransferModal(true);
|
|
@@ -4189,11 +4199,13 @@ function useLogout(options) {
|
|
|
4189
4199
|
}
|
|
4190
4200
|
function useSession(options) {
|
|
4191
4201
|
const client = useAccessClient();
|
|
4202
|
+
const { isBootstrapping } = useAzirid();
|
|
4192
4203
|
const query = reactQuery.useQuery({
|
|
4193
4204
|
queryKey: ["azirid-access", "session"],
|
|
4194
4205
|
queryFn: () => client.get(client.paths.me),
|
|
4195
4206
|
retry: false,
|
|
4196
|
-
|
|
4207
|
+
// Wait for bootstrap to complete before fetching /me
|
|
4208
|
+
enabled: (options?.enabled ?? true) && !isBootstrapping,
|
|
4197
4209
|
refetchInterval: options?.refetchInterval,
|
|
4198
4210
|
refetchOnWindowFocus: options?.refetchOnWindowFocus ?? false
|
|
4199
4211
|
});
|
|
@@ -4627,6 +4639,21 @@ function useTransferPayment({
|
|
|
4627
4639
|
error: currentError
|
|
4628
4640
|
};
|
|
4629
4641
|
}
|
|
4642
|
+
function useBranches() {
|
|
4643
|
+
const client = useAccessClient();
|
|
4644
|
+
return reactQuery.useQuery({
|
|
4645
|
+
queryKey: ["azirid-access", "branches"],
|
|
4646
|
+
queryFn: () => client.get(client.paths.branches)
|
|
4647
|
+
});
|
|
4648
|
+
}
|
|
4649
|
+
function usePaymentMethods(branchId) {
|
|
4650
|
+
const client = useAccessClient();
|
|
4651
|
+
const path = branchId ? `${client.paths.paymentMethods}?branchId=${encodeURIComponent(branchId)}` : client.paths.paymentMethods;
|
|
4652
|
+
return reactQuery.useQuery({
|
|
4653
|
+
queryKey: ["azirid-access", "payment-methods", branchId ?? null],
|
|
4654
|
+
queryFn: () => client.get(path)
|
|
4655
|
+
});
|
|
4656
|
+
}
|
|
4630
4657
|
function useTenants() {
|
|
4631
4658
|
const client = useAccessClient();
|
|
4632
4659
|
return reactQuery.useQuery({
|
|
@@ -4719,7 +4746,7 @@ function usePasswordToggle() {
|
|
|
4719
4746
|
}
|
|
4720
4747
|
|
|
4721
4748
|
// src/index.ts
|
|
4722
|
-
var SDK_VERSION = "0.11.
|
|
4749
|
+
var SDK_VERSION = "0.11.2";
|
|
4723
4750
|
|
|
4724
4751
|
exports.AuthForm = AuthForm;
|
|
4725
4752
|
exports.AziridProvider = AziridProvider;
|
|
@@ -4764,6 +4791,7 @@ exports.socialLoginSchema = socialLoginSchema;
|
|
|
4764
4791
|
exports.useAccessClient = useAccessClient;
|
|
4765
4792
|
exports.useAzirid = useAzirid;
|
|
4766
4793
|
exports.useBootstrap = useBootstrap;
|
|
4794
|
+
exports.useBranches = useBranches;
|
|
4767
4795
|
exports.useBranding = useBranding;
|
|
4768
4796
|
exports.useChangePassword = useChangePassword;
|
|
4769
4797
|
exports.useCheckout = useCheckout;
|
|
@@ -4777,6 +4805,7 @@ exports.usePasskeys = usePasskeys;
|
|
|
4777
4805
|
exports.usePasswordReset = usePasswordReset;
|
|
4778
4806
|
exports.usePasswordToggle = usePasswordToggle;
|
|
4779
4807
|
exports.usePayButton = usePayButton;
|
|
4808
|
+
exports.usePaymentMethods = usePaymentMethods;
|
|
4780
4809
|
exports.usePaymentProviders = usePaymentProviders;
|
|
4781
4810
|
exports.usePayphoneCheckout = usePayphoneCheckout;
|
|
4782
4811
|
exports.usePayphoneConfirm = usePayphoneConfirm;
|