@drmhse/authos-react 0.2.2 → 0.2.3
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 -0
- package/dist/index.d.mts +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +46 -0
- package/dist/index.mjs +46 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -232,6 +232,31 @@ Individual OAuth provider button. Requires `org` and `service` in provider confi
|
|
|
232
232
|
<OAuthButton provider="google">Continue with Google</OAuthButton>
|
|
233
233
|
```
|
|
234
234
|
|
|
235
|
+
### Callback
|
|
236
|
+
|
|
237
|
+
Required for OAuth flows. Handles the redirect from the identity provider by parsing tokens from the URL fragment and setting the session.
|
|
238
|
+
|
|
239
|
+
```tsx
|
|
240
|
+
import { Callback } from '@drmhse/authos-react';
|
|
241
|
+
|
|
242
|
+
function CallbackPage() {
|
|
243
|
+
const router = useRouter();
|
|
244
|
+
|
|
245
|
+
return (
|
|
246
|
+
<Callback
|
|
247
|
+
onSuccess={() => router.push('/')}
|
|
248
|
+
onError={(error) => console.error(error)}
|
|
249
|
+
/>
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
**Props:**
|
|
255
|
+
| Prop | Type | Default | Description |
|
|
256
|
+
|------|------|---------|-------------|
|
|
257
|
+
| `onSuccess` | `() => void` | - | Callback after session is successfully set |
|
|
258
|
+
| `onError` | `(error: Error) => void` | - | Callback on error |
|
|
259
|
+
|
|
235
260
|
## Hooks
|
|
236
261
|
|
|
237
262
|
### useAuthOS
|
package/dist/index.d.mts
CHANGED
|
@@ -283,6 +283,19 @@ interface SignedOutProps {
|
|
|
283
283
|
/** Content to render when user is signed out */
|
|
284
284
|
children: React.ReactNode;
|
|
285
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Props for the Callback component
|
|
288
|
+
*/
|
|
289
|
+
interface CallbackProps {
|
|
290
|
+
/** Callback when session is successfully set */
|
|
291
|
+
onSuccess?: () => void;
|
|
292
|
+
/** Callback when session setting fails */
|
|
293
|
+
onError?: (error: Error) => void;
|
|
294
|
+
/** Custom render function for the callback state */
|
|
295
|
+
children?: (props: {
|
|
296
|
+
error: string | null;
|
|
297
|
+
}) => React.ReactNode;
|
|
298
|
+
}
|
|
286
299
|
|
|
287
300
|
/**
|
|
288
301
|
* Provider component that wraps your app and provides AuthOS context.
|
|
@@ -723,4 +736,6 @@ interface PasskeySignInProps {
|
|
|
723
736
|
*/
|
|
724
737
|
declare function PasskeySignIn({ onSuccess, onError, className, showPasswordSignIn, }: PasskeySignInProps): react_jsx_runtime.JSX.Element;
|
|
725
738
|
|
|
726
|
-
|
|
739
|
+
declare function Callback({ onSuccess, onError, children }: CallbackProps): react_jsx_runtime.JSX.Element;
|
|
740
|
+
|
|
741
|
+
export { type AuthOSConfig, type AuthOSContextState, AuthOSProvider, type AuthOSProviderProps, Callback, type CallbackProps, MagicLinkSignIn, type MagicLinkSignInProps, OAuthButton, type OAuthButtonProps, OrganizationSwitcher, type OrganizationSwitcherProps, PasskeySignIn, type PasskeySignInProps, Protect, type ProtectProps, SignIn, type SignInProps, SignUp, type SignUpProps, SignedIn, type SignedInProps, SignedOut, type SignedOutProps, type SupportedOAuthProvider, UserButton, type UserButtonProps, useAllPermissions, useAnyPermission, useAuthOS, useAuthOSContext, useOrganization, usePermission, useUser };
|
package/dist/index.d.ts
CHANGED
|
@@ -283,6 +283,19 @@ interface SignedOutProps {
|
|
|
283
283
|
/** Content to render when user is signed out */
|
|
284
284
|
children: React.ReactNode;
|
|
285
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* Props for the Callback component
|
|
288
|
+
*/
|
|
289
|
+
interface CallbackProps {
|
|
290
|
+
/** Callback when session is successfully set */
|
|
291
|
+
onSuccess?: () => void;
|
|
292
|
+
/** Callback when session setting fails */
|
|
293
|
+
onError?: (error: Error) => void;
|
|
294
|
+
/** Custom render function for the callback state */
|
|
295
|
+
children?: (props: {
|
|
296
|
+
error: string | null;
|
|
297
|
+
}) => React.ReactNode;
|
|
298
|
+
}
|
|
286
299
|
|
|
287
300
|
/**
|
|
288
301
|
* Provider component that wraps your app and provides AuthOS context.
|
|
@@ -723,4 +736,6 @@ interface PasskeySignInProps {
|
|
|
723
736
|
*/
|
|
724
737
|
declare function PasskeySignIn({ onSuccess, onError, className, showPasswordSignIn, }: PasskeySignInProps): react_jsx_runtime.JSX.Element;
|
|
725
738
|
|
|
726
|
-
|
|
739
|
+
declare function Callback({ onSuccess, onError, children }: CallbackProps): react_jsx_runtime.JSX.Element;
|
|
740
|
+
|
|
741
|
+
export { type AuthOSConfig, type AuthOSContextState, AuthOSProvider, type AuthOSProviderProps, Callback, type CallbackProps, MagicLinkSignIn, type MagicLinkSignInProps, OAuthButton, type OAuthButtonProps, OrganizationSwitcher, type OrganizationSwitcherProps, PasskeySignIn, type PasskeySignInProps, Protect, type ProtectProps, SignIn, type SignInProps, SignUp, type SignUpProps, SignedIn, type SignedInProps, SignedOut, type SignedOutProps, type SupportedOAuthProvider, UserButton, type UserButtonProps, useAllPermissions, useAnyPermission, useAuthOS, useAuthOSContext, useOrganization, usePermission, useUser };
|
package/dist/index.js
CHANGED
|
@@ -1387,6 +1387,51 @@ function PasskeySignIn({
|
|
|
1387
1387
|
showPasswordSignIn && /* @__PURE__ */ jsxRuntime.jsx("div", { "data-authos-signin-prompt": "", children: /* @__PURE__ */ jsxRuntime.jsx("a", { href: "/signin", "data-authos-link": "signin", children: "Sign in with password" }) })
|
|
1388
1388
|
] }) });
|
|
1389
1389
|
}
|
|
1390
|
+
function Callback({ onSuccess, onError, children }) {
|
|
1391
|
+
const { client } = useAuthOSContext();
|
|
1392
|
+
const [error, setError] = react.useState(null);
|
|
1393
|
+
const processedRef = react.useRef(false);
|
|
1394
|
+
react.useEffect(() => {
|
|
1395
|
+
if (processedRef.current || !client) return;
|
|
1396
|
+
const processCallback = async () => {
|
|
1397
|
+
processedRef.current = true;
|
|
1398
|
+
const hash = window.location.hash.substring(1);
|
|
1399
|
+
const params = new URLSearchParams(hash);
|
|
1400
|
+
const accessToken = params.get("access_token");
|
|
1401
|
+
const refreshToken = params.get("refresh_token");
|
|
1402
|
+
const errorParam = params.get("error");
|
|
1403
|
+
const errorDescription = params.get("error_description");
|
|
1404
|
+
if (errorParam) {
|
|
1405
|
+
const msg = errorDescription || errorParam;
|
|
1406
|
+
setError(msg);
|
|
1407
|
+
onError?.(new Error(msg));
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1410
|
+
if (accessToken) {
|
|
1411
|
+
try {
|
|
1412
|
+
await client.setSession({
|
|
1413
|
+
access_token: accessToken,
|
|
1414
|
+
refresh_token: refreshToken || void 0
|
|
1415
|
+
});
|
|
1416
|
+
onSuccess?.();
|
|
1417
|
+
} catch (err) {
|
|
1418
|
+
const message = err.message || "Failed to set session";
|
|
1419
|
+
setError(message);
|
|
1420
|
+
onError?.(err instanceof Error ? err : new Error(message));
|
|
1421
|
+
}
|
|
1422
|
+
} else {
|
|
1423
|
+
const message = "No authentication tokens found in callback URL.";
|
|
1424
|
+
setError(message);
|
|
1425
|
+
onError?.(new Error(message));
|
|
1426
|
+
}
|
|
1427
|
+
};
|
|
1428
|
+
processCallback();
|
|
1429
|
+
}, [client, onSuccess, onError]);
|
|
1430
|
+
if (children) {
|
|
1431
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: children({ error }) });
|
|
1432
|
+
}
|
|
1433
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-authos-callback": "", children: error ? /* @__PURE__ */ jsxRuntime.jsx("div", { "data-authos-error": "", children: error }) : /* @__PURE__ */ jsxRuntime.jsx("div", { "data-authos-loading": "", children: "Completing sign in..." }) });
|
|
1434
|
+
}
|
|
1390
1435
|
|
|
1391
1436
|
Object.defineProperty(exports, "AuthErrorCodes", {
|
|
1392
1437
|
enumerable: true,
|
|
@@ -1401,6 +1446,7 @@ Object.defineProperty(exports, "SsoClient", {
|
|
|
1401
1446
|
get: function () { return ssoSdk.SsoClient; }
|
|
1402
1447
|
});
|
|
1403
1448
|
exports.AuthOSProvider = AuthOSProvider;
|
|
1449
|
+
exports.Callback = Callback;
|
|
1404
1450
|
exports.MagicLinkSignIn = MagicLinkSignIn;
|
|
1405
1451
|
exports.OAuthButton = OAuthButton;
|
|
1406
1452
|
exports.OrganizationSwitcher = OrganizationSwitcher;
|
package/dist/index.mjs
CHANGED
|
@@ -1386,5 +1386,50 @@ function PasskeySignIn({
|
|
|
1386
1386
|
showPasswordSignIn && /* @__PURE__ */ jsx("div", { "data-authos-signin-prompt": "", children: /* @__PURE__ */ jsx("a", { href: "/signin", "data-authos-link": "signin", children: "Sign in with password" }) })
|
|
1387
1387
|
] }) });
|
|
1388
1388
|
}
|
|
1389
|
+
function Callback({ onSuccess, onError, children }) {
|
|
1390
|
+
const { client } = useAuthOSContext();
|
|
1391
|
+
const [error, setError] = useState(null);
|
|
1392
|
+
const processedRef = useRef(false);
|
|
1393
|
+
useEffect(() => {
|
|
1394
|
+
if (processedRef.current || !client) return;
|
|
1395
|
+
const processCallback = async () => {
|
|
1396
|
+
processedRef.current = true;
|
|
1397
|
+
const hash = window.location.hash.substring(1);
|
|
1398
|
+
const params = new URLSearchParams(hash);
|
|
1399
|
+
const accessToken = params.get("access_token");
|
|
1400
|
+
const refreshToken = params.get("refresh_token");
|
|
1401
|
+
const errorParam = params.get("error");
|
|
1402
|
+
const errorDescription = params.get("error_description");
|
|
1403
|
+
if (errorParam) {
|
|
1404
|
+
const msg = errorDescription || errorParam;
|
|
1405
|
+
setError(msg);
|
|
1406
|
+
onError?.(new Error(msg));
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
if (accessToken) {
|
|
1410
|
+
try {
|
|
1411
|
+
await client.setSession({
|
|
1412
|
+
access_token: accessToken,
|
|
1413
|
+
refresh_token: refreshToken || void 0
|
|
1414
|
+
});
|
|
1415
|
+
onSuccess?.();
|
|
1416
|
+
} catch (err) {
|
|
1417
|
+
const message = err.message || "Failed to set session";
|
|
1418
|
+
setError(message);
|
|
1419
|
+
onError?.(err instanceof Error ? err : new Error(message));
|
|
1420
|
+
}
|
|
1421
|
+
} else {
|
|
1422
|
+
const message = "No authentication tokens found in callback URL.";
|
|
1423
|
+
setError(message);
|
|
1424
|
+
onError?.(new Error(message));
|
|
1425
|
+
}
|
|
1426
|
+
};
|
|
1427
|
+
processCallback();
|
|
1428
|
+
}, [client, onSuccess, onError]);
|
|
1429
|
+
if (children) {
|
|
1430
|
+
return /* @__PURE__ */ jsx(Fragment, { children: children({ error }) });
|
|
1431
|
+
}
|
|
1432
|
+
return /* @__PURE__ */ jsx("div", { "data-authos-callback": "", children: error ? /* @__PURE__ */ jsx("div", { "data-authos-error": "", children: error }) : /* @__PURE__ */ jsx("div", { "data-authos-loading": "", children: "Completing sign in..." }) });
|
|
1433
|
+
}
|
|
1389
1434
|
|
|
1390
|
-
export { AuthOSProvider, MagicLinkSignIn, OAuthButton, OrganizationSwitcher, PasskeySignIn, Protect, SignIn, SignUp, SignedIn, SignedOut, UserButton, useAllPermissions, useAnyPermission, useAuthOS, useAuthOSContext, useOrganization, usePermission, useUser };
|
|
1435
|
+
export { AuthOSProvider, Callback, MagicLinkSignIn, OAuthButton, OrganizationSwitcher, PasskeySignIn, Protect, SignIn, SignUp, SignedIn, SignedOut, UserButton, useAllPermissions, useAnyPermission, useAuthOS, useAuthOSContext, useOrganization, usePermission, useUser };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drmhse/authos-react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "React and Next.js adapter for AuthOS authentication",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
|
-
"dist"
|
|
31
|
+
"dist",
|
|
32
|
+
"README.md"
|
|
32
33
|
],
|
|
33
34
|
"scripts": {
|
|
34
35
|
"build": "tsup",
|