azirid-react 0.14.4 → 0.14.6
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 +18 -6
- package/dist/index.cjs +5 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/next-proxy.cjs +8 -2
- package/dist/next-proxy.cjs.map +1 -1
- package/dist/next-proxy.d.cts +2 -0
- package/dist/next-proxy.d.ts +2 -0
- package/dist/next-proxy.js +8 -2
- package/dist/next-proxy.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1342,7 +1342,7 @@ The Azirid dashboard lets admins click "Sign in as user" to impersonate any end
|
|
|
1342
1342
|
1. Admin clicks "Sign in as user" in the Azirid dashboard
|
|
1343
1343
|
2. Dashboard generates a one-time handoff code (valid for 5 minutes) and redirects to your app at `/auth/handoff?code=<code>&api=<apiUrl>`
|
|
1344
1344
|
3. Your app renders `<HandoffCallback>`, which exchanges the code for session tokens directly with the API
|
|
1345
|
-
4. Tokens are stored in `sessionStorage`
|
|
1345
|
+
4. Tokens are stored in `sessionStorage` + `__session` cookie, then the component redirects to `redirectUrl` via hard navigation so `AziridProvider` re-bootstraps with the new session
|
|
1346
1346
|
|
|
1347
1347
|
> **`<HandoffCallback>` is fully standalone** — it does NOT depend on `AziridProvider`. It works even when the provider wraps the entire layout and its bootstrap would redirect to `/login`. No special route groups or layout changes needed.
|
|
1348
1348
|
|
|
@@ -1356,20 +1356,19 @@ import { HandoffCallback } from 'azirid-react'
|
|
|
1356
1356
|
export default function HandoffPage() {
|
|
1357
1357
|
return (
|
|
1358
1358
|
<HandoffCallback
|
|
1359
|
-
|
|
1359
|
+
redirectUrl="/dashboard"
|
|
1360
1360
|
onError={() => window.location.href = '/login'}
|
|
1361
1361
|
/>
|
|
1362
1362
|
)
|
|
1363
1363
|
}
|
|
1364
1364
|
```
|
|
1365
1365
|
|
|
1366
|
-
> **Important:** Use `window.location.href` (not `router.push()`) for redirects. This triggers a full page reload so `AziridProvider` re-bootstraps with the new tokens.
|
|
1367
|
-
|
|
1368
1366
|
**Props:**
|
|
1369
1367
|
|
|
1370
1368
|
| Prop | Type | Default | Description |
|
|
1371
1369
|
|------|------|---------|-------------|
|
|
1372
|
-
| `
|
|
1370
|
+
| `redirectUrl` | `string` | `"/"` | URL to redirect after successful handoff (hard navigation) |
|
|
1371
|
+
| `onSuccess` | `(user: unknown) => void` | — | Called before redirect for optional side effects (analytics, etc.) |
|
|
1373
1372
|
| `onError` | `(error: Error) => void` | — | Called on failure (expired/invalid code); redirect to login |
|
|
1374
1373
|
| `loadingText` | `string` | `"Signing you in..."` | Text shown while the exchange is in progress |
|
|
1375
1374
|
| `errorText` | `string` | `"Failed to complete sign-in. The link may have expired."` | Fallback error text |
|
|
@@ -1432,6 +1431,11 @@ export const proxy = createAziridProxy({
|
|
|
1432
1431
|
// The original URL is preserved as ?redirect= so you can send them back after login.
|
|
1433
1432
|
loginUrl: '/login',
|
|
1434
1433
|
|
|
1434
|
+
// Where to redirect authenticated users when they visit a public route.
|
|
1435
|
+
// E.g. user is logged in and visits /login → redirected to /dashboard.
|
|
1436
|
+
// Your app handles role-based routing from there.
|
|
1437
|
+
dashboardUrl: '/dashboard',
|
|
1438
|
+
|
|
1435
1439
|
// Routes that are ALWAYS public, even if they match a protectedRoute.
|
|
1436
1440
|
// Default: ['/login', '/signup', '/auth/handoff']
|
|
1437
1441
|
publicRoutes: [
|
|
@@ -1452,12 +1456,20 @@ export const config = {
|
|
|
1452
1456
|
|
|
1453
1457
|
#### How it works
|
|
1454
1458
|
|
|
1459
|
+
**Unauthenticated user visits protected route:**
|
|
1455
1460
|
1. User visits `/dashboard/settings` without a valid token
|
|
1456
1461
|
2. Middleware checks: is `/dashboard/settings` protected? Yes (`startsWith('/dashboard')`)
|
|
1457
1462
|
3. Middleware checks: is it public? No
|
|
1458
1463
|
4. Middleware redirects to `/login?redirect=/dashboard/settings`
|
|
1459
1464
|
5. After login, you can read `?redirect=` and send them back
|
|
1460
1465
|
|
|
1466
|
+
**Authenticated user visits public route (with `dashboardUrl`):**
|
|
1467
|
+
1. User is logged in and visits `/login`
|
|
1468
|
+
2. Middleware validates the JWT — valid
|
|
1469
|
+
3. Middleware checks: is `/login` a public route? Yes
|
|
1470
|
+
4. `dashboardUrl` is set → redirects to `/dashboard`
|
|
1471
|
+
5. Your app handles role-based routing from there (e.g. redirect admins to `/admin`)
|
|
1472
|
+
|
|
1461
1473
|
Routes not listed in `protectedRoutes` are accessible to everyone (e.g. `/`, `/pricing`, `/about`).
|
|
1462
1474
|
|
|
1463
1475
|
#### Options
|
|
@@ -1466,9 +1478,9 @@ Routes not listed in `protectedRoutes` are accessible to everyone (e.g. `/`, `/p
|
|
|
1466
1478
|
| ------------------ | ---------- | -------------------------------- | ------------------------------------------------------------- |
|
|
1467
1479
|
| `protectedRoutes` | `string[]` | — | Routes that require auth (matched with `startsWith`) |
|
|
1468
1480
|
| `loginUrl` | `string` | `"/login"` | Redirect target for unauthenticated users |
|
|
1481
|
+
| `dashboardUrl` | `string` | — | Redirect authenticated users away from public routes here |
|
|
1469
1482
|
| `publicRoutes` | `string[]` | `["/login", "/signup", "/auth/handoff"]` | Always-accessible routes, even if inside a protected path |
|
|
1470
1483
|
| `cookieName` | `string` | `"__session"` | Cookie carrying the access token JWT |
|
|
1471
|
-
| `jwksUrl` | `string` | auto | Override JWKS endpoint URL |
|
|
1472
1484
|
|
|
1473
1485
|
---
|
|
1474
1486
|
|
package/dist/index.cjs
CHANGED
|
@@ -3977,6 +3977,7 @@ var subtextStyle = {
|
|
|
3977
3977
|
function HandoffCallback({
|
|
3978
3978
|
onSuccess,
|
|
3979
3979
|
onError,
|
|
3980
|
+
redirectUrl = "/",
|
|
3980
3981
|
loadingText = "Signing you in...",
|
|
3981
3982
|
errorText = "Failed to complete sign-in. The link may have expired."
|
|
3982
3983
|
}) {
|
|
@@ -4003,6 +4004,7 @@ function HandoffCallback({
|
|
|
4003
4004
|
}
|
|
4004
4005
|
performHandoff(apiUrl, code).then((user) => {
|
|
4005
4006
|
onSuccess?.(user);
|
|
4007
|
+
window.location.href = redirectUrl;
|
|
4006
4008
|
}).catch((err) => {
|
|
4007
4009
|
setStatus("error");
|
|
4008
4010
|
const error = err instanceof Error ? err : new Error("Handoff exchange failed");
|
|
@@ -4038,7 +4040,8 @@ async function performHandoff(apiUrl, code) {
|
|
|
4038
4040
|
}
|
|
4039
4041
|
const at = json.at ?? json.accessToken;
|
|
4040
4042
|
if (at) {
|
|
4041
|
-
|
|
4043
|
+
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
4044
|
+
document.cookie = `__session=${at}; Path=/; SameSite=Lax${secure}; Max-Age=900`;
|
|
4042
4045
|
}
|
|
4043
4046
|
return json.user;
|
|
4044
4047
|
}
|
|
@@ -4853,7 +4856,7 @@ function usePasswordToggle() {
|
|
|
4853
4856
|
}
|
|
4854
4857
|
|
|
4855
4858
|
// src/index.ts
|
|
4856
|
-
var SDK_VERSION = "0.14.
|
|
4859
|
+
var SDK_VERSION = "0.14.6";
|
|
4857
4860
|
|
|
4858
4861
|
exports.AUTH_BASE_PATH = AUTH_BASE_PATH;
|
|
4859
4862
|
exports.AuthForm = AuthForm;
|