@monocloud/auth-react 0.1.1-canary-20260605042109

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.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +189 -0
  3. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  4. package/dist/components/process-callback.cjs +62 -0
  5. package/dist/components/process-callback.cjs.map +1 -0
  6. package/dist/components/process-callback.d.mts +46 -0
  7. package/dist/components/process-callback.mjs +60 -0
  8. package/dist/components/process-callback.mjs.map +1 -0
  9. package/dist/components/protected.cjs +85 -0
  10. package/dist/components/protected.cjs.map +1 -0
  11. package/dist/components/protected.d.mts +113 -0
  12. package/dist/components/protected.mjs +83 -0
  13. package/dist/components/protected.mjs.map +1 -0
  14. package/dist/components/signin.cjs +69 -0
  15. package/dist/components/signin.cjs.map +1 -0
  16. package/dist/components/signin.d.mts +70 -0
  17. package/dist/components/signin.mjs +67 -0
  18. package/dist/components/signin.mjs.map +1 -0
  19. package/dist/components/signout.cjs +61 -0
  20. package/dist/components/signout.cjs.map +1 -0
  21. package/dist/components/signout.d.mts +62 -0
  22. package/dist/components/signout.mjs +59 -0
  23. package/dist/components/signout.mjs.map +1 -0
  24. package/dist/components/signup.cjs +68 -0
  25. package/dist/components/signup.cjs.map +1 -0
  26. package/dist/components/signup.d.mts +68 -0
  27. package/dist/components/signup.mjs +66 -0
  28. package/dist/components/signup.mjs.map +1 -0
  29. package/dist/context.cjs +12 -0
  30. package/dist/context.cjs.map +1 -0
  31. package/dist/context.mjs +10 -0
  32. package/dist/context.mjs.map +1 -0
  33. package/dist/index.cjs +79 -0
  34. package/dist/index.d.mts +11 -0
  35. package/dist/index.mjs +11 -0
  36. package/dist/monocloud-auth-provider.cjs +181 -0
  37. package/dist/monocloud-auth-provider.cjs.map +1 -0
  38. package/dist/monocloud-auth-provider.d.mts +64 -0
  39. package/dist/monocloud-auth-provider.mjs +179 -0
  40. package/dist/monocloud-auth-provider.mjs.map +1 -0
  41. package/dist/types.d.mts +107 -0
  42. package/dist/use-auth.cjs +63 -0
  43. package/dist/use-auth.cjs.map +1 -0
  44. package/dist/use-auth.d.mts +56 -0
  45. package/dist/use-auth.mjs +63 -0
  46. package/dist/use-auth.mjs.map +1 -0
  47. package/dist/use-monocloud-client.cjs +47 -0
  48. package/dist/use-monocloud-client.cjs.map +1 -0
  49. package/dist/use-monocloud-client.d.mts +40 -0
  50. package/dist/use-monocloud-client.mjs +47 -0
  51. package/dist/use-monocloud-client.mjs.map +1 -0
  52. package/dist/use-process-callback.cjs +14 -0
  53. package/dist/use-process-callback.cjs.map +1 -0
  54. package/dist/use-process-callback.mjs +14 -0
  55. package/dist/use-process-callback.mjs.map +1 -0
  56. package/package.json +67 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"monocloud-auth-provider.mjs","names":[],"sources":["../src/monocloud-auth-provider.tsx"],"sourcesContent":["'use client';\n\nimport {\n MonoCloudWebJSClient,\n type GetTokensOptions,\n type MonoCloudSession,\n type MonoCloudTokens,\n type RefreshOptions,\n type SignInOptions,\n type SignInSilentOptions,\n type SignOutOptions,\n} from '@monocloud/auth-web-js';\nimport React, {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport {\n MonoCloudAuthContext,\n MonoCloudClientContext,\n MonoCloudProcessCallbackContext,\n} from './context';\nimport type {\n AuthState,\n MonoCloudAuth,\n MonoCloudAuthProviderProps,\n} from './types';\n\nconst initialState: AuthState = {\n isLoading: true,\n isAuthenticated: false,\n};\n\n/**\n * `<MonoCloudAuthProvider>` initializes the MonoCloud JavaScript client and makes\n * the authentication state and actions available through {@link useAuth}.\n *\n * @example Basic setup\n *\n * ```tsx:src/main.tsx tab=\"Basic setup\" tab-group=\"MonoCloudAuthProvider\"\n * \"use client\";\n *\n * import { MonoCloudAuthProvider } from \"@monocloud/auth-react\";\n *\n * export default function Root() {\n * return (\n * <MonoCloudAuthProvider\n * tenantDomain=\"https://your-tenant-domain\"\n * clientId=\"your-client-id\"\n * >\n * <App />\n * </MonoCloudAuthProvider>\n * );\n * }\n * ```\n *\n * @example Client-side router navigation\n *\n * ```tsx:src/main.tsx tab=\"Client-side router navigation\" tab-group=\"MonoCloudAuthProvider\"\n * \"use client\";\n *\n * import { MonoCloudAuthProvider } from \"@monocloud/auth-react\";\n * import { useNavigate } from \"react-router-dom\";\n *\n * export default function Root() {\n * const navigate = useNavigate();\n *\n * return (\n * <MonoCloudAuthProvider\n * tenantDomain=\"https://your-tenant-domain\"\n * clientId=\"your-client-id\"\n * autoProcessCallback={false}\n * postCallback={state => navigate(state.returnUrl ?? \"/\")}\n * >\n * <App />\n * </MonoCloudAuthProvider>\n * );\n * }\n * ```\n *\n * @param props - Props for configuring the provider and the underlying client.\n * @returns The provider element wrapping `children`.\n *\n * @category Components\n */\nexport const MonoCloudAuthProvider = ({\n children,\n autoProcessCallback = true,\n ...clientOptions\n}: MonoCloudAuthProviderProps): React.JSX.Element => {\n const [state, setState] = useState<AuthState>(initialState);\n\n const [client] = useState<MonoCloudWebJSClient>(\n () => new MonoCloudWebJSClient(clientOptions)\n );\n\n const syncSession = useCallback(async (): Promise<void> => {\n const session = await client.getSession();\n setState({\n isLoading: false,\n isAuthenticated: !!session,\n user: session?.user,\n session,\n error: undefined,\n });\n }, [client]);\n\n const processCallback = useCallback(async (): Promise<void> => {\n setState(prev => ({ ...prev, isLoading: true }));\n\n try {\n await client.processCallback();\n await syncSession();\n } catch (e) {\n setState({\n isLoading: false,\n isAuthenticated: false,\n user: undefined,\n session: undefined,\n error: e as Error,\n });\n throw e;\n }\n }, [client, syncSession]);\n\n const initialized = useRef(false);\n useEffect(() => {\n /* v8 ignore start -- StrictMode double-invocation guard */\n if (initialized.current) {\n return;\n }\n /* v8 ignore stop */\n initialized.current = true;\n\n if (autoProcessCallback) {\n processCallback().catch(() => {});\n } else {\n syncSession();\n }\n }, [autoProcessCallback, processCallback, syncSession]);\n\n const signIn = useCallback(\n async (signInOptions?: SignInOptions): Promise<void> => {\n setState(prev => ({ ...prev, isLoading: true }));\n try {\n await client.signIn(signInOptions);\n await syncSession();\n } catch (e) {\n setState(prev => ({ ...prev, isLoading: false, error: e as Error }));\n }\n },\n [client, syncSession]\n );\n\n const signOut = useCallback(\n async (signOutOptions?: SignOutOptions): Promise<void> => {\n setState(prev => ({ ...prev, isLoading: true }));\n try {\n await client.signOut(signOutOptions);\n await syncSession();\n } catch (e) {\n setState(prev => ({ ...prev, isLoading: false, error: e as Error }));\n }\n },\n [client, syncSession]\n );\n\n const signInSilent = useCallback(\n async (\n signInSilentOptions?: SignInSilentOptions\n ): Promise<MonoCloudSession> => {\n const session = await client.signInSilent(signInSilentOptions);\n await syncSession();\n return session;\n },\n [client, syncSession]\n );\n\n const refreshSession = useCallback(\n async (refreshOptions?: RefreshOptions): Promise<void> => {\n await client.refreshSession(refreshOptions);\n await syncSession();\n },\n [client, syncSession]\n );\n\n const refetchUserInfo = useCallback(async (): Promise<void> => {\n await client.refetchUserInfo();\n await syncSession();\n }, [client, syncSession]);\n\n const getTokens = useCallback(\n async (options?: GetTokensOptions): Promise<MonoCloudTokens> => {\n const tokens = await client.getTokens(options);\n await syncSession();\n return tokens;\n },\n [client, syncSession]\n );\n\n const value = useMemo<MonoCloudAuth>(\n () => ({\n ...state,\n signIn,\n signOut,\n signInSilent,\n refreshSession,\n refetchUserInfo,\n getTokens,\n }),\n [\n state,\n signIn,\n signOut,\n signInSilent,\n refreshSession,\n refetchUserInfo,\n getTokens,\n ]\n );\n\n return (\n <MonoCloudClientContext.Provider value={client}>\n <MonoCloudProcessCallbackContext.Provider value={processCallback}>\n <MonoCloudAuthContext.Provider value={value}>\n {children}\n </MonoCloudAuthContext.Provider>\n </MonoCloudProcessCallbackContext.Provider>\n </MonoCloudClientContext.Provider>\n );\n};\n"],"mappings":"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"}
