@insforge/react 0.2.8 → 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 +12 -10
- package/dist/components.d.ts +12 -10
- package/dist/components.js +14 -34
- package/dist/components.js.map +1 -1
- package/dist/components.mjs +14 -34
- package/dist/components.mjs.map +1 -1
- package/dist/index.js +14 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -34
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.mts +2 -0
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
package/dist/components.d.mts
CHANGED
|
@@ -12,16 +12,14 @@ import '@insforge/shared-schemas';
|
|
|
12
12
|
* @component
|
|
13
13
|
* @example
|
|
14
14
|
* ```tsx
|
|
15
|
-
* <SignIn afterSignInUrl="/dashboard" />
|
|
16
|
-
*
|
|
17
|
-
* // With custom callbacks
|
|
18
15
|
* <SignIn
|
|
16
|
+
* afterSignInUrl="/auth/callback"
|
|
19
17
|
* onSuccess={(user) => console.log('Signed in:', user)}
|
|
20
18
|
* onError={(error) => console.error('Error:', error)}
|
|
21
19
|
* />
|
|
22
20
|
* ```
|
|
23
21
|
*/
|
|
24
|
-
declare function SignIn({ onSuccess, onError, ...uiProps }: SignInProps): react_jsx_runtime.JSX.Element | null;
|
|
22
|
+
declare function SignIn({ afterSignInUrl, onSuccess, onError, ...uiProps }: SignInProps): react_jsx_runtime.JSX.Element | null;
|
|
25
23
|
|
|
26
24
|
/**
|
|
27
25
|
* Pre-built sign-up component with full authentication logic.
|
|
@@ -29,16 +27,15 @@ declare function SignIn({ onSuccess, onError, ...uiProps }: SignInProps): react_
|
|
|
29
27
|
* @component
|
|
30
28
|
* @example
|
|
31
29
|
* ```tsx
|
|
32
|
-
* <SignUp afterSignUpUrl="/onboarding" />
|
|
33
|
-
*
|
|
34
|
-
* // With custom callbacks
|
|
35
30
|
* <SignUp
|
|
31
|
+
* afterSignUpUrl="/auth/callback"
|
|
36
32
|
* onSuccess={(user) => console.log('Signed up:', user)}
|
|
37
33
|
* onError={(error) => console.error('Error:', error)}
|
|
38
34
|
* />
|
|
35
|
+
*
|
|
39
36
|
* ```
|
|
40
37
|
*/
|
|
41
|
-
declare function SignUp({ onSuccess, onError, ...uiProps }: SignUpProps): react_jsx_runtime.JSX.Element | null;
|
|
38
|
+
declare function SignUp({ afterSignUpUrl, onSuccess, onError, ...uiProps }: SignUpProps): react_jsx_runtime.JSX.Element | null;
|
|
42
39
|
|
|
43
40
|
/**
|
|
44
41
|
* User profile button with dropdown menu and sign-out functionality.
|
|
@@ -157,15 +154,20 @@ interface InsforgeCallbackProps {
|
|
|
157
154
|
onRedirect?: (url: string) => void;
|
|
158
155
|
}
|
|
159
156
|
/**
|
|
160
|
-
* InsforgeCallback - Handles OAuth
|
|
157
|
+
* InsforgeCallback - Handles OAuth authentication callbacks
|
|
161
158
|
*
|
|
162
159
|
* Place this component on your `/auth/callback` page.
|
|
163
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
|
+
*
|
|
164
166
|
* @example
|
|
165
167
|
* ```tsx
|
|
166
168
|
* // Minimal usage
|
|
167
169
|
* export default function CallbackPage() {
|
|
168
|
-
* return <InsforgeCallback />;
|
|
170
|
+
* return <InsforgeCallback redirectTo="/dashboard" />;
|
|
169
171
|
* }
|
|
170
172
|
* ```
|
|
171
173
|
*
|
package/dist/components.d.ts
CHANGED
|
@@ -12,16 +12,14 @@ import '@insforge/shared-schemas';
|
|
|
12
12
|
* @component
|
|
13
13
|
* @example
|
|
14
14
|
* ```tsx
|
|
15
|
-
* <SignIn afterSignInUrl="/dashboard" />
|
|
16
|
-
*
|
|
17
|
-
* // With custom callbacks
|
|
18
15
|
* <SignIn
|
|
16
|
+
* afterSignInUrl="/auth/callback"
|
|
19
17
|
* onSuccess={(user) => console.log('Signed in:', user)}
|
|
20
18
|
* onError={(error) => console.error('Error:', error)}
|
|
21
19
|
* />
|
|
22
20
|
* ```
|
|
23
21
|
*/
|
|
24
|
-
declare function SignIn({ onSuccess, onError, ...uiProps }: SignInProps): react_jsx_runtime.JSX.Element | null;
|
|
22
|
+
declare function SignIn({ afterSignInUrl, onSuccess, onError, ...uiProps }: SignInProps): react_jsx_runtime.JSX.Element | null;
|
|
25
23
|
|
|
26
24
|
/**
|
|
27
25
|
* Pre-built sign-up component with full authentication logic.
|
|
@@ -29,16 +27,15 @@ declare function SignIn({ onSuccess, onError, ...uiProps }: SignInProps): react_
|
|
|
29
27
|
* @component
|
|
30
28
|
* @example
|
|
31
29
|
* ```tsx
|
|
32
|
-
* <SignUp afterSignUpUrl="/onboarding" />
|
|
33
|
-
*
|
|
34
|
-
* // With custom callbacks
|
|
35
30
|
* <SignUp
|
|
31
|
+
* afterSignUpUrl="/auth/callback"
|
|
36
32
|
* onSuccess={(user) => console.log('Signed up:', user)}
|
|
37
33
|
* onError={(error) => console.error('Error:', error)}
|
|
38
34
|
* />
|
|
35
|
+
*
|
|
39
36
|
* ```
|
|
40
37
|
*/
|
|
41
|
-
declare function SignUp({ onSuccess, onError, ...uiProps }: SignUpProps): react_jsx_runtime.JSX.Element | null;
|
|
38
|
+
declare function SignUp({ afterSignUpUrl, onSuccess, onError, ...uiProps }: SignUpProps): react_jsx_runtime.JSX.Element | null;
|
|
42
39
|
|
|
43
40
|
/**
|
|
44
41
|
* User profile button with dropdown menu and sign-out functionality.
|
|
@@ -157,15 +154,20 @@ interface InsforgeCallbackProps {
|
|
|
157
154
|
onRedirect?: (url: string) => void;
|
|
158
155
|
}
|
|
159
156
|
/**
|
|
160
|
-
* InsforgeCallback - Handles OAuth
|
|
157
|
+
* InsforgeCallback - Handles OAuth authentication callbacks
|
|
161
158
|
*
|
|
162
159
|
* Place this component on your `/auth/callback` page.
|
|
163
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
|
+
*
|
|
164
166
|
* @example
|
|
165
167
|
* ```tsx
|
|
166
168
|
* // Minimal usage
|
|
167
169
|
* export default function CallbackPage() {
|
|
168
|
-
* return <InsforgeCallback />;
|
|
170
|
+
* return <InsforgeCallback redirectTo="/dashboard" />;
|
|
169
171
|
* }
|
|
170
172
|
* ```
|
|
171
173
|
*
|
package/dist/components.js
CHANGED
|
@@ -911,6 +911,7 @@ function SignInForm({
|
|
|
911
911
|
);
|
|
912
912
|
}
|
|
913
913
|
function SignIn({
|
|
914
|
+
afterSignInUrl,
|
|
914
915
|
onSuccess,
|
|
915
916
|
onError,
|
|
916
917
|
...uiProps
|
|
@@ -950,10 +951,9 @@ function SignIn({
|
|
|
950
951
|
try {
|
|
951
952
|
setOauthLoading(provider);
|
|
952
953
|
setError("");
|
|
953
|
-
const redirectTo = `${window.location.origin}/auth/callback`;
|
|
954
954
|
await insforge.auth.signInWithOAuth({
|
|
955
955
|
provider,
|
|
956
|
-
redirectTo
|
|
956
|
+
redirectTo: afterSignInUrl
|
|
957
957
|
});
|
|
958
958
|
} catch (err) {
|
|
959
959
|
const errorMessage = err.message || `${provider} sign in failed`;
|
|
@@ -1132,6 +1132,7 @@ function SignUpForm({
|
|
|
1132
1132
|
);
|
|
1133
1133
|
}
|
|
1134
1134
|
function SignUp({
|
|
1135
|
+
afterSignUpUrl,
|
|
1135
1136
|
onSuccess,
|
|
1136
1137
|
onError,
|
|
1137
1138
|
...uiProps
|
|
@@ -1176,10 +1177,9 @@ function SignUp({
|
|
|
1176
1177
|
try {
|
|
1177
1178
|
setOauthLoading(provider);
|
|
1178
1179
|
setError("");
|
|
1179
|
-
const redirectTo = `${window.location.origin}/auth/callback`;
|
|
1180
1180
|
await insforge.auth.signInWithOAuth({
|
|
1181
1181
|
provider,
|
|
1182
|
-
redirectTo
|
|
1182
|
+
redirectTo: afterSignUpUrl
|
|
1183
1183
|
});
|
|
1184
1184
|
} catch (err) {
|
|
1185
1185
|
const errorMessage = err.message || `${provider} sign up failed`;
|
|
@@ -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" })
|