@monocloud/auth-nextjs 0.1.9 → 0.1.11
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 +1 -1
- package/dist/{chunk-C0xms8kb.cjs → _virtual/_rolldown/runtime.cjs} +1 -6
- package/dist/client/index.cjs +3 -2
- package/dist/client/index.d.mts +3 -203
- package/dist/client/index.mjs +2 -1
- package/dist/{protect-client-page-BdsnH8gs.cjs → client/protect-client-page.cjs} +9 -112
- package/dist/client/protect-client-page.cjs.map +1 -0
- package/dist/client/protect-client-page.d.mts +123 -0
- package/dist/{protect-client-page-BFVskb3X.mjs → client/protect-client-page.mjs} +5 -91
- package/dist/client/protect-client-page.mjs.map +1 -0
- package/dist/client/use-auth.cjs +96 -0
- package/dist/client/use-auth.cjs.map +1 -0
- package/dist/client/use-auth.d.mts +84 -0
- package/dist/client/use-auth.mjs +94 -0
- package/dist/client/use-auth.mjs.map +1 -0
- package/dist/components/client/index.cjs +4 -156
- package/dist/components/client/index.d.mts +3 -189
- package/dist/components/client/index.mjs +3 -153
- package/dist/components/client/protected.cjs +89 -0
- package/dist/components/client/protected.cjs.map +1 -0
- package/dist/components/client/protected.d.mts +114 -0
- package/dist/components/client/protected.mjs +87 -0
- package/dist/components/client/protected.mjs.map +1 -0
- package/dist/components/client/redirect-to-signin.cjs +77 -0
- package/dist/components/client/redirect-to-signin.cjs.map +1 -0
- package/dist/components/client/redirect-to-signin.d.mts +78 -0
- package/dist/components/client/redirect-to-signin.mjs +76 -0
- package/dist/components/client/redirect-to-signin.mjs.map +1 -0
- package/dist/components/index.cjs +6 -168
- package/dist/components/index.d.mts +4 -188
- package/dist/components/index.mjs +4 -164
- package/dist/components/signin.cjs +63 -0
- package/dist/components/signin.cjs.map +1 -0
- package/dist/components/signin.d.mts +72 -0
- package/dist/components/signin.mjs +61 -0
- package/dist/components/signin.mjs.map +1 -0
- package/dist/components/signout.cjs +49 -0
- package/dist/components/signout.cjs.map +1 -0
- package/dist/components/signout.d.mts +55 -0
- package/dist/components/signout.mjs +47 -0
- package/dist/components/signout.mjs.map +1 -0
- package/dist/components/signup.cjs +67 -0
- package/dist/components/signup.cjs.map +1 -0
- package/dist/components/signup.d.mts +70 -0
- package/dist/components/signup.mjs +65 -0
- package/dist/components/signup.mjs.map +1 -0
- package/dist/index.cjs +15 -1136
- package/dist/index.d.mts +5 -1681
- package/dist/index.mjs +4 -1125
- package/dist/initialize.cjs +284 -0
- package/dist/initialize.cjs.map +1 -0
- package/dist/initialize.d.mts +1383 -0
- package/dist/initialize.mjs +274 -0
- package/dist/initialize.mjs.map +1 -0
- package/dist/monocloud-next-client.cjs +600 -0
- package/dist/monocloud-next-client.cjs.map +1 -0
- package/dist/monocloud-next-client.d.mts +330 -0
- package/dist/monocloud-next-client.mjs +599 -0
- package/dist/monocloud-next-client.mjs.map +1 -0
- package/dist/requests/monocloud-app-router-request.cjs +32 -0
- package/dist/requests/monocloud-app-router-request.cjs.map +1 -0
- package/dist/requests/monocloud-app-router-request.mjs +31 -0
- package/dist/requests/monocloud-app-router-request.mjs.map +1 -0
- package/dist/requests/monocloud-cookie-request.cjs +22 -0
- package/dist/requests/monocloud-cookie-request.cjs.map +1 -0
- package/dist/requests/monocloud-cookie-request.mjs +21 -0
- package/dist/requests/monocloud-cookie-request.mjs.map +1 -0
- package/dist/requests/monocloud-page-router-request.cjs +37 -0
- package/dist/requests/monocloud-page-router-request.cjs.map +1 -0
- package/dist/requests/monocloud-page-router-request.mjs +36 -0
- package/dist/requests/monocloud-page-router-request.mjs.map +1 -0
- package/dist/responses/monocloud-app-router-response.cjs +67 -0
- package/dist/responses/monocloud-app-router-response.cjs.map +1 -0
- package/dist/responses/monocloud-app-router-response.mjs +66 -0
- package/dist/responses/monocloud-app-router-response.mjs.map +1 -0
- package/dist/responses/monocloud-cookie-response.cjs +20 -0
- package/dist/responses/monocloud-cookie-response.cjs.map +1 -0
- package/dist/responses/monocloud-cookie-response.mjs +19 -0
- package/dist/responses/monocloud-cookie-response.mjs.map +1 -0
- package/dist/responses/monocloud-page-router-response.cjs +54 -0
- package/dist/responses/monocloud-page-router-response.cjs.map +1 -0
- package/dist/responses/monocloud-page-router-response.mjs +53 -0
- package/dist/responses/monocloud-page-router-response.mjs.map +1 -0
- package/dist/{types-ClljFIvK.d.mts → types.d.mts} +2 -2
- package/dist/utils.cjs +89 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.mjs +80 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +3 -3
- package/dist/components/client/index.cjs.map +0 -1
- package/dist/components/client/index.mjs.map +0 -1
- package/dist/components/index.cjs.map +0 -1
- package/dist/components/index.mjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/protect-client-page-BFVskb3X.mjs.map +0 -1
- package/dist/protect-client-page-BdsnH8gs.cjs.map +0 -1
|
@@ -1,154 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "
|
|
3
|
-
import { isUserInGroup } from "@monocloud/auth-node-core/utils";
|
|
4
|
-
import React, { useEffect } from "react";
|
|
1
|
+
import { RedirectToSignIn } from "./redirect-to-signin.mjs";
|
|
2
|
+
import { Protected } from "./protected.mjs";
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* `<RedirectToSignIn>` is a **client-side component** that immediately redirects the user to the MonoCloud sign-in page when it is rendered.
|
|
9
|
-
*
|
|
10
|
-
* It does not render any UI.
|
|
11
|
-
*
|
|
12
|
-
* > This component must be used inside a Client Component (`"use client"`).
|
|
13
|
-
*
|
|
14
|
-
* @example Basic Usage
|
|
15
|
-
*
|
|
16
|
-
* ```tsx title="Basic Usage"
|
|
17
|
-
* "use client";
|
|
18
|
-
*
|
|
19
|
-
* import { useAuth } from "@monocloud/auth-nextjs/client";
|
|
20
|
-
* import { RedirectToSignIn } from "@monocloud/auth-nextjs/components/client";
|
|
21
|
-
*
|
|
22
|
-
* export default function Home() {
|
|
23
|
-
* const { isLoading, isAuthenticated } = useAuth();
|
|
24
|
-
*
|
|
25
|
-
* if (!isLoading && !isAuthenticated) {
|
|
26
|
-
* return <RedirectToSignIn />;
|
|
27
|
-
* }
|
|
28
|
-
*
|
|
29
|
-
* return <>You are signed in</>;
|
|
30
|
-
* }
|
|
31
|
-
* ```
|
|
32
|
-
*
|
|
33
|
-
* @example With Options
|
|
34
|
-
*
|
|
35
|
-
* You can customize the authorization request by passing in props.
|
|
36
|
-
*
|
|
37
|
-
* ```tsx title="With options"
|
|
38
|
-
* "use client";
|
|
39
|
-
*
|
|
40
|
-
* import { useAuth } from "@monocloud/auth-nextjs/client";
|
|
41
|
-
* import { RedirectToSignIn } from "@monocloud/auth-nextjs/components/client";
|
|
42
|
-
*
|
|
43
|
-
* export default function Home() {
|
|
44
|
-
* const { isLoading, isAuthenticated } = useAuth();
|
|
45
|
-
*
|
|
46
|
-
* if (!isLoading && !isAuthenticated) {
|
|
47
|
-
* return (
|
|
48
|
-
* <RedirectToSignIn
|
|
49
|
-
* returnUrl="/dashboard"
|
|
50
|
-
* loginHint="user@example.com"
|
|
51
|
-
* />
|
|
52
|
-
* );
|
|
53
|
-
* }
|
|
54
|
-
*
|
|
55
|
-
* return <>You are signed in</>;
|
|
56
|
-
* }
|
|
57
|
-
* ```
|
|
58
|
-
*
|
|
59
|
-
* @param props - The props for customizing RedirectToSignIn.
|
|
60
|
-
* @returns
|
|
61
|
-
*
|
|
62
|
-
* @category Components
|
|
63
|
-
*/
|
|
64
|
-
const RedirectToSignIn = ({ returnUrl, ...authParams }) => {
|
|
65
|
-
useEffect(() => {
|
|
66
|
-
redirectToSignIn({
|
|
67
|
-
returnUrl,
|
|
68
|
-
...authParams
|
|
69
|
-
});
|
|
70
|
-
}, [authParams, returnUrl]);
|
|
71
|
-
return null;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
//#endregion
|
|
75
|
-
//#region src/components/client/protected.tsx
|
|
76
|
-
/**
|
|
77
|
-
* `<Protected>` conditionally renders its children based on the user’s authentication state and (optionally) group membership.
|
|
78
|
-
*
|
|
79
|
-
* > `<Protected>` runs on the client and only affects what is rendered. It does **not** prevent data from being sent to the browser.
|
|
80
|
-
* > To enforce access before content is rendered or sent to the client, use server-side protection such as {@link MonoCloudNextClient.protectPage | protectPage()}, or {@link MonoCloudNextClient.protect | protect()}.
|
|
81
|
-
*
|
|
82
|
-
* @example Basic Usage
|
|
83
|
-
*
|
|
84
|
-
* ```tsx title="Basic Usage"
|
|
85
|
-
* "use client";
|
|
86
|
-
*
|
|
87
|
-
* import { Protected } from "@monocloud/auth-nextjs/components/client";
|
|
88
|
-
*
|
|
89
|
-
* export default function Home() {
|
|
90
|
-
* return (
|
|
91
|
-
* <Protected fallback={<>Sign in to view the message.</>}>
|
|
92
|
-
* <>This is the protected content.</>
|
|
93
|
-
* </Protected>
|
|
94
|
-
* );
|
|
95
|
-
* }
|
|
96
|
-
* ```
|
|
97
|
-
*
|
|
98
|
-
* @example With Groups
|
|
99
|
-
*
|
|
100
|
-
* ```tsx title="With Groups"
|
|
101
|
-
* "use client";
|
|
102
|
-
*
|
|
103
|
-
* import { Protected } from "@monocloud/auth-nextjs/components/client";
|
|
104
|
-
*
|
|
105
|
-
* export default function Home() {
|
|
106
|
-
* return (
|
|
107
|
-
* <Protected
|
|
108
|
-
* groups={["admin"]}
|
|
109
|
-
* onGroupAccessDenied={(user) => <>User {user.email} is not allowed to access admin content.</>}
|
|
110
|
-
* >
|
|
111
|
-
* <>Signed in as admin</>
|
|
112
|
-
* </Protected>
|
|
113
|
-
* );
|
|
114
|
-
* }
|
|
115
|
-
* ```
|
|
116
|
-
*
|
|
117
|
-
* @example Requiring all groups
|
|
118
|
-
*
|
|
119
|
-
* ```tsx title="Requiring all groups"
|
|
120
|
-
* "use client";
|
|
121
|
-
*
|
|
122
|
-
* import { Protected } from "@monocloud/auth-nextjs/components/client";
|
|
123
|
-
*
|
|
124
|
-
* export default function Home() {
|
|
125
|
-
* return (
|
|
126
|
-
* <Protected
|
|
127
|
-
* groups={["admin", "billing"]}
|
|
128
|
-
* matchAllGroups
|
|
129
|
-
* onGroupAccessDenied={(user) => <>User {user.email} is not allowed to access billing content.</>}
|
|
130
|
-
* >
|
|
131
|
-
* <>Sensitive settings</>
|
|
132
|
-
* </Protected>
|
|
133
|
-
* );
|
|
134
|
-
* }
|
|
135
|
-
* ```
|
|
136
|
-
*
|
|
137
|
-
* @param props - Props for customizing the Protected component.
|
|
138
|
-
* @returns The children if authorized, the `fallback` or `onGroupAccessDenied` content if unauthenticated or unauthorized, or `null` while loading.
|
|
139
|
-
*
|
|
140
|
-
* @category Components
|
|
141
|
-
*/
|
|
142
|
-
const Protected = ({ children, groups, groupsClaim, matchAllGroups = false, fallback = null, onGroupAccessDenied = () => /* @__PURE__ */ React.createElement(React.Fragment, null) }) => {
|
|
143
|
-
const { isLoading, error, isAuthenticated, user } = useAuth();
|
|
144
|
-
if (isLoading) return null;
|
|
145
|
-
if (error || !isAuthenticated || !user) {
|
|
146
|
-
if (fallback) return fallback;
|
|
147
|
-
return null;
|
|
148
|
-
}
|
|
149
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, !groups || isUserInGroup(user, groups, groupsClaim ?? process.env.NEXT_PUBLIC_MONOCLOUD_AUTH_GROUPS_CLAIM, matchAllGroups) ? children : onGroupAccessDenied(user));
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
//#endregion
|
|
153
|
-
export { Protected, RedirectToSignIn };
|
|
154
|
-
//# sourceMappingURL=index.mjs.map
|
|
4
|
+
export { Protected, RedirectToSignIn };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
4
|
+
const require_use_auth = require('../../client/use-auth.cjs');
|
|
5
|
+
require('../../client/index.cjs');
|
|
6
|
+
let _monocloud_auth_node_core_utils = require("@monocloud/auth-node-core/utils");
|
|
7
|
+
let react = require("react");
|
|
8
|
+
react = require_runtime.__toESM(react);
|
|
9
|
+
|
|
10
|
+
//#region src/components/client/protected.tsx
|
|
11
|
+
/**
|
|
12
|
+
* `<Protected>` conditionally renders its children based on the user’s authentication state and (optionally) group membership.
|
|
13
|
+
*
|
|
14
|
+
* > `<Protected>` runs on the client and only affects what is rendered. It does **not** prevent data from being sent to the browser.
|
|
15
|
+
* > To enforce access before content is rendered or sent to the client, use server-side protection such as {@link MonoCloudNextClient.protectPage | protectPage()}, or {@link MonoCloudNextClient.protect | protect()}.
|
|
16
|
+
*
|
|
17
|
+
* @example Basic Usage
|
|
18
|
+
*
|
|
19
|
+
* ```tsx title="Basic Usage"
|
|
20
|
+
* "use client";
|
|
21
|
+
*
|
|
22
|
+
* import { Protected } from "@monocloud/auth-nextjs/components/client";
|
|
23
|
+
*
|
|
24
|
+
* export default function Home() {
|
|
25
|
+
* return (
|
|
26
|
+
* <Protected fallback={<>Sign in to view the message.</>}>
|
|
27
|
+
* <>This is the protected content.</>
|
|
28
|
+
* </Protected>
|
|
29
|
+
* );
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example With Groups
|
|
34
|
+
*
|
|
35
|
+
* ```tsx title="With Groups"
|
|
36
|
+
* "use client";
|
|
37
|
+
*
|
|
38
|
+
* import { Protected } from "@monocloud/auth-nextjs/components/client";
|
|
39
|
+
*
|
|
40
|
+
* export default function Home() {
|
|
41
|
+
* return (
|
|
42
|
+
* <Protected
|
|
43
|
+
* groups={["admin"]}
|
|
44
|
+
* onGroupAccessDenied={(user) => <>User {user.email} is not allowed to access admin content.</>}
|
|
45
|
+
* >
|
|
46
|
+
* <>Signed in as admin</>
|
|
47
|
+
* </Protected>
|
|
48
|
+
* );
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example Requiring all groups
|
|
53
|
+
*
|
|
54
|
+
* ```tsx title="Requiring all groups"
|
|
55
|
+
* "use client";
|
|
56
|
+
*
|
|
57
|
+
* import { Protected } from "@monocloud/auth-nextjs/components/client";
|
|
58
|
+
*
|
|
59
|
+
* export default function Home() {
|
|
60
|
+
* return (
|
|
61
|
+
* <Protected
|
|
62
|
+
* groups={["admin", "billing"]}
|
|
63
|
+
* matchAllGroups
|
|
64
|
+
* onGroupAccessDenied={(user) => <>User {user.email} is not allowed to access billing content.</>}
|
|
65
|
+
* >
|
|
66
|
+
* <>Sensitive settings</>
|
|
67
|
+
* </Protected>
|
|
68
|
+
* );
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @param props - Props for customizing the Protected component.
|
|
73
|
+
* @returns The children if authorized, the `fallback` or `onGroupAccessDenied` content if unauthenticated or unauthorized, or `null` while loading.
|
|
74
|
+
*
|
|
75
|
+
* @category Components
|
|
76
|
+
*/
|
|
77
|
+
const Protected = ({ children, groups, groupsClaim, matchAllGroups = false, fallback = null, onGroupAccessDenied = () => /* @__PURE__ */ react.default.createElement(react.default.Fragment, null) }) => {
|
|
78
|
+
const { isLoading, error, isAuthenticated, user } = require_use_auth.useAuth();
|
|
79
|
+
if (isLoading) return null;
|
|
80
|
+
if (error || !isAuthenticated || !user) {
|
|
81
|
+
if (fallback) return fallback;
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, !groups || (0, _monocloud_auth_node_core_utils.isUserInGroup)(user, groups, groupsClaim ?? process.env.NEXT_PUBLIC_MONOCLOUD_AUTH_GROUPS_CLAIM, matchAllGroups) ? children : onGroupAccessDenied(user));
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
exports.Protected = Protected;
|
|
89
|
+
//# sourceMappingURL=protected.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protected.cjs","names":["useAuth"],"sources":["../../../src/components/client/protected.tsx"],"sourcesContent":["'use client';\n\nimport { isUserInGroup } from '@monocloud/auth-node-core/utils';\nimport React from 'react';\nimport { useAuth } from '../../client';\nimport type { MonoCloudUser } from '@monocloud/auth-node-core';\nimport type { MonoCloudNextClient } from '../../monocloud-next-client';\n\n/**\n * Props for the `<Protected />` component.\n *\n * @category Types\n */\nexport interface ProtectedComponentProps {\n /**\n * Content to render when access is allowed.\n */\n children: React.ReactNode;\n\n /**\n * Groups required to view the protected content. By default, the user must belong to **any** of the specified groups.\n */\n groups?: string[];\n\n /**\n * Name of the claim that contains groups in the user profile.\n * @defaultValue 'groups'\n */\n groupsClaim?: string;\n\n /**\n * If `true`, the user must belong to **all** specified `groups` (instead of any).\n * @defaultValue false\n */\n matchAllGroups?: boolean;\n\n /**\n * Content to render when the user is not authenticated.\n */\n fallback?: React.ReactNode;\n\n /**\n * Rendered when the user is authenticated but does not meet the `groups` requirement. If omitted, nothing is rendered (or `fallback` is used only for unauthenticated users).\n */\n onGroupAccessDenied?: (user: MonoCloudUser) => React.ReactNode;\n}\n\n/**\n * `<Protected>` conditionally renders its children based on the user’s authentication state and (optionally) group membership.\n *\n * > `<Protected>` runs on the client and only affects what is rendered. It does **not** prevent data from being sent to the browser.\n * > To enforce access before content is rendered or sent to the client, use server-side protection such as {@link MonoCloudNextClient.protectPage | protectPage()}, or {@link MonoCloudNextClient.protect | protect()}.\n *\n * @example Basic Usage\n *\n * ```tsx title=\"Basic Usage\"\n * \"use client\";\n *\n * import { Protected } from \"@monocloud/auth-nextjs/components/client\";\n *\n * export default function Home() {\n * return (\n * <Protected fallback={<>Sign in to view the message.</>}>\n * <>This is the protected content.</>\n * </Protected>\n * );\n * }\n * ```\n *\n * @example With Groups\n *\n * ```tsx title=\"With Groups\"\n * \"use client\";\n *\n * import { Protected } from \"@monocloud/auth-nextjs/components/client\";\n *\n * export default function Home() {\n * return (\n * <Protected\n * groups={[\"admin\"]}\n * onGroupAccessDenied={(user) => <>User {user.email} is not allowed to access admin content.</>}\n * >\n * <>Signed in as admin</>\n * </Protected>\n * );\n * }\n * ```\n *\n * @example Requiring all groups\n *\n * ```tsx title=\"Requiring all groups\"\n * \"use client\";\n *\n * import { Protected } from \"@monocloud/auth-nextjs/components/client\";\n *\n * export default function Home() {\n * return (\n * <Protected\n * groups={[\"admin\", \"billing\"]}\n * matchAllGroups\n * onGroupAccessDenied={(user) => <>User {user.email} is not allowed to access billing content.</>}\n * >\n * <>Sensitive settings</>\n * </Protected>\n * );\n * }\n * ```\n *\n * @param props - Props for customizing the Protected component.\n * @returns The children if authorized, the `fallback` or `onGroupAccessDenied` content if unauthenticated or unauthorized, or `null` while loading.\n *\n * @category Components\n */\nexport const Protected = ({\n children,\n groups,\n groupsClaim,\n matchAllGroups = false,\n fallback = null,\n onGroupAccessDenied = (): React.ReactNode => <></>,\n}: ProtectedComponentProps): React.ReactNode | null => {\n const { isLoading, error, isAuthenticated, user } = useAuth();\n\n if (isLoading) {\n return null;\n }\n\n if (error || !isAuthenticated || !user) {\n if (fallback) {\n return fallback;\n }\n\n return null;\n }\n\n return (\n <>\n {!groups ||\n isUserInGroup(\n user,\n groups,\n groupsClaim ?? process.env.NEXT_PUBLIC_MONOCLOUD_AUTH_GROUPS_CLAIM,\n matchAllGroups\n )\n ? children\n : onGroupAccessDenied(user)}\n </>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiHA,MAAa,aAAa,EACxB,UACA,QACA,aACA,iBAAiB,OACjB,WAAW,MACX,4BAA6C,yEAAK,OACG;CACrD,MAAM,EAAE,WAAW,OAAO,iBAAiB,SAASA,0BAAS;AAE7D,KAAI,UACF,QAAO;AAGT,KAAI,SAAS,CAAC,mBAAmB,CAAC,MAAM;AACtC,MAAI,SACF,QAAO;AAGT,SAAO;;AAGT,QACE,0EACG,CAAC,6DAEA,MACA,QACA,eAAe,QAAQ,IAAI,yCAC3B,eACD,GACG,WACA,oBAAoB,KAAK,CAC5B"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { MonoCloudUser } from "@monocloud/auth-node-core";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/components/client/protected.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Props for the `<Protected />` component.
|
|
7
|
+
*
|
|
8
|
+
* @category Types
|
|
9
|
+
*/
|
|
10
|
+
interface ProtectedComponentProps {
|
|
11
|
+
/**
|
|
12
|
+
* Content to render when access is allowed.
|
|
13
|
+
*/
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Groups required to view the protected content. By default, the user must belong to **any** of the specified groups.
|
|
17
|
+
*/
|
|
18
|
+
groups?: string[];
|
|
19
|
+
/**
|
|
20
|
+
* Name of the claim that contains groups in the user profile.
|
|
21
|
+
* @defaultValue 'groups'
|
|
22
|
+
*/
|
|
23
|
+
groupsClaim?: string;
|
|
24
|
+
/**
|
|
25
|
+
* If `true`, the user must belong to **all** specified `groups` (instead of any).
|
|
26
|
+
* @defaultValue false
|
|
27
|
+
*/
|
|
28
|
+
matchAllGroups?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Content to render when the user is not authenticated.
|
|
31
|
+
*/
|
|
32
|
+
fallback?: React.ReactNode;
|
|
33
|
+
/**
|
|
34
|
+
* Rendered when the user is authenticated but does not meet the `groups` requirement. If omitted, nothing is rendered (or `fallback` is used only for unauthenticated users).
|
|
35
|
+
*/
|
|
36
|
+
onGroupAccessDenied?: (user: MonoCloudUser) => React.ReactNode;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* `<Protected>` conditionally renders its children based on the user’s authentication state and (optionally) group membership.
|
|
40
|
+
*
|
|
41
|
+
* > `<Protected>` runs on the client and only affects what is rendered. It does **not** prevent data from being sent to the browser.
|
|
42
|
+
* > To enforce access before content is rendered or sent to the client, use server-side protection such as {@link MonoCloudNextClient.protectPage | protectPage()}, or {@link MonoCloudNextClient.protect | protect()}.
|
|
43
|
+
*
|
|
44
|
+
* @example Basic Usage
|
|
45
|
+
*
|
|
46
|
+
* ```tsx title="Basic Usage"
|
|
47
|
+
* "use client";
|
|
48
|
+
*
|
|
49
|
+
* import { Protected } from "@monocloud/auth-nextjs/components/client";
|
|
50
|
+
*
|
|
51
|
+
* export default function Home() {
|
|
52
|
+
* return (
|
|
53
|
+
* <Protected fallback={<>Sign in to view the message.</>}>
|
|
54
|
+
* <>This is the protected content.</>
|
|
55
|
+
* </Protected>
|
|
56
|
+
* );
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @example With Groups
|
|
61
|
+
*
|
|
62
|
+
* ```tsx title="With Groups"
|
|
63
|
+
* "use client";
|
|
64
|
+
*
|
|
65
|
+
* import { Protected } from "@monocloud/auth-nextjs/components/client";
|
|
66
|
+
*
|
|
67
|
+
* export default function Home() {
|
|
68
|
+
* return (
|
|
69
|
+
* <Protected
|
|
70
|
+
* groups={["admin"]}
|
|
71
|
+
* onGroupAccessDenied={(user) => <>User {user.email} is not allowed to access admin content.</>}
|
|
72
|
+
* >
|
|
73
|
+
* <>Signed in as admin</>
|
|
74
|
+
* </Protected>
|
|
75
|
+
* );
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @example Requiring all groups
|
|
80
|
+
*
|
|
81
|
+
* ```tsx title="Requiring all groups"
|
|
82
|
+
* "use client";
|
|
83
|
+
*
|
|
84
|
+
* import { Protected } from "@monocloud/auth-nextjs/components/client";
|
|
85
|
+
*
|
|
86
|
+
* export default function Home() {
|
|
87
|
+
* return (
|
|
88
|
+
* <Protected
|
|
89
|
+
* groups={["admin", "billing"]}
|
|
90
|
+
* matchAllGroups
|
|
91
|
+
* onGroupAccessDenied={(user) => <>User {user.email} is not allowed to access billing content.</>}
|
|
92
|
+
* >
|
|
93
|
+
* <>Sensitive settings</>
|
|
94
|
+
* </Protected>
|
|
95
|
+
* );
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @param props - Props for customizing the Protected component.
|
|
100
|
+
* @returns The children if authorized, the `fallback` or `onGroupAccessDenied` content if unauthenticated or unauthorized, or `null` while loading.
|
|
101
|
+
*
|
|
102
|
+
* @category Components
|
|
103
|
+
*/
|
|
104
|
+
declare const Protected: ({
|
|
105
|
+
children,
|
|
106
|
+
groups,
|
|
107
|
+
groupsClaim,
|
|
108
|
+
matchAllGroups,
|
|
109
|
+
fallback,
|
|
110
|
+
onGroupAccessDenied
|
|
111
|
+
}: ProtectedComponentProps) => React.ReactNode | null;
|
|
112
|
+
//#endregion
|
|
113
|
+
export { Protected, ProtectedComponentProps };
|
|
114
|
+
//# sourceMappingURL=protected.d.mts.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useAuth } from "../../client/use-auth.mjs";
|
|
4
|
+
import "../../client/index.mjs";
|
|
5
|
+
import { isUserInGroup } from "@monocloud/auth-node-core/utils";
|
|
6
|
+
import React from "react";
|
|
7
|
+
|
|
8
|
+
//#region src/components/client/protected.tsx
|
|
9
|
+
/**
|
|
10
|
+
* `<Protected>` conditionally renders its children based on the user’s authentication state and (optionally) group membership.
|
|
11
|
+
*
|
|
12
|
+
* > `<Protected>` runs on the client and only affects what is rendered. It does **not** prevent data from being sent to the browser.
|
|
13
|
+
* > To enforce access before content is rendered or sent to the client, use server-side protection such as {@link MonoCloudNextClient.protectPage | protectPage()}, or {@link MonoCloudNextClient.protect | protect()}.
|
|
14
|
+
*
|
|
15
|
+
* @example Basic Usage
|
|
16
|
+
*
|
|
17
|
+
* ```tsx title="Basic Usage"
|
|
18
|
+
* "use client";
|
|
19
|
+
*
|
|
20
|
+
* import { Protected } from "@monocloud/auth-nextjs/components/client";
|
|
21
|
+
*
|
|
22
|
+
* export default function Home() {
|
|
23
|
+
* return (
|
|
24
|
+
* <Protected fallback={<>Sign in to view the message.</>}>
|
|
25
|
+
* <>This is the protected content.</>
|
|
26
|
+
* </Protected>
|
|
27
|
+
* );
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example With Groups
|
|
32
|
+
*
|
|
33
|
+
* ```tsx title="With Groups"
|
|
34
|
+
* "use client";
|
|
35
|
+
*
|
|
36
|
+
* import { Protected } from "@monocloud/auth-nextjs/components/client";
|
|
37
|
+
*
|
|
38
|
+
* export default function Home() {
|
|
39
|
+
* return (
|
|
40
|
+
* <Protected
|
|
41
|
+
* groups={["admin"]}
|
|
42
|
+
* onGroupAccessDenied={(user) => <>User {user.email} is not allowed to access admin content.</>}
|
|
43
|
+
* >
|
|
44
|
+
* <>Signed in as admin</>
|
|
45
|
+
* </Protected>
|
|
46
|
+
* );
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @example Requiring all groups
|
|
51
|
+
*
|
|
52
|
+
* ```tsx title="Requiring all groups"
|
|
53
|
+
* "use client";
|
|
54
|
+
*
|
|
55
|
+
* import { Protected } from "@monocloud/auth-nextjs/components/client";
|
|
56
|
+
*
|
|
57
|
+
* export default function Home() {
|
|
58
|
+
* return (
|
|
59
|
+
* <Protected
|
|
60
|
+
* groups={["admin", "billing"]}
|
|
61
|
+
* matchAllGroups
|
|
62
|
+
* onGroupAccessDenied={(user) => <>User {user.email} is not allowed to access billing content.</>}
|
|
63
|
+
* >
|
|
64
|
+
* <>Sensitive settings</>
|
|
65
|
+
* </Protected>
|
|
66
|
+
* );
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @param props - Props for customizing the Protected component.
|
|
71
|
+
* @returns The children if authorized, the `fallback` or `onGroupAccessDenied` content if unauthenticated or unauthorized, or `null` while loading.
|
|
72
|
+
*
|
|
73
|
+
* @category Components
|
|
74
|
+
*/
|
|
75
|
+
const Protected = ({ children, groups, groupsClaim, matchAllGroups = false, fallback = null, onGroupAccessDenied = () => /* @__PURE__ */ React.createElement(React.Fragment, null) }) => {
|
|
76
|
+
const { isLoading, error, isAuthenticated, user } = useAuth();
|
|
77
|
+
if (isLoading) return null;
|
|
78
|
+
if (error || !isAuthenticated || !user) {
|
|
79
|
+
if (fallback) return fallback;
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, !groups || isUserInGroup(user, groups, groupsClaim ?? process.env.NEXT_PUBLIC_MONOCLOUD_AUTH_GROUPS_CLAIM, matchAllGroups) ? children : onGroupAccessDenied(user));
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
//#endregion
|
|
86
|
+
export { Protected };
|
|
87
|
+
//# sourceMappingURL=protected.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protected.mjs","names":[],"sources":["../../../src/components/client/protected.tsx"],"sourcesContent":["'use client';\n\nimport { isUserInGroup } from '@monocloud/auth-node-core/utils';\nimport React from 'react';\nimport { useAuth } from '../../client';\nimport type { MonoCloudUser } from '@monocloud/auth-node-core';\nimport type { MonoCloudNextClient } from '../../monocloud-next-client';\n\n/**\n * Props for the `<Protected />` component.\n *\n * @category Types\n */\nexport interface ProtectedComponentProps {\n /**\n * Content to render when access is allowed.\n */\n children: React.ReactNode;\n\n /**\n * Groups required to view the protected content. By default, the user must belong to **any** of the specified groups.\n */\n groups?: string[];\n\n /**\n * Name of the claim that contains groups in the user profile.\n * @defaultValue 'groups'\n */\n groupsClaim?: string;\n\n /**\n * If `true`, the user must belong to **all** specified `groups` (instead of any).\n * @defaultValue false\n */\n matchAllGroups?: boolean;\n\n /**\n * Content to render when the user is not authenticated.\n */\n fallback?: React.ReactNode;\n\n /**\n * Rendered when the user is authenticated but does not meet the `groups` requirement. If omitted, nothing is rendered (or `fallback` is used only for unauthenticated users).\n */\n onGroupAccessDenied?: (user: MonoCloudUser) => React.ReactNode;\n}\n\n/**\n * `<Protected>` conditionally renders its children based on the user’s authentication state and (optionally) group membership.\n *\n * > `<Protected>` runs on the client and only affects what is rendered. It does **not** prevent data from being sent to the browser.\n * > To enforce access before content is rendered or sent to the client, use server-side protection such as {@link MonoCloudNextClient.protectPage | protectPage()}, or {@link MonoCloudNextClient.protect | protect()}.\n *\n * @example Basic Usage\n *\n * ```tsx title=\"Basic Usage\"\n * \"use client\";\n *\n * import { Protected } from \"@monocloud/auth-nextjs/components/client\";\n *\n * export default function Home() {\n * return (\n * <Protected fallback={<>Sign in to view the message.</>}>\n * <>This is the protected content.</>\n * </Protected>\n * );\n * }\n * ```\n *\n * @example With Groups\n *\n * ```tsx title=\"With Groups\"\n * \"use client\";\n *\n * import { Protected } from \"@monocloud/auth-nextjs/components/client\";\n *\n * export default function Home() {\n * return (\n * <Protected\n * groups={[\"admin\"]}\n * onGroupAccessDenied={(user) => <>User {user.email} is not allowed to access admin content.</>}\n * >\n * <>Signed in as admin</>\n * </Protected>\n * );\n * }\n * ```\n *\n * @example Requiring all groups\n *\n * ```tsx title=\"Requiring all groups\"\n * \"use client\";\n *\n * import { Protected } from \"@monocloud/auth-nextjs/components/client\";\n *\n * export default function Home() {\n * return (\n * <Protected\n * groups={[\"admin\", \"billing\"]}\n * matchAllGroups\n * onGroupAccessDenied={(user) => <>User {user.email} is not allowed to access billing content.</>}\n * >\n * <>Sensitive settings</>\n * </Protected>\n * );\n * }\n * ```\n *\n * @param props - Props for customizing the Protected component.\n * @returns The children if authorized, the `fallback` or `onGroupAccessDenied` content if unauthenticated or unauthorized, or `null` while loading.\n *\n * @category Components\n */\nexport const Protected = ({\n children,\n groups,\n groupsClaim,\n matchAllGroups = false,\n fallback = null,\n onGroupAccessDenied = (): React.ReactNode => <></>,\n}: ProtectedComponentProps): React.ReactNode | null => {\n const { isLoading, error, isAuthenticated, user } = useAuth();\n\n if (isLoading) {\n return null;\n }\n\n if (error || !isAuthenticated || !user) {\n if (fallback) {\n return fallback;\n }\n\n return null;\n }\n\n return (\n <>\n {!groups ||\n isUserInGroup(\n user,\n groups,\n groupsClaim ?? process.env.NEXT_PUBLIC_MONOCLOUD_AUTH_GROUPS_CLAIM,\n matchAllGroups\n )\n ? children\n : onGroupAccessDenied(user)}\n </>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiHA,MAAa,aAAa,EACxB,UACA,QACA,aACA,iBAAiB,OACjB,WAAW,MACX,4BAA6C,yDAAK,OACG;CACrD,MAAM,EAAE,WAAW,OAAO,iBAAiB,SAAS,SAAS;AAE7D,KAAI,UACF,QAAO;AAGT,KAAI,SAAS,CAAC,mBAAmB,CAAC,MAAM;AACtC,MAAI,SACF,QAAO;AAGT,SAAO;;AAGT,QACE,0DACG,CAAC,UACF,cACE,MACA,QACA,eAAe,QAAQ,IAAI,yCAC3B,eACD,GACG,WACA,oBAAoB,KAAK,CAC5B"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
4
|
+
const require_protect_client_page = require('../../client/protect-client-page.cjs');
|
|
5
|
+
let react = require("react");
|
|
6
|
+
|
|
7
|
+
//#region src/components/client/redirect-to-signin.tsx
|
|
8
|
+
/**
|
|
9
|
+
* `<RedirectToSignIn>` is a **client-side component** that immediately redirects the user to the MonoCloud sign-in page when it is rendered.
|
|
10
|
+
*
|
|
11
|
+
* It does not render any UI.
|
|
12
|
+
*
|
|
13
|
+
* > This component must be used inside a Client Component (`"use client"`).
|
|
14
|
+
*
|
|
15
|
+
* @example Basic Usage
|
|
16
|
+
*
|
|
17
|
+
* ```tsx title="Basic Usage"
|
|
18
|
+
* "use client";
|
|
19
|
+
*
|
|
20
|
+
* import { useAuth } from "@monocloud/auth-nextjs/client";
|
|
21
|
+
* import { RedirectToSignIn } from "@monocloud/auth-nextjs/components/client";
|
|
22
|
+
*
|
|
23
|
+
* export default function Home() {
|
|
24
|
+
* const { isLoading, isAuthenticated } = useAuth();
|
|
25
|
+
*
|
|
26
|
+
* if (!isLoading && !isAuthenticated) {
|
|
27
|
+
* return <RedirectToSignIn />;
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* return <>You are signed in</>;
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example With Options
|
|
35
|
+
*
|
|
36
|
+
* You can customize the authorization request by passing in props.
|
|
37
|
+
*
|
|
38
|
+
* ```tsx title="With options"
|
|
39
|
+
* "use client";
|
|
40
|
+
*
|
|
41
|
+
* import { useAuth } from "@monocloud/auth-nextjs/client";
|
|
42
|
+
* import { RedirectToSignIn } from "@monocloud/auth-nextjs/components/client";
|
|
43
|
+
*
|
|
44
|
+
* export default function Home() {
|
|
45
|
+
* const { isLoading, isAuthenticated } = useAuth();
|
|
46
|
+
*
|
|
47
|
+
* if (!isLoading && !isAuthenticated) {
|
|
48
|
+
* return (
|
|
49
|
+
* <RedirectToSignIn
|
|
50
|
+
* returnUrl="/dashboard"
|
|
51
|
+
* loginHint="user@example.com"
|
|
52
|
+
* />
|
|
53
|
+
* );
|
|
54
|
+
* }
|
|
55
|
+
*
|
|
56
|
+
* return <>You are signed in</>;
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @param props - The props for customizing RedirectToSignIn.
|
|
61
|
+
* @returns
|
|
62
|
+
*
|
|
63
|
+
* @category Components
|
|
64
|
+
*/
|
|
65
|
+
const RedirectToSignIn = ({ returnUrl, ...authParams }) => {
|
|
66
|
+
(0, react.useEffect)(() => {
|
|
67
|
+
require_protect_client_page.redirectToSignIn({
|
|
68
|
+
returnUrl,
|
|
69
|
+
...authParams
|
|
70
|
+
});
|
|
71
|
+
}, [authParams, returnUrl]);
|
|
72
|
+
return null;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
exports.RedirectToSignIn = RedirectToSignIn;
|
|
77
|
+
//# sourceMappingURL=redirect-to-signin.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirect-to-signin.cjs","names":[],"sources":["../../../src/components/client/redirect-to-signin.tsx"],"sourcesContent":["'use client';\n\nimport { useEffect } from 'react';\nimport { redirectToSignIn } from '../../client/protect-client-page';\nimport { ExtraAuthParams } from '../../types';\n\n/**\n * Props for the `<RedirectToSignIn />` Component\n *\n * @category Types\n */\nexport interface RedirectToSignInProps extends ExtraAuthParams {\n /**\n * The URL to return to after successful authentication. If not provided, the current URL is used.\n */\n returnUrl?: string;\n}\n\n/**\n * `<RedirectToSignIn>` is a **client-side component** that immediately redirects the user to the MonoCloud sign-in page when it is rendered.\n *\n * It does not render any UI.\n *\n * > This component must be used inside a Client Component (`\"use client\"`).\n *\n * @example Basic Usage\n *\n * ```tsx title=\"Basic Usage\"\n * \"use client\";\n *\n * import { useAuth } from \"@monocloud/auth-nextjs/client\";\n * import { RedirectToSignIn } from \"@monocloud/auth-nextjs/components/client\";\n *\n * export default function Home() {\n * const { isLoading, isAuthenticated } = useAuth();\n *\n * if (!isLoading && !isAuthenticated) {\n * return <RedirectToSignIn />;\n * }\n *\n * return <>You are signed in</>;\n * }\n * ```\n *\n * @example With Options\n *\n * You can customize the authorization request by passing in props.\n *\n * ```tsx title=\"With options\"\n * \"use client\";\n *\n * import { useAuth } from \"@monocloud/auth-nextjs/client\";\n * import { RedirectToSignIn } from \"@monocloud/auth-nextjs/components/client\";\n *\n * export default function Home() {\n * const { isLoading, isAuthenticated } = useAuth();\n *\n * if (!isLoading && !isAuthenticated) {\n * return (\n * <RedirectToSignIn\n * returnUrl=\"/dashboard\"\n * loginHint=\"user@example.com\"\n * />\n * );\n * }\n *\n * return <>You are signed in</>;\n * }\n * ```\n *\n * @param props - The props for customizing RedirectToSignIn.\n * @returns\n *\n * @category Components\n */\nexport const RedirectToSignIn = ({\n returnUrl,\n ...authParams\n}: RedirectToSignInProps): null => {\n useEffect(() => {\n redirectToSignIn({ returnUrl, ...authParams });\n }, [authParams, returnUrl]);\n return null;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,MAAa,oBAAoB,EAC/B,WACA,GAAG,iBAC8B;AACjC,4BAAgB;AACd,+CAAiB;GAAE;GAAW,GAAG;GAAY,CAAC;IAC7C,CAAC,YAAY,UAAU,CAAC;AAC3B,QAAO"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ExtraAuthParams } from "../../types.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/components/client/redirect-to-signin.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Props for the `<RedirectToSignIn />` Component
|
|
6
|
+
*
|
|
7
|
+
* @category Types
|
|
8
|
+
*/
|
|
9
|
+
interface RedirectToSignInProps extends ExtraAuthParams {
|
|
10
|
+
/**
|
|
11
|
+
* The URL to return to after successful authentication. If not provided, the current URL is used.
|
|
12
|
+
*/
|
|
13
|
+
returnUrl?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* `<RedirectToSignIn>` is a **client-side component** that immediately redirects the user to the MonoCloud sign-in page when it is rendered.
|
|
17
|
+
*
|
|
18
|
+
* It does not render any UI.
|
|
19
|
+
*
|
|
20
|
+
* > This component must be used inside a Client Component (`"use client"`).
|
|
21
|
+
*
|
|
22
|
+
* @example Basic Usage
|
|
23
|
+
*
|
|
24
|
+
* ```tsx title="Basic Usage"
|
|
25
|
+
* "use client";
|
|
26
|
+
*
|
|
27
|
+
* import { useAuth } from "@monocloud/auth-nextjs/client";
|
|
28
|
+
* import { RedirectToSignIn } from "@monocloud/auth-nextjs/components/client";
|
|
29
|
+
*
|
|
30
|
+
* export default function Home() {
|
|
31
|
+
* const { isLoading, isAuthenticated } = useAuth();
|
|
32
|
+
*
|
|
33
|
+
* if (!isLoading && !isAuthenticated) {
|
|
34
|
+
* return <RedirectToSignIn />;
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* return <>You are signed in</>;
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example With Options
|
|
42
|
+
*
|
|
43
|
+
* You can customize the authorization request by passing in props.
|
|
44
|
+
*
|
|
45
|
+
* ```tsx title="With options"
|
|
46
|
+
* "use client";
|
|
47
|
+
*
|
|
48
|
+
* import { useAuth } from "@monocloud/auth-nextjs/client";
|
|
49
|
+
* import { RedirectToSignIn } from "@monocloud/auth-nextjs/components/client";
|
|
50
|
+
*
|
|
51
|
+
* export default function Home() {
|
|
52
|
+
* const { isLoading, isAuthenticated } = useAuth();
|
|
53
|
+
*
|
|
54
|
+
* if (!isLoading && !isAuthenticated) {
|
|
55
|
+
* return (
|
|
56
|
+
* <RedirectToSignIn
|
|
57
|
+
* returnUrl="/dashboard"
|
|
58
|
+
* loginHint="user@example.com"
|
|
59
|
+
* />
|
|
60
|
+
* );
|
|
61
|
+
* }
|
|
62
|
+
*
|
|
63
|
+
* return <>You are signed in</>;
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @param props - The props for customizing RedirectToSignIn.
|
|
68
|
+
* @returns
|
|
69
|
+
*
|
|
70
|
+
* @category Components
|
|
71
|
+
*/
|
|
72
|
+
declare const RedirectToSignIn: ({
|
|
73
|
+
returnUrl,
|
|
74
|
+
...authParams
|
|
75
|
+
}: RedirectToSignInProps) => null;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { RedirectToSignIn, RedirectToSignInProps };
|
|
78
|
+
//# sourceMappingURL=redirect-to-signin.d.mts.map
|