@@ -0,0 +1,107 @@
1
+ import { GetTokensOptions, MonoCloudSession, MonoCloudTokens, MonoCloudUser, MonoCloudWebJSClientOptions, RefreshOptions, SignInOptions, SignInSilentOptions, SignOutOptions } from "@monocloud/auth-web-js";
2
+ import { ReactNode } from "react";
3
+
4
+ //#region src/types.d.ts
5
+ /**
6
+ * The current authentication state.
7
+ *
8
+ * @category Types
9
+ */
10
+ interface AuthState {
11
+ /**
12
+ * Flag indicating if the authentication state is still loading.
13
+ */
14
+ isLoading: boolean;
15
+ /**
16
+ * Flag indicating if the user is authenticated.
17
+ */
18
+ isAuthenticated: boolean;
19
+ /**
20
+ * Error encountered during authentication, if any.
21
+ */
22
+ error?: Error;
23
+ /**
24
+ * The authenticated user's information, if available.
25
+ */
26
+ user?: MonoCloudUser;
27
+ /**
28
+ * The current session, including tokens and the user, if available.
29
+ */
30
+ session?: MonoCloudSession;
31
+ }
32
+ /**
33
+ * The current authentication state and the authentication actions.
34
+ *
35
+ * @category Types
36
+ */
37
+ interface MonoCloudAuth extends AuthState {
38
+ /**
39
+ * Initiates the sign-in flow.
40
+ */
41
+ signIn: (signInOptions?: SignInOptions) => Promise<void>;
42
+ /**
43
+ * Initiates the sign-out flow.
44
+ */
45
+ signOut: (signOutOptions?: SignOutOptions) => Promise<void>;
46
+ /**
47
+ * Attempts to silently restore the session via a hidden iframe (`prompt=none`).
48
+ */
49
+ signInSilent: (signInSilentOptions?: SignInSilentOptions) => Promise<MonoCloudSession>;
50
+ /**
51
+ * Refreshes the current session using the Refresh Token Grant.
52
+ */
53
+ refreshSession: (refreshOptions?: RefreshOptions) => Promise<void>;
54
+ /**
55
+ * Refetches the user's profile from the UserInfo endpoint and updates the session.
56
+ */
57
+ refetchUserInfo: () => Promise<void>;
58
+ /**
59
+ * Retrieves the active tokens, refreshing them if they have expired.
60
+ */
61
+ getTokens: (options?: GetTokensOptions) => Promise<MonoCloudTokens>;
62
+ }
63
+ /**
64
+ * Props for `<MonoCloudAuthProvider />`.
65
+ *
66
+ * @category Types
67
+ */
68
+ interface MonoCloudAuthProviderProps extends MonoCloudWebJSClientOptions {
69
+ /**
70
+ * The application tree that should have access to the authentication context.
71
+ */
72
+ children: ReactNode;
73
+ /**
74
+ * When `true` (the default), the provider processes the OIDC callback
75
+ * automatically when it mounts. Set it to `false` when you handle the callback
76
+ * yourself with `<ProcessCallback />` on a dedicated route.
77
+ *
78
+ * @defaultValue true
79
+ */
80
+ autoProcessCallback?: boolean;
81
+ }
82
+ /**
83
+ * Props for the `<ProcessCallback />` component.
84
+ *
85
+ * @category Types
86
+ */
87
+ interface ProcessCallbackProps {
88
+ /**
89
+ * Content rendered while the callback is being processed.
90
+ *
91
+ * @defaultValue null
92
+ */
93
+ loading?: ReactNode;
94
+ /**
95
+ * Content rendered when callback processing fails.
96
+ */
97
+ error?: ReactNode | ((error: Error) => ReactNode);
98
+ /**
99
+ * Content rendered after the callback has been processed successfully.
100
+ *
101
+ * @defaultValue null
102
+ */
103
+ children?: ReactNode;
104
+ }
105
+ //#endregion
106
+ export { AuthState, MonoCloudAuth, MonoCloudAuthProviderProps, ProcessCallbackProps };
107
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1,63 @@
1
+ "use client";
2
+ const require_context = require("./context.cjs");
3
+ let _monocloud_auth_web_js = require("@monocloud/auth-web-js");
4
+ let react = require("react");
5
+ //#region src/use-auth.tsx
6
+ /**
7
+ * `useAuth()` is a client-side hook that exposes the current authentication
8
+ * state and actions provided by {@link MonoCloudAuthProvider}.
9
+ *
10
+ * @example Reading the authentication state
11
+ *
12
+ * ```tsx:src/Profile.tsx tab="Reading the authentication state" tab-group="useAuth"
13
+ * "use client";
14
+ *
15
+ * import { useAuth } from "@monocloud/auth-react";
16
+ *
17
+ * export default function Home() {
18
+ * const { isLoading, isAuthenticated, user } = useAuth();
19
+ *
20
+ * if (isLoading) {
21
+ * return <>Loading...</>;
22
+ * }
23
+ *
24
+ * if (!isAuthenticated) {
25
+ * return <>Not signed in</>;
26
+ * }
27
+ *
28
+ * return <>User Id: {user?.sub}</>;
29
+ * }
30
+ * ```
31
+ *
32
+ * @example Triggering actions
33
+ *
34
+ * ```tsx:src/Profile.tsx tab="Triggering actions" tab-group="useAuth"
35
+ * "use client";
36
+ *
37
+ * import { useAuth } from "@monocloud/auth-react";
38
+ *
39
+ * export default function Account() {
40
+ * const { signOut, refetchUserInfo } = useAuth();
41
+ *
42
+ * return (
43
+ * <>
44
+ * <button onClick={() => refetchUserInfo()}>Refresh profile</button>
45
+ * <button onClick={() => signOut()}>Sign out</button>
46
+ * </>
47
+ * );
48
+ * }
49
+ * ```
50
+ *
51
+ * @returns The current {@link MonoCloudAuth}.
52
+ *
53
+ * @category Hooks
54
+ */
55
+ const useAuth = () => {
56
+ const context = (0, react.useContext)(require_context.MonoCloudAuthContext);
57
+ if (!context) throw new _monocloud_auth_web_js.MonoCloudJsError("useAuth() can only be used inside a <MonoCloudAuthProvider>...</MonoCloudAuthProvider>.");
58
+ return context;
59
+ };
60
+ //#endregion
61
+ exports.useAuth = useAuth;
62
+
63
+ //# sourceMappingURL=use-auth.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-auth.cjs","names":["MonoCloudAuthContext","MonoCloudJsError"],"sources":["../src/use-auth.tsx"],"sourcesContent":["'use client';\n\nimport { MonoCloudJsError } from '@monocloud/auth-web-js';\nimport { useContext } from 'react';\nimport { MonoCloudAuthContext } from './context';\nimport type { MonoCloudAuth } from './types';\nimport type { MonoCloudAuthProvider } from './monocloud-auth-provider';\n\n/**\n * `useAuth()` is a client-side hook that exposes the current authentication\n * state and actions provided by {@link MonoCloudAuthProvider}.\n *\n * @example Reading the authentication state\n *\n * ```tsx:src/Profile.tsx tab=\"Reading the authentication state\" tab-group=\"useAuth\"\n * \"use client\";\n *\n * import { useAuth } from \"@monocloud/auth-react\";\n *\n * export default function Home() {\n * const { isLoading, isAuthenticated, user } = useAuth();\n *\n * if (isLoading) {\n * return <>Loading...</>;\n * }\n *\n * if (!isAuthenticated) {\n * return <>Not signed in</>;\n * }\n *\n * return <>User Id: {user?.sub}</>;\n * }\n * ```\n *\n * @example Triggering actions\n *\n * ```tsx:src/Profile.tsx tab=\"Triggering actions\" tab-group=\"useAuth\"\n * \"use client\";\n *\n * import { useAuth } from \"@monocloud/auth-react\";\n *\n * export default function Account() {\n * const { signOut, refetchUserInfo } = useAuth();\n *\n * return (\n * <>\n * <button onClick={() => refetchUserInfo()}>Refresh profile</button>\n * <button onClick={() => signOut()}>Sign out</button>\n * </>\n * );\n * }\n * ```\n *\n * @returns The current {@link MonoCloudAuth}.\n *\n * @category Hooks\n */\nexport const useAuth = (): MonoCloudAuth => {\n const context = useContext(MonoCloudAuthContext);\n\n if (!context) {\n throw new MonoCloudJsError(\n 'useAuth() can only be used inside a <MonoCloudAuthProvider>...</MonoCloudAuthProvider>.'\n );\n }\n\n return context;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,MAAa,gBAA+B;CAC1C,MAAM,WAAA,GAAA,MAAA,YAAqBA,gBAAAA,oBAAoB;CAE/C,IAAI,CAAC,SACH,MAAM,IAAIC,uBAAAA,iBACR,yFACF;CAGF,OAAO;AACT"}
@@ -0,0 +1,56 @@
1
+ import { MonoCloudAuth } from "./types.mjs";
2
+
3
+ //#region src/use-auth.d.ts
4
+ /**
5
+ * `useAuth()` is a client-side hook that exposes the current authentication
6
+ * state and actions provided by {@link MonoCloudAuthProvider}.
7
+ *
8
+ * @example Reading the authentication state
9
+ *
10
+ * ```tsx:src/Profile.tsx tab="Reading the authentication state" tab-group="useAuth"
11
+ * "use client";
12
+ *
13
+ * import { useAuth } from "@monocloud/auth-react";
14
+ *
15
+ * export default function Home() {
16
+ * const { isLoading, isAuthenticated, user } = useAuth();
17
+ *
18
+ * if (isLoading) {
19
+ * return <>Loading...</>;
20
+ * }
21
+ *
22
+ * if (!isAuthenticated) {
23
+ * return <>Not signed in</>;
24
+ * }
25
+ *
26
+ * return <>User Id: {user?.sub}</>;
27
+ * }
28
+ * ```
29
+ *
30
+ * @example Triggering actions
31
+ *
32
+ * ```tsx:src/Profile.tsx tab="Triggering actions" tab-group="useAuth"
33
+ * "use client";
34
+ *
35
+ * import { useAuth } from "@monocloud/auth-react";
36
+ *
37
+ * export default function Account() {
38
+ * const { signOut, refetchUserInfo } = useAuth();
39
+ *
40
+ * return (
41
+ * <>
42
+ * <button onClick={() => refetchUserInfo()}>Refresh profile</button>
43
+ * <button onClick={() => signOut()}>Sign out</button>
44
+ * </>
45
+ * );
46
+ * }
47
+ * ```
48
+ *
49
+ * @returns The current {@link MonoCloudAuth}.
50
+ *
51
+ * @category Hooks
52
+ */
53
+ declare const useAuth: () => MonoCloudAuth;
54
+ //#endregion
55
+ export { useAuth };
56
+ //# sourceMappingURL=use-auth.d.mts.map
@@ -0,0 +1,63 @@
1
+ "use client";
2
+ import { MonoCloudAuthContext } from "./context.mjs";
3
+ import { MonoCloudJsError } from "@monocloud/auth-web-js";
4
+ import { useContext } from "react";
5
+ //#region src/use-auth.tsx
6
+ /**
7
+ * `useAuth()` is a client-side hook that exposes the current authentication
8
+ * state and actions provided by {@link MonoCloudAuthProvider}.
9
+ *
10
+ * @example Reading the authentication state
11
+ *
12
+ * ```tsx:src/Profile.tsx tab="Reading the authentication state" tab-group="useAuth"
13
+ * "use client";
14
+ *
15
+ * import { useAuth } from "@monocloud/auth-react";
16
+ *
17
+ * export default function Home() {
18
+ * const { isLoading, isAuthenticated, user } = useAuth();
19
+ *
20
+ * if (isLoading) {
21
+ * return <>Loading...</>;
22
+ * }
23
+ *
24
+ * if (!isAuthenticated) {
25
+ * return <>Not signed in</>;
26
+ * }
27
+ *
28
+ * return <>User Id: {user?.sub}</>;
29
+ * }
30
+ * ```
31
+ *
32
+ * @example Triggering actions
33
+ *
34
+ * ```tsx:src/Profile.tsx tab="Triggering actions" tab-group="useAuth"
35
+ * "use client";
36
+ *
37
+ * import { useAuth } from "@monocloud/auth-react";
38
+ *
39
+ * export default function Account() {
40
+ * const { signOut, refetchUserInfo } = useAuth();
41
+ *
42
+ * return (
43
+ * <>
44
+ * <button onClick={() => refetchUserInfo()}>Refresh profile</button>
45
+ * <button onClick={() => signOut()}>Sign out</button>
46
+ * </>
47
+ * );
48
+ * }
49
+ * ```
50
+ *
51
+ * @returns The current {@link MonoCloudAuth}.
52
+ *
53
+ * @category Hooks
54
+ */
55
+ const useAuth = () => {
56
+ const context = useContext(MonoCloudAuthContext);
57
+ if (!context) throw new MonoCloudJsError("useAuth() can only be used inside a <MonoCloudAuthProvider>...</MonoCloudAuthProvider>.");
58
+ return context;
59
+ };
60
+ //#endregion
61
+ export { useAuth };
62
+
63
+ //# sourceMappingURL=use-auth.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-auth.mjs","names":[],"sources":["../src/use-auth.tsx"],"sourcesContent":["'use client';\n\nimport { MonoCloudJsError } from '@monocloud/auth-web-js';\nimport { useContext } from 'react';\nimport { MonoCloudAuthContext } from './context';\nimport type { MonoCloudAuth } from './types';\nimport type { MonoCloudAuthProvider } from './monocloud-auth-provider';\n\n/**\n * `useAuth()` is a client-side hook that exposes the current authentication\n * state and actions provided by {@link MonoCloudAuthProvider}.\n *\n * @example Reading the authentication state\n *\n * ```tsx:src/Profile.tsx tab=\"Reading the authentication state\" tab-group=\"useAuth\"\n * \"use client\";\n *\n * import { useAuth } from \"@monocloud/auth-react\";\n *\n * export default function Home() {\n * const { isLoading, isAuthenticated, user } = useAuth();\n *\n * if (isLoading) {\n * return <>Loading...</>;\n * }\n *\n * if (!isAuthenticated) {\n * return <>Not signed in</>;\n * }\n *\n * return <>User Id: {user?.sub}</>;\n * }\n * ```\n *\n * @example Triggering actions\n *\n * ```tsx:src/Profile.tsx tab=\"Triggering actions\" tab-group=\"useAuth\"\n * \"use client\";\n *\n * import { useAuth } from \"@monocloud/auth-react\";\n *\n * export default function Account() {\n * const { signOut, refetchUserInfo } = useAuth();\n *\n * return (\n * <>\n * <button onClick={() => refetchUserInfo()}>Refresh profile</button>\n * <button onClick={() => signOut()}>Sign out</button>\n * </>\n * );\n * }\n * ```\n *\n * @returns The current {@link MonoCloudAuth}.\n *\n * @category Hooks\n */\nexport const useAuth = (): MonoCloudAuth => {\n const context = useContext(MonoCloudAuthContext);\n\n if (!context) {\n throw new MonoCloudJsError(\n 'useAuth() can only be used inside a <MonoCloudAuthProvider>...</MonoCloudAuthProvider>.'\n );\n }\n\n return context;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,MAAa,gBAA+B;CAC1C,MAAM,UAAU,WAAW,oBAAoB;CAE/C,IAAI,CAAC,SACH,MAAM,IAAI,iBACR,yFACF;CAGF,OAAO;AACT"}
@@ -0,0 +1,47 @@
1
+ "use client";
2
+ const require_context = require("./context.cjs");
3
+ let _monocloud_auth_web_js = require("@monocloud/auth-web-js");
4
+ let react = require("react");
5
+ //#region src/use-monocloud-client.tsx
6
+ /**
7
+ * `useMonoCloudClient()` returns the underlying {@link MonoCloudWebJSClient} created by
8
+ * {@link MonoCloudAuthProvider}.
9
+ *
10
+ * @remarks
11
+ * This is intended for advanced, lower-level operations that
12
+ * {@link useAuth} does not cover - for example token revocation via
13
+ * `client.oidcClient`. Most applications only need {@link useAuth}.
14
+ *
15
+ * @example Revoking the access token
16
+ *
17
+ * ```tsx title="Revoking the access token"
18
+ * "use client";
19
+ *
20
+ * import { useAuth, useMonoCloudClient } from "@monocloud/auth-react";
21
+ *
22
+ * export default function RevokeButton() {
23
+ * const { getTokens } = useAuth();
24
+ * const client = useMonoCloudClient();
25
+ *
26
+ * const revoke = async () => {
27
+ * const tokens = await getTokens();
28
+ * await client.oidcClient.revokeToken(tokens.accessToken);
29
+ * };
30
+ *
31
+ * return <button onClick={() => void revoke()}>Revoke</button>;
32
+ * }
33
+ * ```
34
+ *
35
+ * @returns The underlying {@link MonoCloudWebJSClient} instance.
36
+ *
37
+ * @category Hooks
38
+ */
39
+ const useMonoCloudClient = () => {
40
+ const client = (0, react.useContext)(require_context.MonoCloudClientContext);
41
+ if (!client) throw new _monocloud_auth_web_js.MonoCloudJsError("useMonoCloudClient() can only be used inside a <MonoCloudAuthProvider>...</MonoCloudAuthProvider>.");
42
+ return client;
43
+ };
44
+ //#endregion
45
+ exports.useMonoCloudClient = useMonoCloudClient;
46
+
47
+ //# sourceMappingURL=use-monocloud-client.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-monocloud-client.cjs","names":["MonoCloudClientContext","MonoCloudJsError"],"sources":["../src/use-monocloud-client.tsx"],"sourcesContent":["'use client';\n\nimport { MonoCloudJsError } from '@monocloud/auth-web-js';\nimport type { MonoCloudWebJSClient } from '@monocloud/auth-web-js';\nimport { useContext } from 'react';\nimport { MonoCloudClientContext } from './context';\nimport type { MonoCloudAuthProvider } from './monocloud-auth-provider';\nimport type { useAuth } from './use-auth';\n\n/**\n * `useMonoCloudClient()` returns the underlying {@link MonoCloudWebJSClient} created by\n * {@link MonoCloudAuthProvider}.\n *\n * @remarks\n * This is intended for advanced, lower-level operations that\n * {@link useAuth} does not cover - for example token revocation via\n * `client.oidcClient`. Most applications only need {@link useAuth}.\n *\n * @example Revoking the access token\n *\n * ```tsx title=\"Revoking the access token\"\n * \"use client\";\n *\n * import { useAuth, useMonoCloudClient } from \"@monocloud/auth-react\";\n *\n * export default function RevokeButton() {\n * const { getTokens } = useAuth();\n * const client = useMonoCloudClient();\n *\n * const revoke = async () => {\n * const tokens = await getTokens();\n * await client.oidcClient.revokeToken(tokens.accessToken);\n * };\n *\n * return <button onClick={() => void revoke()}>Revoke</button>;\n * }\n * ```\n *\n * @returns The underlying {@link MonoCloudWebJSClient} instance.\n *\n * @category Hooks\n */\nexport const useMonoCloudClient = (): MonoCloudWebJSClient => {\n const client = useContext(MonoCloudClientContext);\n\n if (!client) {\n throw new MonoCloudJsError(\n 'useMonoCloudClient() can only be used inside a <MonoCloudAuthProvider>...</MonoCloudAuthProvider>.'\n );\n }\n\n return client;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,2BAAiD;CAC5D,MAAM,UAAA,GAAA,MAAA,YAAoBA,gBAAAA,sBAAsB;CAEhD,IAAI,CAAC,QACH,MAAM,IAAIC,uBAAAA,iBACR,oGACF;CAGF,OAAO;AACT"}
@@ -0,0 +1,40 @@
1
+ import { MonoCloudWebJSClient } from "@monocloud/auth-web-js";
2
+
3
+ //#region src/use-monocloud-client.d.ts
4
+ /**
5
+ * `useMonoCloudClient()` returns the underlying {@link MonoCloudWebJSClient} created by
6
+ * {@link MonoCloudAuthProvider}.
7
+ *
8
+ * @remarks
9
+ * This is intended for advanced, lower-level operations that
10
+ * {@link useAuth} does not cover - for example token revocation via
11
+ * `client.oidcClient`. Most applications only need {@link useAuth}.
12
+ *
13
+ * @example Revoking the access token
14
+ *
15
+ * ```tsx title="Revoking the access token"
16
+ * "use client";
17
+ *
18
+ * import { useAuth, useMonoCloudClient } from "@monocloud/auth-react";
19
+ *
20
+ * export default function RevokeButton() {
21
+ * const { getTokens } = useAuth();
22
+ * const client = useMonoCloudClient();
23
+ *
24
+ * const revoke = async () => {
25
+ * const tokens = await getTokens();
26
+ * await client.oidcClient.revokeToken(tokens.accessToken);
27
+ * };
28
+ *
29
+ * return <button onClick={() => void revoke()}>Revoke</button>;
30
+ * }
31
+ * ```
32
+ *
33
+ * @returns The underlying {@link MonoCloudWebJSClient} instance.
34
+ *
35
+ * @category Hooks
36
+ */
37
+ declare const useMonoCloudClient: () => MonoCloudWebJSClient;
38
+ //#endregion
39
+ export { useMonoCloudClient };
40
+ //# sourceMappingURL=use-monocloud-client.d.mts.map
@@ -0,0 +1,47 @@
1
+ "use client";
2
+ import { MonoCloudClientContext } from "./context.mjs";
3
+ import { MonoCloudJsError } from "@monocloud/auth-web-js";
4
+ import { useContext } from "react";
5
+ //#region src/use-monocloud-client.tsx
6
+ /**
7
+ * `useMonoCloudClient()` returns the underlying {@link MonoCloudWebJSClient} created by
8
+ * {@link MonoCloudAuthProvider}.
9
+ *
10
+ * @remarks
11
+ * This is intended for advanced, lower-level operations that
12
+ * {@link useAuth} does not cover - for example token revocation via
13
+ * `client.oidcClient`. Most applications only need {@link useAuth}.
14
+ *
15
+ * @example Revoking the access token
16
+ *
17
+ * ```tsx title="Revoking the access token"
18
+ * "use client";
19
+ *
20
+ * import { useAuth, useMonoCloudClient } from "@monocloud/auth-react";
21
+ *
22
+ * export default function RevokeButton() {
23
+ * const { getTokens } = useAuth();
24
+ * const client = useMonoCloudClient();
25
+ *
26
+ * const revoke = async () => {
27
+ * const tokens = await getTokens();
28
+ * await client.oidcClient.revokeToken(tokens.accessToken);
29
+ * };
30
+ *
31
+ * return <button onClick={() => void revoke()}>Revoke</button>;
32
+ * }
33
+ * ```
34
+ *
35
+ * @returns The underlying {@link MonoCloudWebJSClient} instance.
36
+ *
37
+ * @category Hooks
38
+ */
39
+ const useMonoCloudClient = () => {
40
+ const client = useContext(MonoCloudClientContext);
41
+ if (!client) throw new MonoCloudJsError("useMonoCloudClient() can only be used inside a <MonoCloudAuthProvider>...</MonoCloudAuthProvider>.");
42
+ return client;
43
+ };
44
+ //#endregion
45
+ export { useMonoCloudClient };
46
+
47
+ //# sourceMappingURL=use-monocloud-client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-monocloud-client.mjs","names":[],"sources":["../src/use-monocloud-client.tsx"],"sourcesContent":["'use client';\n\nimport { MonoCloudJsError } from '@monocloud/auth-web-js';\nimport type { MonoCloudWebJSClient } from '@monocloud/auth-web-js';\nimport { useContext } from 'react';\nimport { MonoCloudClientContext } from './context';\nimport type { MonoCloudAuthProvider } from './monocloud-auth-provider';\nimport type { useAuth } from './use-auth';\n\n/**\n * `useMonoCloudClient()` returns the underlying {@link MonoCloudWebJSClient} created by\n * {@link MonoCloudAuthProvider}.\n *\n * @remarks\n * This is intended for advanced, lower-level operations that\n * {@link useAuth} does not cover - for example token revocation via\n * `client.oidcClient`. Most applications only need {@link useAuth}.\n *\n * @example Revoking the access token\n *\n * ```tsx title=\"Revoking the access token\"\n * \"use client\";\n *\n * import { useAuth, useMonoCloudClient } from \"@monocloud/auth-react\";\n *\n * export default function RevokeButton() {\n * const { getTokens } = useAuth();\n * const client = useMonoCloudClient();\n *\n * const revoke = async () => {\n * const tokens = await getTokens();\n * await client.oidcClient.revokeToken(tokens.accessToken);\n * };\n *\n * return <button onClick={() => void revoke()}>Revoke</button>;\n * }\n * ```\n *\n * @returns The underlying {@link MonoCloudWebJSClient} instance.\n *\n * @category Hooks\n */\nexport const useMonoCloudClient = (): MonoCloudWebJSClient => {\n const client = useContext(MonoCloudClientContext);\n\n if (!client) {\n throw new MonoCloudJsError(\n 'useMonoCloudClient() can only be used inside a <MonoCloudAuthProvider>...</MonoCloudAuthProvider>.'\n );\n }\n\n return client;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,2BAAiD;CAC5D,MAAM,SAAS,WAAW,sBAAsB;CAEhD,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,oGACF;CAGF,OAAO;AACT"}
@@ -0,0 +1,14 @@
1
+ "use client";
2
+ const require_context = require("./context.cjs");
3
+ let _monocloud_auth_web_js = require("@monocloud/auth-web-js");
4
+ let react = require("react");
5
+ //#region src/use-process-callback.tsx
6
+ const useProcessCallback = () => {
7
+ const processCallback = (0, react.useContext)(require_context.MonoCloudProcessCallbackContext);
8
+ if (!processCallback) throw new _monocloud_auth_web_js.MonoCloudJsError("<ProcessCallback /> can only be used inside a <MonoCloudAuthProvider>...</MonoCloudAuthProvider>.");
9
+ return processCallback;
10
+ };
11
+ //#endregion
12
+ exports.useProcessCallback = useProcessCallback;
13
+
14
+ //# sourceMappingURL=use-process-callback.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-process-callback.cjs","names":["MonoCloudProcessCallbackContext","MonoCloudJsError"],"sources":["../src/use-process-callback.tsx"],"sourcesContent":["'use client';\n\nimport { MonoCloudJsError } from '@monocloud/auth-web-js';\nimport { useContext } from 'react';\nimport { MonoCloudProcessCallbackContext } from './context';\n\nexport const useProcessCallback = (): (() => Promise<void>) => {\n const processCallback = useContext(MonoCloudProcessCallbackContext);\n\n if (!processCallback) {\n throw new MonoCloudJsError(\n '<ProcessCallback /> can only be used inside a <MonoCloudAuthProvider>...</MonoCloudAuthProvider>.'\n );\n }\n\n return processCallback;\n};\n"],"mappings":";;;;;AAMA,MAAa,2BAAkD;CAC7D,MAAM,mBAAA,GAAA,MAAA,YAA6BA,gBAAAA,+BAA+B;CAElE,IAAI,CAAC,iBACH,MAAM,IAAIC,uBAAAA,iBACR,mGACF;CAGF,OAAO;AACT"}
@@ -0,0 +1,14 @@
1
+ "use client";
2
+ import { MonoCloudProcessCallbackContext } from "./context.mjs";
3
+ import { MonoCloudJsError } from "@monocloud/auth-web-js";
4
+ import { useContext } from "react";
5
+ //#region src/use-process-callback.tsx
6
+ const useProcessCallback = () => {
7
+ const processCallback = useContext(MonoCloudProcessCallbackContext);
8
+ if (!processCallback) throw new MonoCloudJsError("<ProcessCallback /> can only be used inside a <MonoCloudAuthProvider>...</MonoCloudAuthProvider>.");
9
+ return processCallback;
10
+ };
11
+ //#endregion
12
+ export { useProcessCallback };
13
+
14
+ //# sourceMappingURL=use-process-callback.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-process-callback.mjs","names":[],"sources":["../src/use-process-callback.tsx"],"sourcesContent":["'use client';\n\nimport { MonoCloudJsError } from '@monocloud/auth-web-js';\nimport { useContext } from 'react';\nimport { MonoCloudProcessCallbackContext } from './context';\n\nexport const useProcessCallback = (): (() => Promise<void>) => {\n const processCallback = useContext(MonoCloudProcessCallbackContext);\n\n if (!processCallback) {\n throw new MonoCloudJsError(\n '<ProcessCallback /> can only be used inside a <MonoCloudAuthProvider>...</MonoCloudAuthProvider>.'\n );\n }\n\n return processCallback;\n};\n"],"mappings":";;;;;AAMA,MAAa,2BAAkD;CAC7D,MAAM,kBAAkB,WAAW,+BAA+B;CAElE,IAAI,CAAC,iBACH,MAAM,IAAI,iBACR,mGACF;CAGF,OAAO;AACT"}
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@monocloud/auth-react",
3
+ "version": "0.1.1-canary-20260605042109",
4
+ "description": "MonoCloud React Authentication SDK",
5
+ "keywords": [
6
+ "monocloud",
7
+ "authentication",
8
+ "auth",
9
+ "sdk",
10
+ "react",
11
+ "spa",
12
+ "browser"
13
+ ],
14
+ "homepage": "https://www.monocloud.com",
15
+ "bugs": {
16
+ "url": "https://github.com/monocloud/auth-js/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/monocloud/auth-js.git",
21
+ "directory": "packages/react"
22
+ },
23
+ "license": "MIT",
24
+ "author": {
25
+ "name": "MonoCloud",
26
+ "email": "support@monocloud.com"
27
+ },
28
+ "main": "./dist/index.cjs",
29
+ "module": "./dist/index.mjs",
30
+ "types": "./dist/index.d.mts",
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.mts",
37
+ "import": "./dist/index.mjs",
38
+ "require": "./dist/index.cjs"
39
+ }
40
+ },
41
+ "dependencies": {
42
+ "@monocloud/auth-web-js": "0.1.2"
43
+ },
44
+ "devDependencies": {
45
+ "@testing-library/dom": "10.4.1",
46
+ "@testing-library/react": "16.3.2",
47
+ "@types/react": "19.2.15",
48
+ "@types/react-dom": "19.2.3",
49
+ "eslint": "10.4.0",
50
+ "@monocloud/auth-test-utils": "0.0.1"
51
+ },
52
+ "peerDependencies": {
53
+ "react": "^18.0.0 || ^19.2.3",
54
+ "react-dom": "^18.3.1 || ^19.2.3"
55
+ },
56
+ "engines": {
57
+ "node": ">=16"
58
+ },
59
+ "scripts": {
60
+ "build": "tsdown",
61
+ "lint:es": "eslint src tests",
62
+ "lint:ts": "tsc",
63
+ "lint": "pnpm run lint:es && pnpm run lint:ts",
64
+ "test": "eslint tests && rimraf coverage && vitest && pnpm report",
65
+ "report": "nyc report --reporter json-summary --reporter html --reporter text -t ./coverage --report-dir ./coverage/summary && npx @monocloud/auth-test-utils check-coverage"
66
+ }
67
+ }