@insforge/react 0.2.9 → 0.2.10
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/components.d.mts +7 -2
- package/dist/components.d.ts +7 -2
- package/dist/components.js +10 -30
- package/dist/components.js.map +1 -1
- package/dist/components.mjs +10 -30
- package/dist/components.mjs.map +1 -1
- package/dist/index.js +10 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/components.d.mts
CHANGED
|
@@ -154,15 +154,20 @@ interface InsforgeCallbackProps {
|
|
|
154
154
|
onRedirect?: (url: string) => void;
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
|
-
* InsforgeCallback - Handles OAuth
|
|
157
|
+
* InsforgeCallback - Handles OAuth authentication callbacks
|
|
158
158
|
*
|
|
159
159
|
* Place this component on your `/auth/callback` page.
|
|
160
160
|
*
|
|
161
|
+
* How it works:
|
|
162
|
+
* 1. SDK automatically detects OAuth callback parameters and saves to localStorage
|
|
163
|
+
* 2. Provider validates the session from localStorage
|
|
164
|
+
* 3. This component waits for validation and handles redirect
|
|
165
|
+
*
|
|
161
166
|
* @example
|
|
162
167
|
* ```tsx
|
|
163
168
|
* // Minimal usage
|
|
164
169
|
* export default function CallbackPage() {
|
|
165
|
-
* return <InsforgeCallback />;
|
|
170
|
+
* return <InsforgeCallback redirectTo="/dashboard" />;
|
|
166
171
|
* }
|
|
167
172
|
* ```
|
|
168
173
|
*
|
package/dist/components.d.ts
CHANGED
|
@@ -154,15 +154,20 @@ interface InsforgeCallbackProps {
|
|
|
154
154
|
onRedirect?: (url: string) => void;
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
|
-
* InsforgeCallback - Handles OAuth
|
|
157
|
+
* InsforgeCallback - Handles OAuth authentication callbacks
|
|
158
158
|
*
|
|
159
159
|
* Place this component on your `/auth/callback` page.
|
|
160
160
|
*
|
|
161
|
+
* How it works:
|
|
162
|
+
* 1. SDK automatically detects OAuth callback parameters and saves to localStorage
|
|
163
|
+
* 2. Provider validates the session from localStorage
|
|
164
|
+
* 3. This component waits for validation and handles redirect
|
|
165
|
+
*
|
|
161
166
|
* @example
|
|
162
167
|
* ```tsx
|
|
163
168
|
* // Minimal usage
|
|
164
169
|
* export default function CallbackPage() {
|
|
165
|
-
* return <InsforgeCallback />;
|
|
170
|
+
* return <InsforgeCallback redirectTo="/dashboard" />;
|
|
166
171
|
* }
|
|
167
172
|
* ```
|
|
168
173
|
*
|
package/dist/components.js
CHANGED
|
@@ -1386,18 +1386,19 @@ function SignedOut({ children }) {
|
|
|
1386
1386
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
1387
1387
|
}
|
|
1388
1388
|
function InsforgeCallback({
|
|
1389
|
-
redirectTo,
|
|
1389
|
+
redirectTo = "/",
|
|
1390
1390
|
onSuccess,
|
|
1391
1391
|
onError,
|
|
1392
1392
|
loadingComponent,
|
|
1393
1393
|
onRedirect
|
|
1394
1394
|
}) {
|
|
1395
1395
|
const isProcessingRef = react.useRef(false);
|
|
1396
|
-
const {
|
|
1396
|
+
const { isLoaded, isSignedIn } = useInsforge();
|
|
1397
1397
|
react.useEffect(() => {
|
|
1398
|
+
if (!isLoaded) return;
|
|
1399
|
+
if (isProcessingRef.current) return;
|
|
1400
|
+
isProcessingRef.current = true;
|
|
1398
1401
|
const processCallback = async () => {
|
|
1399
|
-
if (isProcessingRef.current) return;
|
|
1400
|
-
isProcessingRef.current = true;
|
|
1401
1402
|
const searchParams = new URLSearchParams(window.location.search);
|
|
1402
1403
|
const error = searchParams.get("error");
|
|
1403
1404
|
if (error) {
|
|
@@ -1413,26 +1414,8 @@ function InsforgeCallback({
|
|
|
1413
1414
|
}
|
|
1414
1415
|
return;
|
|
1415
1416
|
}
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
const errorMsg = "no_token";
|
|
1419
|
-
if (onError) {
|
|
1420
|
-
onError(errorMsg);
|
|
1421
|
-
} else {
|
|
1422
|
-
const errorUrl = "/?error=" + encodeURIComponent(errorMsg);
|
|
1423
|
-
if (onRedirect) {
|
|
1424
|
-
onRedirect(errorUrl);
|
|
1425
|
-
} else {
|
|
1426
|
-
window.location.href = errorUrl;
|
|
1427
|
-
}
|
|
1428
|
-
}
|
|
1429
|
-
return;
|
|
1430
|
-
}
|
|
1431
|
-
const result = await handleAuthCallback({
|
|
1432
|
-
accessToken
|
|
1433
|
-
});
|
|
1434
|
-
if (!result.success) {
|
|
1435
|
-
const errorMsg = result.error || "authentication_failed";
|
|
1417
|
+
if (!isSignedIn) {
|
|
1418
|
+
const errorMsg = "authentication_failed";
|
|
1436
1419
|
if (onError) {
|
|
1437
1420
|
onError(errorMsg);
|
|
1438
1421
|
} else {
|
|
@@ -1449,17 +1432,14 @@ function InsforgeCallback({
|
|
|
1449
1432
|
if (onSuccess) {
|
|
1450
1433
|
onSuccess();
|
|
1451
1434
|
}
|
|
1452
|
-
const destination = redirectTo || sessionStorage.getItem("auth_destination") || sessionStorage.getItem("oauth_final_destination") || "/";
|
|
1453
|
-
sessionStorage.removeItem("auth_destination");
|
|
1454
|
-
sessionStorage.removeItem("oauth_final_destination");
|
|
1455
1435
|
if (onRedirect) {
|
|
1456
|
-
onRedirect(
|
|
1436
|
+
onRedirect(redirectTo);
|
|
1457
1437
|
} else {
|
|
1458
|
-
window.location.href =
|
|
1438
|
+
window.location.href = redirectTo;
|
|
1459
1439
|
}
|
|
1460
1440
|
};
|
|
1461
1441
|
processCallback();
|
|
1462
|
-
}, [
|
|
1442
|
+
}, [isLoaded, isSignedIn, redirectTo, onSuccess, onError, onRedirect]);
|
|
1463
1443
|
const defaultLoading = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center min-h-screen", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-center", children: [
|
|
1464
1444
|
/* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-2xl font-semibold mb-4", children: "Completing authentication..." }),
|
|
1465
1445
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto" })
|