@krak-stack/auth 0.1.61 → 0.1.63
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 +52 -56
- package/dist/access.d.ts +0 -6
- package/dist/access.js +1 -7
- package/dist/components/api-key-edit-form.js +7 -9
- package/dist/components/auth-forms.d.ts +1 -0
- package/dist/components/auth-forms.js +97 -42
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +1 -1
- package/dist/components/project-access-matrix.d.ts +0 -2
- package/dist/components/project-access-matrix.js +0 -7
- package/dist/components/user-button.d.ts +3 -2
- package/dist/components/user-button.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/server/actor.d.ts +2 -16
- package/dist/server/actor.js +0 -16
- package/dist/server/middleware.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,86 +1,82 @@
|
|
|
1
1
|
# @krak-stack/auth
|
|
2
2
|
|
|
3
|
-
Effect
|
|
3
|
+
Typed Effect contracts, server authentication middleware, project authorization primitives, and React authentication components for Krakstack Auth.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
|
-
```
|
|
7
|
+
```bash
|
|
8
8
|
bun add @krak-stack/auth effect
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Choose a narrow package subpath for the runtime boundary:
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
| Entry point | Purpose |
|
|
14
|
+
| -------------------------------- | --------------------------------------------------------------------- |
|
|
15
|
+
| `@krak-stack/auth/server` | Proxy, `AuthMiddleware`, `AuthService`, `ActorRequired`, and policies |
|
|
16
|
+
| `@krak-stack/auth/components` | React provider, forms, account controls, and UI permission helpers |
|
|
17
|
+
| `@krak-stack/auth/access` | Typed project access definitions |
|
|
18
|
+
| `@krak-stack/auth/access/matrix` | Generated permission matrix |
|
|
19
|
+
| `@krak-stack/auth/api` | Combined Effect HttpApi contracts |
|
|
20
|
+
| `@krak-stack/auth/schema` | Shared schemas |
|
|
21
|
+
| `@krak-stack/auth/admin` | Administrative API contract |
|
|
22
|
+
| `@krak-stack/auth/extra` | Browser-facing extra API contract |
|
|
15
23
|
|
|
16
|
-
|
|
24
|
+
The complete export map is defined in `package.json` and documented at [auth.krakstack.net/en/docs/sdk](https://auth.krakstack.net/en/docs/sdk).
|
|
17
25
|
|
|
18
|
-
|
|
26
|
+
## Server Configuration
|
|
19
27
|
|
|
20
|
-
|
|
28
|
+
Server clients use:
|
|
21
29
|
|
|
22
|
-
|
|
30
|
+
```env
|
|
31
|
+
KRAKSTACK_AUTH_URL=https://auth.example.com
|
|
32
|
+
KRAKSTACK_AUTH_SERVICE_API_KEY=server_only_secret
|
|
33
|
+
```
|
|
23
34
|
|
|
24
|
-
|
|
25
|
-
- `server.getUser({ params: { id } })` - returns one user by ID.
|
|
35
|
+
`AuthClientConfig` accepts explicit `baseUrl` and redacted `apiKey` overrides. Never expose the service key through a `VITE_*` variable.
|
|
26
36
|
|
|
27
|
-
|
|
37
|
+
```ts
|
|
38
|
+
import { AuthService } from "@krak-stack/auth/server";
|
|
39
|
+
import { Effect } from "effect";
|
|
28
40
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
const program = Effect.gen(function* () {
|
|
42
|
+
const auth = yield* AuthService;
|
|
43
|
+
return yield* auth.requireUserOrganization();
|
|
44
|
+
});
|
|
45
|
+
```
|
|
34
46
|
|
|
35
|
-
|
|
47
|
+
Use `AuthMiddleware.layer()` to provide request headers and configuration in an Effect HttpApi application. See the [middleware guide](https://auth.krakstack.net/en/docs/middleware).
|
|
36
48
|
|
|
37
|
-
|
|
38
|
-
- `server.listOrganizationMembers({ params: { organizationId } })` - returns organization members with user contact details.
|
|
49
|
+
## React Components
|
|
39
50
|
|
|
40
|
-
|
|
41
|
-
import { Effect } from "effect";
|
|
42
|
-
import { AuthClient } from "@krak-stack/auth";
|
|
43
|
-
|
|
44
|
-
const users = await Effect.runPromise(
|
|
45
|
-
Effect.gen(function* () {
|
|
46
|
-
const auth = yield* AuthClient;
|
|
47
|
-
return yield* auth.server.listUsersByIds({
|
|
48
|
-
query: { ids: "user_1,user_2" },
|
|
49
|
-
});
|
|
50
|
-
}).pipe(Effect.provide(AuthClient.layer)),
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
const organizations = await Effect.runPromise(
|
|
54
|
-
Effect.gen(function* () {
|
|
55
|
-
const auth = yield* AuthClient;
|
|
56
|
-
return yield* auth.server.listOrganizations({
|
|
57
|
-
query: { userId: "user_1" },
|
|
58
|
-
});
|
|
59
|
-
}).pipe(Effect.provide(AuthClient.layer)),
|
|
60
|
-
);
|
|
61
|
-
```
|
|
51
|
+
The current emitted component bundle expects Krakstack/shadcn UI aliases and additional consumer runtime packages. Validate the packed package in the target application before adopting the UI surface. The server-only entry points have a smaller integration boundary.
|
|
62
52
|
|
|
63
|
-
|
|
53
|
+
When components are configured, register their Tailwind source:
|
|
64
54
|
|
|
65
|
-
|
|
55
|
+
```css
|
|
56
|
+
@import "tailwindcss";
|
|
57
|
+
@import "@krak-stack/auth/tailwind.css";
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`UserButton` accepts `menuActions` for app-owned menu items such as dashboard or workspace links:
|
|
66
61
|
|
|
67
62
|
```tsx
|
|
68
|
-
import {
|
|
63
|
+
import { UserButton } from "@krak-stack/auth";
|
|
69
64
|
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
|
70
65
|
|
|
71
|
-
<
|
|
72
|
-
allowedOrganizationIds={["organization-id"]}
|
|
73
|
-
features={{
|
|
74
|
-
organizationCreation: false,
|
|
75
|
-
organizationSwitching: false,
|
|
76
|
-
userInvitations: false,
|
|
77
|
-
}}
|
|
66
|
+
<UserButton
|
|
78
67
|
menuActions={
|
|
79
|
-
<DropdownMenuItem render={<a href="/
|
|
68
|
+
<DropdownMenuItem render={<a href="/dashboard" />}>
|
|
80
69
|
Dashboard
|
|
81
70
|
</DropdownMenuItem>
|
|
82
71
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
<UserButton signOutRedirect="/" side="bottom" />
|
|
72
|
+
signOutRedirect="/"
|
|
73
|
+
/>;
|
|
86
74
|
```
|
|
75
|
+
|
|
76
|
+
See [React components and CSS](https://auth.krakstack.net/en/docs/components) for the provider and component requirements.
|
|
77
|
+
|
|
78
|
+
## Authorization
|
|
79
|
+
|
|
80
|
+
Define project permissions with `defineProjectAccess`, resolve actors with `ActorRequired`, and enforce backend policies with `withPolicy`. Frontend permission helpers control presentation only.
|
|
81
|
+
|
|
82
|
+
See the [RBAC guide](https://auth.krakstack.net/en/docs/rbac).
|
package/dist/access.d.ts
CHANGED
|
@@ -15,9 +15,6 @@ export type ApiKeyOwner = {
|
|
|
15
15
|
} | {
|
|
16
16
|
readonly type: "organization";
|
|
17
17
|
readonly organizationId: string;
|
|
18
|
-
} | {
|
|
19
|
-
readonly type: "service";
|
|
20
|
-
readonly serviceId: string;
|
|
21
18
|
};
|
|
22
19
|
export type ApiKeyActor = {
|
|
23
20
|
readonly type: "apiKey";
|
|
@@ -51,7 +48,6 @@ export type ProjectAccessDefinition<Project extends string = string, Action exte
|
|
|
51
48
|
readonly apiKeys: {
|
|
52
49
|
readonly user: ReadonlyArray<Action>;
|
|
53
50
|
readonly organization: ReadonlyArray<Action>;
|
|
54
|
-
readonly service: ReadonlyArray<Action>;
|
|
55
51
|
};
|
|
56
52
|
readonly qualify: (action: Action) => ProjectPermission<Project, Action>;
|
|
57
53
|
readonly permission: (action: Action) => Policy;
|
|
@@ -66,7 +62,6 @@ export type ProjectAccessDefinition<Project extends string = string, Action exte
|
|
|
66
62
|
readonly apiKeyPermissions: {
|
|
67
63
|
readonly user: ApiKeyPermissionGrant;
|
|
68
64
|
readonly organization: ApiKeyPermissionGrant;
|
|
69
|
-
readonly service: ApiKeyPermissionGrant;
|
|
70
65
|
};
|
|
71
66
|
readonly actorForUser: (input: {
|
|
72
67
|
readonly userId: string;
|
|
@@ -107,7 +102,6 @@ export type ProjectAccessConfig<Project extends string, Permissions extends Read
|
|
|
107
102
|
readonly apiKeys?: {
|
|
108
103
|
readonly user?: ReadonlyArray<Permissions[number]>;
|
|
109
104
|
readonly organization?: ReadonlyArray<Permissions[number]>;
|
|
110
|
-
readonly service?: ReadonlyArray<Permissions[number]>;
|
|
111
105
|
};
|
|
112
106
|
};
|
|
113
107
|
export declare const defineProjectAccess: <const Project extends string, const Permissions extends ReadonlyArray<string>>(config: ProjectAccessConfig<Project, Permissions>) => ProjectAccessDefinition<Project, Permissions[number]>;
|
package/dist/access.js
CHANGED
|
@@ -54,7 +54,6 @@ export const defineProjectAccess = (config) => {
|
|
|
54
54
|
});
|
|
55
55
|
const userApiKeyActions = (config.apiKeys?.user ?? []).filter((action) => allowedActions.has(action));
|
|
56
56
|
const organizationApiKeyActions = (config.apiKeys?.organization ?? []).filter((action) => allowedActions.has(action));
|
|
57
|
-
const serviceApiKeyActions = (config.apiKeys?.service ?? []).filter((action) => allowedActions.has(action));
|
|
58
57
|
const actorForUser = (input) => {
|
|
59
58
|
const roles = roleList(input.roles);
|
|
60
59
|
return {
|
|
@@ -76,18 +75,15 @@ export const defineProjectAccess = (config) => {
|
|
|
76
75
|
return intersection(intersection(permissionsForRoles(input.owner.roles), permissionsForActions(userApiKeyActions)), keyPermissions);
|
|
77
76
|
case "organization":
|
|
78
77
|
return intersection(permissionsForActions(organizationApiKeyActions), keyPermissions);
|
|
79
|
-
case "service":
|
|
80
|
-
return intersection(permissionsForActions(serviceApiKeyActions), keyPermissions);
|
|
81
78
|
}
|
|
82
79
|
})();
|
|
83
|
-
const organizationId = input.owner.type === "service" ? null : input.owner.organizationId;
|
|
84
80
|
return {
|
|
85
81
|
actor: {
|
|
86
82
|
type: "apiKey",
|
|
87
83
|
apiKeyId: input.apiKeyId,
|
|
88
84
|
owner: input.owner,
|
|
89
85
|
},
|
|
90
|
-
organizationId,
|
|
86
|
+
organizationId: input.owner.organizationId,
|
|
91
87
|
permissions,
|
|
92
88
|
};
|
|
93
89
|
};
|
|
@@ -98,7 +94,6 @@ export const defineProjectAccess = (config) => {
|
|
|
98
94
|
apiKeys: {
|
|
99
95
|
user: userApiKeyActions,
|
|
100
96
|
organization: organizationApiKeyActions,
|
|
101
|
-
service: serviceApiKeyActions,
|
|
102
97
|
},
|
|
103
98
|
qualify,
|
|
104
99
|
permission: (action) => permission(qualify(action)),
|
|
@@ -110,7 +105,6 @@ export const defineProjectAccess = (config) => {
|
|
|
110
105
|
apiKeyPermissions: {
|
|
111
106
|
user: encodeGrant(userApiKeyActions),
|
|
112
107
|
organization: encodeGrant(organizationApiKeyActions),
|
|
113
|
-
service: encodeGrant(serviceApiKeyActions),
|
|
114
108
|
},
|
|
115
109
|
actorForUser,
|
|
116
110
|
actorForApiKey,
|
|
@@ -11,7 +11,9 @@ import { ExtraApiKeyPermissions } from "../extra/schema";
|
|
|
11
11
|
const editApiKeyFormBuilder = FormBuilder.empty
|
|
12
12
|
.addField("name", Schema.NonEmptyString)
|
|
13
13
|
.addField("enabled", Schema.Boolean)
|
|
14
|
-
.addField("referrers", Schema.String)
|
|
14
|
+
.addField("referrers", Schema.String)
|
|
15
|
+
.addField("permissions", Schema.Record(Schema.String, Schema.Boolean));
|
|
16
|
+
const ApiKeyPermissionsField = ({ field, props }) => (_jsx(ApiKeyPermissions, { description: props.description, idPrefix: props.idPrefix, permissions: props.permissions, labels: props.labels, selected: field.value, title: props.title, onChange: (id, checked) => field.onChange({ ...field.value, [id]: checked }) }));
|
|
15
17
|
export const ApiKeyEditForm = ({ configId, keyData, messages, permissions, permissionLabels, onSaved, }) => {
|
|
16
18
|
const permissionOptions = Object.entries(permissions).flatMap(([project, actions]) => actions.map((action) => ({
|
|
17
19
|
id: `${project}:${action}`,
|
|
@@ -24,11 +26,8 @@ export const ApiKeyEditForm = ({ configId, keyData, messages, permissions, permi
|
|
|
24
26
|
option.id,
|
|
25
27
|
currentGrant[option.project]?.includes(option.action) ?? false,
|
|
26
28
|
]));
|
|
27
|
-
const [selectedPermissions, setSelectedPermissions] = useState(initialSelectedPermissions);
|
|
28
|
-
const selectedPermissionsRef = useRef(selectedPermissions);
|
|
29
29
|
const permissionOptionsRef = useRef(permissionOptions);
|
|
30
30
|
const permissionsRef = useRef(permissions);
|
|
31
|
-
selectedPermissionsRef.current = selectedPermissions;
|
|
32
31
|
permissionOptionsRef.current = permissionOptions;
|
|
33
32
|
permissionsRef.current = permissions;
|
|
34
33
|
const [form] = useState(() => FormReact.make(editApiKeyFormBuilder, {
|
|
@@ -36,6 +35,7 @@ export const ApiKeyEditForm = ({ configId, keyData, messages, permissions, permi
|
|
|
36
35
|
name: TextField,
|
|
37
36
|
enabled: CheckboxField,
|
|
38
37
|
referrers: TextAreaField,
|
|
38
|
+
permissions: ApiKeyPermissionsField,
|
|
39
39
|
},
|
|
40
40
|
mode: { validation: "onSubmit" },
|
|
41
41
|
onSubmit: (_, { decoded }) => Effect.tryPromise({
|
|
@@ -46,7 +46,7 @@ export const ApiKeyEditForm = ({ configId, keyData, messages, permissions, permi
|
|
|
46
46
|
selectedGrant[project] = [];
|
|
47
47
|
}
|
|
48
48
|
for (const option of permissionOptionsRef.current) {
|
|
49
|
-
if (!
|
|
49
|
+
if (!decoded.permissions[option.id])
|
|
50
50
|
continue;
|
|
51
51
|
selectedGrant[option.project] = [
|
|
52
52
|
...(selectedGrant[option.project] ?? []),
|
|
@@ -72,12 +72,10 @@ export const ApiKeyEditForm = ({ configId, keyData, messages, permissions, permi
|
|
|
72
72
|
name: keyData.name ?? "",
|
|
73
73
|
enabled: keyData.enabled,
|
|
74
74
|
referrers: apiKeyReferrers(keyData.metadata).join("\n"),
|
|
75
|
+
permissions: initialSelectedPermissions,
|
|
75
76
|
}, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
|
|
76
77
|
event.preventDefault();
|
|
77
78
|
event.stopPropagation();
|
|
78
79
|
submit();
|
|
79
|
-
}, children: [_jsx(form.name, { label: messages.name, required: true }), _jsx(form.enabled, { label: messages.enabled }), _jsx(form.referrers, { label: messages.referrers, description: messages.referrersDescription, placeholder: messages.referrersPlaceholder, rows: 3 }), _jsx(
|
|
80
|
-
...current,
|
|
81
|
-
[id]: checked,
|
|
82
|
-
})) }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form })] }) }) }));
|
|
80
|
+
}, children: [_jsx(form.name, { label: messages.name, required: true }), _jsx(form.enabled, { label: messages.enabled }), _jsx(form.referrers, { label: messages.referrers, description: messages.referrersDescription, placeholder: messages.referrersPlaceholder, rows: 3 }), _jsx(form.permissions, { description: messages.permissionsDescription, idPrefix: "edit", permissions: permissions, labels: permissionLabels, title: messages.permissions }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form })] }) }) }));
|
|
83
81
|
};
|
|
@@ -8,6 +8,7 @@ type AuthFormProps = {
|
|
|
8
8
|
export declare function Signin(props: AuthFormProps): import("react").JSX.Element;
|
|
9
9
|
export declare function Signup(props: AuthFormProps): import("react").JSX.Element;
|
|
10
10
|
export declare function VerifyEmail(props: AuthFormProps): import("react").JSX.Element;
|
|
11
|
+
export declare function ForgotPassword(props: AuthFormProps): import("react").JSX.Element;
|
|
11
12
|
export declare function ResetPassword(props: AuthFormProps): import("react").JSX.Element;
|
|
12
13
|
export declare function TwoFactor(props: AuthFormProps): import("react").JSX.Element;
|
|
13
14
|
export {};
|
|
@@ -28,6 +28,7 @@ const signupFormBuilder = FormBuilder.empty
|
|
|
28
28
|
const verifyEmailFormBuilder = FormBuilder.empty
|
|
29
29
|
.addField("email", Schema.String)
|
|
30
30
|
.addField("otp", Schema.String);
|
|
31
|
+
const forgotPasswordFormBuilder = FormBuilder.empty.addField("email", Schema.String);
|
|
31
32
|
const resetPasswordFormBuilder = FormBuilder.empty.addField("password", Schema.String);
|
|
32
33
|
const twoFactorFormBuilder = FormBuilder.empty
|
|
33
34
|
.addField("code", Schema.String)
|
|
@@ -42,6 +43,11 @@ const defaultMessages = {
|
|
|
42
43
|
field_name: "Name",
|
|
43
44
|
field_password: "Password",
|
|
44
45
|
forgot_password_back_to_sign_in: "Back to sign in",
|
|
46
|
+
forgot_password_description: "Enter your email and we will send a reset link if an account exists.",
|
|
47
|
+
forgot_password_error: "Unable to send password reset email.",
|
|
48
|
+
forgot_password_submit: "Send reset link",
|
|
49
|
+
forgot_password_success: "If an account exists for that email, a reset link has been sent.",
|
|
50
|
+
forgot_password_title: "Reset password",
|
|
45
51
|
oauth_client_no_auth_methods: "No authentication methods are enabled for this application.",
|
|
46
52
|
reset_password_description: "Enter a new password for your account.",
|
|
47
53
|
reset_password_error: "Unable to reset password.",
|
|
@@ -100,6 +106,11 @@ const defaultMessages = {
|
|
|
100
106
|
field_name: "Nom",
|
|
101
107
|
field_password: "Mot de passe",
|
|
102
108
|
forgot_password_back_to_sign_in: "Retour à la connexion",
|
|
109
|
+
forgot_password_description: "Saisissez votre courriel et nous enverrons un lien de réinitialisation si un compte existe.",
|
|
110
|
+
forgot_password_error: "Impossible d'envoyer le courriel de réinitialisation.",
|
|
111
|
+
forgot_password_submit: "Envoyer le lien",
|
|
112
|
+
forgot_password_success: "Si un compte existe pour ce courriel, un lien de réinitialisation a été envoyé.",
|
|
113
|
+
forgot_password_title: "Réinitialiser le mot de passe",
|
|
103
114
|
oauth_client_no_auth_methods: "Aucune méthode d'authentification n'est activée pour cette application.",
|
|
104
115
|
reset_password_description: "Saisissez un nouveau mot de passe pour votre compte.",
|
|
105
116
|
reset_password_error: "Impossible de réinitialiser le mot de passe.",
|
|
@@ -261,23 +272,6 @@ export function Signin(props) {
|
|
|
261
272
|
setOtpSentTo(email);
|
|
262
273
|
setEmailOtpResendAvailableAt(Date.now() + EMAIL_OTP_RESEND_COOLDOWN_SECONDS * 1000);
|
|
263
274
|
};
|
|
264
|
-
if (action.type === "social") {
|
|
265
|
-
const result = await authClient.signIn.social({
|
|
266
|
-
provider: "google",
|
|
267
|
-
callbackURL: socialRedirectTarget,
|
|
268
|
-
errorCallbackURL: "/sign-in",
|
|
269
|
-
...(oauthQuery
|
|
270
|
-
? { additionalData: { query: oauthQuery } }
|
|
271
|
-
: {}),
|
|
272
|
-
...(oauthQuery ? { oauth_query: oauthQuery } : {}),
|
|
273
|
-
});
|
|
274
|
-
if (result.error) {
|
|
275
|
-
throw new Error(result.error.message ?? m.sign_in_error);
|
|
276
|
-
}
|
|
277
|
-
if (result.data?.url)
|
|
278
|
-
onNavigate(result.data.url);
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
275
|
if (action.type === "sendEmailOtp") {
|
|
282
276
|
await sendEmailOtp();
|
|
283
277
|
return;
|
|
@@ -333,6 +327,25 @@ export function Signin(props) {
|
|
|
333
327
|
}));
|
|
334
328
|
const submit = useAtomSet(form.submit);
|
|
335
329
|
const submitResult = useAtomValue(form.submit);
|
|
330
|
+
const [socialSignIn] = useState(() => Atom.fn((provider) => Effect.tryPromise({
|
|
331
|
+
try: async () => {
|
|
332
|
+
const result = await authClient.signIn.social({
|
|
333
|
+
provider,
|
|
334
|
+
callbackURL: socialRedirectTarget,
|
|
335
|
+
errorCallbackURL: "/sign-in",
|
|
336
|
+
...(oauthQuery ? { additionalData: { query: oauthQuery } } : {}),
|
|
337
|
+
...(oauthQuery ? { oauth_query: oauthQuery } : {}),
|
|
338
|
+
});
|
|
339
|
+
if (result.error) {
|
|
340
|
+
throw new Error(result.error.message ?? m.sign_in_error);
|
|
341
|
+
}
|
|
342
|
+
if (result.data?.url)
|
|
343
|
+
onNavigate(result.data.url);
|
|
344
|
+
},
|
|
345
|
+
catch: (cause) => cause instanceof Error ? cause : new Error(m.sign_in_error),
|
|
346
|
+
})));
|
|
347
|
+
const startSocialSignIn = useAtomSet(socialSignIn);
|
|
348
|
+
const socialSignInResult = useAtomValue(socialSignIn);
|
|
336
349
|
const formValues = Option.getOrElse(useAtomValue(form.values), () => ({
|
|
337
350
|
email: "",
|
|
338
351
|
password: "",
|
|
@@ -367,7 +380,7 @@ export function Signin(props) {
|
|
|
367
380
|
setOtp("");
|
|
368
381
|
submit({ type: "sendEmailOtp" });
|
|
369
382
|
};
|
|
370
|
-
const signInWithGoogle = () =>
|
|
383
|
+
const signInWithGoogle = () => startSocialSignIn("google");
|
|
371
384
|
return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.auth_sign_in }), _jsx(CardDescription, { children: !emailSubmitted ? (m.sign_in_description) : (_jsxs(_Fragment, { children: [text(m.sign_in_email_as, { email: formValues.email }), " ", _jsx(Button, { type: "button", variant: "link", className: "h-auto px-0", onClick: resetEmailStep, children: m.sign_in_change_email })] })) })] }), _jsxs(CardContent, { children: [hasPrimaryAuth ? (_jsx(form.Initialize, { defaultValues: { email: "", password: "", otp: "" }, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
|
|
372
385
|
event.preventDefault();
|
|
373
386
|
event.stopPropagation();
|
|
@@ -377,7 +390,12 @@ export function Signin(props) {
|
|
|
377
390
|
method: selectedAuthMethod,
|
|
378
391
|
otpSent: Boolean(otpSentTo),
|
|
379
392
|
});
|
|
380
|
-
}, children: [!emailSubmitted ? (_jsx(form.email, { label: m.field_email, type: "email", autoComplete: "email",
|
|
393
|
+
}, children: [!emailSubmitted ? (_jsx(form.email, { label: m.field_email, type: "email", autoComplete: "email", onKeyDown: (event) => {
|
|
394
|
+
if (event.key !== "Enter")
|
|
395
|
+
return;
|
|
396
|
+
event.preventDefault();
|
|
397
|
+
event.currentTarget.form?.requestSubmit();
|
|
398
|
+
}, required: true })) : null, emailSubmitted && selectedAuthMethod === "password" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.password, { label: m.field_password, type: "password", autoComplete: "current-password", required: true }), _jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: [_jsx(Link, { className: authLinkClassName, to: "/reset-password", search: searchObject(searchString), children: m.sign_in_forgot_password }), canChangeAuthMethod ? (_jsxs(Button, { type: "button", variant: "link", className: "h-auto px-0", onClick: switchAuthMethod, children: [_jsx(Mail, {}), m.sign_in_use_email_otp] })) : null] })] })) : null, emailSubmitted && selectedAuthMethod === "emailOtp" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.otp, { label: m.sign_in_email_otp_code }), _jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: [otpSentTo ? (_jsx(Button, { type: "button", variant: "link", className: "h-auto px-0", disabled: emailOtpResendSeconds > 0, onClick: resendEmailOtp, children: emailOtpResendSeconds > 0
|
|
381
399
|
? text(m.sign_in_email_otp_resend_countdown, {
|
|
382
400
|
seconds: String(emailOtpResendSeconds),
|
|
383
401
|
})
|
|
@@ -385,7 +403,7 @@ export function Signin(props) {
|
|
|
385
403
|
? m.sign_in_continue
|
|
386
404
|
: selectedAuthMethod === "emailOtp"
|
|
387
405
|
? m.sign_in_email_otp_verify
|
|
388
|
-
: m.auth_sign_in] }) })] }) })) : null, options.google && !emailSubmitted ? (_jsxs("div", { className: "mt-4 flex flex-col gap-3", children: [hasPrimaryAuth ? (_jsx(Divider, { label: m.auth_or_continue_with })) : null, _jsxs(Button, { type: "button", variant: "outline", className: "w-full", disabled: submitResult.waiting, onClick: signInWithGoogle, children: [_jsx(GoogleLogo, {}), m.auth_continue_with_google] })] })) : null, !hasPrimaryAuth && !options.google ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.oauth_client_no_auth_methods })) : null, options.signUp ? (_jsx("p", { className: "text-muted-foreground mt-6 text-center text-sm", children: _jsxs(Link, { className: authLinkClassName, to: "/sign-up", search: searchObject(searchString), children: [m.sign_in_need_account, " ", m.auth_sign_up] }) })) : null] })] }));
|
|
406
|
+
: m.auth_sign_in] }) })] }) })) : null, options.google && !emailSubmitted ? (_jsxs("div", { className: "mt-4 flex flex-col gap-3", children: [hasPrimaryAuth ? (_jsx(Divider, { label: m.auth_or_continue_with })) : null, _jsxs(Button, { type: "button", variant: "outline", className: "w-full", disabled: submitResult.waiting, onClick: signInWithGoogle, children: [_jsx(GoogleLogo, {}), m.auth_continue_with_google] }), _jsx(SubmitError, { result: socialSignInResult })] })) : null, !hasPrimaryAuth && !options.google ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.oauth_client_no_auth_methods })) : null, options.signUp ? (_jsx("p", { className: "text-muted-foreground mt-6 text-center text-sm", children: _jsxs(Link, { className: authLinkClassName, to: "/sign-up", search: searchObject(searchString), children: [m.sign_in_need_account, " ", m.auth_sign_up] }) })) : null] })] }));
|
|
389
407
|
}
|
|
390
408
|
export function Signup(props) {
|
|
391
409
|
const { authClient, baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
|
|
@@ -409,21 +427,8 @@ export function Signup(props) {
|
|
|
409
427
|
const [form] = useState(() => FormReact.make(signupFormBuilder, {
|
|
410
428
|
fields: { name: TextField, email: TextField, password: TextField },
|
|
411
429
|
mode: { validation: "onSubmit" },
|
|
412
|
-
onSubmit: (
|
|
430
|
+
onSubmit: (_, { decoded: value }) => Effect.tryPromise({
|
|
413
431
|
try: async () => {
|
|
414
|
-
if (action === "social") {
|
|
415
|
-
const result = await authClient.signIn.social({
|
|
416
|
-
provider: "google",
|
|
417
|
-
callbackURL: redirectTarget,
|
|
418
|
-
errorCallbackURL: "/sign-up",
|
|
419
|
-
});
|
|
420
|
-
if (result.error) {
|
|
421
|
-
throw new Error(result.error.message ?? m.sign_up_error);
|
|
422
|
-
}
|
|
423
|
-
if (result.data?.url)
|
|
424
|
-
onNavigate(result.data.url);
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
432
|
if (!options.signUp) {
|
|
428
433
|
throw new Error(m.sign_up_disabled_description);
|
|
429
434
|
}
|
|
@@ -444,15 +449,32 @@ export function Signup(props) {
|
|
|
444
449
|
}));
|
|
445
450
|
const submit = useAtomSet(form.submit);
|
|
446
451
|
const submitResult = useAtomValue(form.submit);
|
|
447
|
-
const
|
|
452
|
+
const [socialSignUp] = useState(() => Atom.fn((provider) => Effect.tryPromise({
|
|
453
|
+
try: async () => {
|
|
454
|
+
const result = await authClient.signIn.social({
|
|
455
|
+
provider,
|
|
456
|
+
callbackURL: redirectTarget,
|
|
457
|
+
errorCallbackURL: "/sign-up",
|
|
458
|
+
});
|
|
459
|
+
if (result.error) {
|
|
460
|
+
throw new Error(result.error.message ?? m.sign_up_error);
|
|
461
|
+
}
|
|
462
|
+
if (result.data?.url)
|
|
463
|
+
onNavigate(result.data.url);
|
|
464
|
+
},
|
|
465
|
+
catch: (cause) => cause instanceof Error ? cause : new Error(m.sign_up_error),
|
|
466
|
+
})));
|
|
467
|
+
const startSocialSignUp = useAtomSet(socialSignUp);
|
|
468
|
+
const socialSignUpResult = useAtomValue(socialSignUp);
|
|
469
|
+
const signUpWithGoogle = () => startSocialSignUp("google");
|
|
448
470
|
if (!options.signUp) {
|
|
449
471
|
return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.sign_up_disabled_title }), _jsx(CardDescription, { children: m.sign_up_disabled_description })] }), _jsx(CardContent, { children: _jsx("p", { className: "text-muted-foreground text-center text-sm", children: _jsxs(Link, { className: authLinkClassName, to: "/sign-in", search: searchObject(searchString), children: [m.sign_up_have_account, " ", m.auth_sign_in] }) }) })] }));
|
|
450
472
|
}
|
|
451
473
|
return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.sign_up_title }), _jsx(CardDescription, { children: m.sign_up_description })] }), _jsxs(CardContent, { children: [_jsx(form.Initialize, { defaultValues: { name: "", email: "", password: "" }, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
|
|
452
474
|
event.preventDefault();
|
|
453
475
|
event.stopPropagation();
|
|
454
|
-
submit(
|
|
455
|
-
}, children: [options.signUpName ? (_jsx(form.name, { label: m.field_name, autoComplete: "name", required: true })) : null, _jsx(form.email, { label: m.field_email, type: "email", autoComplete: "email", required: true }), _jsx(form.password, { label: m.field_password, type: "password", autoComplete: "new-password", minLength: 8, required: true }), _jsx(SubmitError, { result: submitResult }), _jsxs(Button, { type: "submit", disabled: submitResult.waiting, children: [submitResult.waiting ? (_jsx(Loader2, { className: "animate-spin", "data-icon": "inline-start" })) : null, effectFormMessages().submit] })] }) }), options.google ? (_jsxs("div", { className: "mt-4 flex flex-col gap-3", children: [_jsx(Divider, { label: m.auth_or_continue_with }), _jsxs(Button, { type: "button", variant: "outline", className: "w-full", disabled: submitResult.waiting, onClick: signUpWithGoogle, children: [_jsx(GoogleLogo, {}), m.auth_continue_with_google] })] })) : null, _jsx("p", { className: "text-muted-foreground mt-6 text-center text-sm", children: _jsxs(Link, { className: authLinkClassName, to: "/sign-in", search: searchObject(searchString), children: [m.sign_up_have_account, " ", m.auth_sign_in] }) })] })] }));
|
|
476
|
+
submit();
|
|
477
|
+
}, children: [options.signUpName ? (_jsx(form.name, { label: m.field_name, autoComplete: "name", required: true })) : null, _jsx(form.email, { label: m.field_email, type: "email", autoComplete: "email", required: true }), _jsx(form.password, { label: m.field_password, type: "password", autoComplete: "new-password", minLength: 8, required: true }), _jsx(SubmitError, { result: submitResult }), _jsxs(Button, { type: "submit", disabled: submitResult.waiting, children: [submitResult.waiting ? (_jsx(Loader2, { className: "animate-spin", "data-icon": "inline-start" })) : null, effectFormMessages().submit] })] }) }), options.google ? (_jsxs("div", { className: "mt-4 flex flex-col gap-3", children: [_jsx(Divider, { label: m.auth_or_continue_with }), _jsxs(Button, { type: "button", variant: "outline", className: "w-full", disabled: submitResult.waiting, onClick: signUpWithGoogle, children: [_jsx(GoogleLogo, {}), m.auth_continue_with_google] }), _jsx(SubmitError, { result: socialSignUpResult })] })) : null, _jsx("p", { className: "text-muted-foreground mt-6 text-center text-sm", children: _jsxs(Link, { className: authLinkClassName, to: "/sign-in", search: searchObject(searchString), children: [m.sign_up_have_account, " ", m.auth_sign_in] }) })] })] }));
|
|
456
478
|
}
|
|
457
479
|
export function VerifyEmail(props) {
|
|
458
480
|
const { authClient, baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
|
|
@@ -508,21 +530,54 @@ export function VerifyEmail(props) {
|
|
|
508
530
|
submit("verify");
|
|
509
531
|
}, children: [_jsx(form.email, { label: m.field_email, type: "email", autoComplete: "email", required: true }), _jsx(form.otp, { label: m.verify_email_code }), _jsx(SubmitError, { result: submitResult }), resent ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.verify_email_resent })) : null, _jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [_jsxs(Button, { type: "submit", disabled: submitResult.waiting, children: [submitResult.waiting ? (_jsx(Loader2, { className: "animate-spin", "data-icon": "inline-start" })) : null, effectFormMessages().submit] }), _jsx(Button, { type: "button", variant: "ghost", disabled: submitResult.waiting, onClick: resendCode, children: m.verify_email_resend })] })] }) }), _jsx("p", { className: "text-muted-foreground mt-6 text-center text-sm", children: _jsx(Link, { className: authLinkClassName, to: "/sign-in", children: m.forgot_password_back_to_sign_in }) })] })] }));
|
|
510
532
|
}
|
|
511
|
-
export function
|
|
533
|
+
export function ForgotPassword(props) {
|
|
512
534
|
const { authClient, labels: m } = useAuthFormOptions(props);
|
|
513
|
-
const navigate = useNavigate();
|
|
514
535
|
const searchString = useRouterState({
|
|
515
536
|
select: (state) => state.location.searchStr,
|
|
516
537
|
});
|
|
517
|
-
const
|
|
538
|
+
const [submitted, setSubmitted] = useState(false);
|
|
539
|
+
const [form] = useState(() => FormReact.make(forgotPasswordFormBuilder, {
|
|
540
|
+
fields: { email: TextField },
|
|
541
|
+
mode: { validation: "onSubmit" },
|
|
542
|
+
onSubmit: (_, { decoded: value }) => Effect.tryPromise({
|
|
543
|
+
try: async () => {
|
|
544
|
+
setSubmitted(false);
|
|
545
|
+
const result = await authClient.requestPasswordReset({
|
|
546
|
+
email: value.email.trim(),
|
|
547
|
+
redirectTo: `${window.location.origin}/reset-password`,
|
|
548
|
+
});
|
|
549
|
+
if (result.error) {
|
|
550
|
+
throw new Error(result.error.message ?? m.forgot_password_error);
|
|
551
|
+
}
|
|
552
|
+
setSubmitted(true);
|
|
553
|
+
},
|
|
554
|
+
catch: (cause) => cause instanceof Error ? cause : new Error(m.forgot_password_error),
|
|
555
|
+
}),
|
|
556
|
+
}));
|
|
557
|
+
const submit = useAtomSet(form.submit);
|
|
558
|
+
const submitResult = useAtomValue(form.submit);
|
|
559
|
+
return (_jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-3xl", children: m.forgot_password_title }), _jsx(CardDescription, { children: m.forgot_password_description })] }), _jsxs(CardContent, { children: [_jsx(form.Initialize, { defaultValues: { email: "" }, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
|
|
560
|
+
event.preventDefault();
|
|
561
|
+
event.stopPropagation();
|
|
562
|
+
submit();
|
|
563
|
+
}, children: [_jsx(form.email, { label: m.field_email, type: "email", autoComplete: "email", required: true }), _jsx(SubmitError, { result: submitResult }), submitted ? (_jsx("p", { className: "bg-card text-card-foreground rounded-lg border px-4 py-3 text-sm shadow-xs", children: m.forgot_password_success })) : null, _jsxs(Button, { type: "submit", disabled: submitResult.waiting, children: [submitResult.waiting ? (_jsx(Loader2, { className: "animate-spin", "data-icon": "inline-start" })) : null, m.forgot_password_submit] })] }) }), _jsx("p", { className: "text-muted-foreground mt-6 text-center text-sm", children: _jsx(Link, { className: authLinkClassName, to: "/sign-in", search: searchObject(searchString), children: m.forgot_password_back_to_sign_in }) })] })] }));
|
|
564
|
+
}
|
|
565
|
+
export function ResetPassword(props) {
|
|
566
|
+
const searchString = useRouterState({
|
|
567
|
+
select: (state) => state.location.searchStr,
|
|
568
|
+
});
|
|
569
|
+
const token = getSearchParam(searchString, "token");
|
|
570
|
+
return token ? (_jsx(ResetPasswordForm, { ...props, token: token })) : (_jsx(ForgotPassword, { ...props }));
|
|
571
|
+
}
|
|
572
|
+
function ResetPasswordForm({ token, ...props }) {
|
|
573
|
+
const { authClient, labels: m } = useAuthFormOptions(props);
|
|
574
|
+
const navigate = useNavigate();
|
|
518
575
|
const onSuccess = () => navigate({ to: "/sign-in" });
|
|
519
576
|
const [form] = useState(() => FormReact.make(resetPasswordFormBuilder, {
|
|
520
577
|
fields: { password: TextField },
|
|
521
578
|
mode: { validation: "onSubmit" },
|
|
522
579
|
onSubmit: (_, { decoded: value }) => Effect.tryPromise({
|
|
523
580
|
try: async () => {
|
|
524
|
-
if (!token)
|
|
525
|
-
throw new Error(m.reset_password_missing_token);
|
|
526
581
|
const result = await authClient.resetPassword({
|
|
527
582
|
newPassword: value.password,
|
|
528
583
|
token,
|
|
@@ -4,7 +4,7 @@ export { OrganizationSwitcher } from "./organization-switcher";
|
|
|
4
4
|
export { MemberRequired } from "./member-required";
|
|
5
5
|
export { HasPermission, useHasPermission } from "./has-permission";
|
|
6
6
|
export { ProjectAccessMatrix } from "./project-access-matrix";
|
|
7
|
-
export { ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, } from "./auth-forms";
|
|
7
|
+
export { ForgotPassword, ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, } from "./auth-forms";
|
|
8
8
|
export { UserButton } from "./user-button";
|
|
9
9
|
export { AdminOrganizationsTable } from "./admin-organizations";
|
|
10
10
|
export { AdminOrganizationForm } from "./admin-organization-form";
|
|
@@ -15,6 +15,6 @@ export type { ApiKeyOwner, ApiKeyActor, Actor, Policy, ProjectAccessConfig, Proj
|
|
|
15
15
|
export type { ProjectAccessMatrixAccess, ProjectAccessMatrixMessages, } from "./project-access-matrix";
|
|
16
16
|
export type { KrakstackAuthContextValue, KrakstackAuthLocale, KrakstackAuthProviderProps, } from "./auth-provider";
|
|
17
17
|
export type { OrganizationSwitcherDialog, OrganizationSwitcherFeatures, OrganizationSwitcherProps, } from "./organization-switcher";
|
|
18
|
-
export type { UserButtonDialog } from "./user-button";
|
|
18
|
+
export type { UserButtonDialog, UserButtonProps } from "./user-button";
|
|
19
19
|
export type { AuthUiClient } from "./auth-client";
|
|
20
20
|
export type { MemberRequiredMessages, MemberRequiredProps, } from "./member-required";
|
package/dist/components/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export { OrganizationSwitcher } from "./organization-switcher";
|
|
|
4
4
|
export { MemberRequired } from "./member-required";
|
|
5
5
|
export { HasPermission, useHasPermission } from "./has-permission";
|
|
6
6
|
export { ProjectAccessMatrix } from "./project-access-matrix";
|
|
7
|
-
export { ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, } from "./auth-forms";
|
|
7
|
+
export { ForgotPassword, ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, } from "./auth-forms";
|
|
8
8
|
export { UserButton } from "./user-button";
|
|
9
9
|
export { AdminOrganizationsTable } from "./admin-organizations";
|
|
10
10
|
export { AdminOrganizationForm } from "./admin-organization-form";
|
|
@@ -4,7 +4,6 @@ export type ProjectAccessMatrixAccess<Action extends string = string> = {
|
|
|
4
4
|
readonly apiKeys: {
|
|
5
5
|
readonly user: ReadonlyArray<Action>;
|
|
6
6
|
readonly organization: ReadonlyArray<Action>;
|
|
7
|
-
readonly service: ReadonlyArray<Action>;
|
|
8
7
|
};
|
|
9
8
|
readonly project: string;
|
|
10
9
|
readonly roles: Readonly<Record<string, ReadonlyArray<Action> | undefined>>;
|
|
@@ -17,7 +16,6 @@ export type ProjectAccessMatrixMessages = {
|
|
|
17
16
|
organizationKey: string;
|
|
18
17
|
resource: string;
|
|
19
18
|
rolePermissions: string;
|
|
20
|
-
serviceKey: string;
|
|
21
19
|
userKey: string;
|
|
22
20
|
};
|
|
23
21
|
export declare const ProjectAccessMatrix: <Action extends string, Role extends string>({ access, labels, locale, messages: messageOverrides, }: {
|
|
@@ -9,7 +9,6 @@ const messages = {
|
|
|
9
9
|
organizationKey: "Organization key",
|
|
10
10
|
resource: "Resource",
|
|
11
11
|
rolePermissions: "Role grants",
|
|
12
|
-
serviceKey: "Service key",
|
|
13
12
|
userKey: "User key",
|
|
14
13
|
},
|
|
15
14
|
fr: {
|
|
@@ -20,7 +19,6 @@ const messages = {
|
|
|
20
19
|
organizationKey: "Clé d’organisation",
|
|
21
20
|
resource: "Ressource",
|
|
22
21
|
rolePermissions: "Droits des rôles",
|
|
23
|
-
serviceKey: "Clé de service",
|
|
24
22
|
userKey: "Clé utilisateur",
|
|
25
23
|
},
|
|
26
24
|
};
|
|
@@ -47,11 +45,6 @@ export const ProjectAccessMatrix = ({ access, labels, locale = "en", messages: m
|
|
|
47
45
|
label: text.organizationKey,
|
|
48
46
|
permissions: access.apiKeys.organization,
|
|
49
47
|
},
|
|
50
|
-
{
|
|
51
|
-
id: "service",
|
|
52
|
-
label: text.serviceKey,
|
|
53
|
-
permissions: access.apiKeys.service,
|
|
54
|
-
},
|
|
55
48
|
];
|
|
56
49
|
return (_jsxs("div", { className: "space-y-8", children: [_jsx(PermissionTable, { access: access, columns: roleColumns, labels: labels, text: text, title: text.rolePermissions }), _jsx(PermissionTable, { access: access, columns: keyColumns, labels: labels, text: text, title: text.apiKeyPermissions })] }));
|
|
57
50
|
};
|
|
@@ -219,7 +219,7 @@ declare const messages: {
|
|
|
219
219
|
};
|
|
220
220
|
type UserButtonMessageKey = keyof (typeof messages)["en"];
|
|
221
221
|
export type UserButtonMessages = Partial<Record<UserButtonMessageKey, string>>;
|
|
222
|
-
type
|
|
222
|
+
export type UserButtonProps = {
|
|
223
223
|
authClient?: AuthUiClient;
|
|
224
224
|
baseUrl?: string | undefined;
|
|
225
225
|
signOutRedirect?: string;
|
|
@@ -227,11 +227,12 @@ type UserDropdownProps = {
|
|
|
227
227
|
defaultDialog?: UserButtonDialog | null;
|
|
228
228
|
hideTrigger?: boolean;
|
|
229
229
|
renderUnauthenticated?: () => ReactNode;
|
|
230
|
+
menuActions?: ReactNode;
|
|
230
231
|
apiKeyPermissions?: Readonly<Record<string, ReadonlyArray<string>>>;
|
|
231
232
|
messages?: UserButtonMessages;
|
|
232
233
|
dialog?: UserButtonDialog | null;
|
|
233
234
|
onDialogChange?: (dialog: UserButtonDialog | null) => void;
|
|
234
235
|
};
|
|
235
236
|
export type UserButtonDialog = "account" | "security" | "apiKeys" | "adminUsers" | "adminOrganizations";
|
|
236
|
-
export declare const UserButton: ({ authClient: providedAuthClient, baseUrl, signOutRedirect, side, defaultDialog, hideTrigger, renderUnauthenticated, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }:
|
|
237
|
+
export declare const UserButton: ({ authClient: providedAuthClient, baseUrl, signOutRedirect, side, defaultDialog, hideTrigger, renderUnauthenticated, menuActions, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }: UserButtonProps) => import("react").JSX.Element;
|
|
237
238
|
export {};
|
|
@@ -318,7 +318,7 @@ const userApiKeysAtom = Atom.family((authClient) => Atom.keepAlive(Atom.make(Eff
|
|
|
318
318
|
catch: (error) => error,
|
|
319
319
|
}))));
|
|
320
320
|
const emptyApiKeysAtom = Atom.make(Effect.succeed([]));
|
|
321
|
-
export const UserButton = ({ authClient: providedAuthClient, baseUrl, signOutRedirect = "/", side = "bottom", defaultDialog = null, hideTrigger = false, renderUnauthenticated, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }) => {
|
|
321
|
+
export const UserButton = ({ authClient: providedAuthClient, baseUrl, signOutRedirect = "/", side = "bottom", defaultDialog = null, hideTrigger = false, renderUnauthenticated, menuActions, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }) => {
|
|
322
322
|
const auth = useKrakstackAuth();
|
|
323
323
|
const authClient = providedAuthClient ?? auth?.authClient;
|
|
324
324
|
if (!authClient) {
|
|
@@ -415,7 +415,7 @@ export const UserButton = ({ authClient: providedAuthClient, baseUrl, signOutRed
|
|
|
415
415
|
await refetch();
|
|
416
416
|
setSettingsDialog(null);
|
|
417
417
|
};
|
|
418
|
-
return (_jsxs(UserButtonMessagesContext.Provider, { value: m, children: [hideTrigger ? null : (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "outline", size: "icon", children: [displayImage ? (_jsx("img", { src: displayImage, alt: displayName || displayEmail, className: "size-full rounded-md object-cover" })) : (_jsx(UserIcon, { className: "size-4.5" })), _jsx("span", { className: "sr-only", children: m.user_button_aria_label() })] }) }), _jsx(DropdownMenuContent, { className: "w-56 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [isImpersonating ? (_jsx("div", { className: "px-1 py-0.5", children: _jsx(Badge, { variant: "secondary", className: "text-xs font-normal", children: m.user_button_impersonating() }) })) : null, _jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: displayName || displayEmail, subtitle: displayName ? displayEmail : m.user_button_account(), icon: UserIcon, className: "px-1 py-1.5 text-left text-sm", ...(displayImage ? { imageSrc: displayImage } : {}) }) }), _jsx(DropdownMenuSeparator, {}), canManageUserSettings ? (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { disabled: isPending, onClick: () => setSettingsDialog("account"), children: [_jsx(UserCircleIcon, {}), m.user_button_account()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("security"), children: [_jsx(ShieldCheck, {}), m.user_button_security()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] }), _jsx(DropdownMenuSeparator, {})] })) : null, (isAdmin && canUseAdminSettings) || isImpersonating ? (_jsxs(_Fragment, { children: [isAdmin && canUseAdminSettings ? (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("adminUsers"), children: [_jsx(Users, {}), m.user_button_admin_users()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("adminOrganizations"), children: [_jsx(Building2, {}), m.user_button_admin_organizations()] })] })) : null, isImpersonating ? (_jsxs(DropdownMenuItem, { disabled: isStoppingImpersonation, onClick: stopImpersonating, children: [_jsx(StopCircle, {}), m.user_button_stop_impersonating()] })) : null, _jsx(DropdownMenuSeparator, {})] })) : null, _jsxs(DropdownMenuItem, { onClick: signOut, children: [_jsx(LogOutIcon, {}), m.user_button_logout()] })] }) })] })), _jsx(Dialog, { open: canManageUserSettings && settingsDialog === "account", onOpenChange: (open) => {
|
|
418
|
+
return (_jsxs(UserButtonMessagesContext.Provider, { value: m, children: [hideTrigger ? null : (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "outline", size: "icon", children: [displayImage ? (_jsx("img", { src: displayImage, alt: displayName || displayEmail, className: "size-full rounded-md object-cover" })) : (_jsx(UserIcon, { className: "size-4.5" })), _jsx("span", { className: "sr-only", children: m.user_button_aria_label() })] }) }), _jsx(DropdownMenuContent, { className: "w-56 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [isImpersonating ? (_jsx("div", { className: "px-1 py-0.5", children: _jsx(Badge, { variant: "secondary", className: "text-xs font-normal", children: m.user_button_impersonating() }) })) : null, _jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: displayName || displayEmail, subtitle: displayName ? displayEmail : m.user_button_account(), icon: UserIcon, className: "px-1 py-1.5 text-left text-sm", ...(displayImage ? { imageSrc: displayImage } : {}) }) }), menuActions ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), menuActions] })) : null, _jsx(DropdownMenuSeparator, {}), canManageUserSettings ? (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { disabled: isPending, onClick: () => setSettingsDialog("account"), children: [_jsx(UserCircleIcon, {}), m.user_button_account()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("security"), children: [_jsx(ShieldCheck, {}), m.user_button_security()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] }), _jsx(DropdownMenuSeparator, {})] })) : null, (isAdmin && canUseAdminSettings) || isImpersonating ? (_jsxs(_Fragment, { children: [isAdmin && canUseAdminSettings ? (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("adminUsers"), children: [_jsx(Users, {}), m.user_button_admin_users()] }), _jsxs(DropdownMenuItem, { onClick: () => setSettingsDialog("adminOrganizations"), children: [_jsx(Building2, {}), m.user_button_admin_organizations()] })] })) : null, isImpersonating ? (_jsxs(DropdownMenuItem, { disabled: isStoppingImpersonation, onClick: stopImpersonating, children: [_jsx(StopCircle, {}), m.user_button_stop_impersonating()] })) : null, _jsx(DropdownMenuSeparator, {})] })) : null, _jsxs(DropdownMenuItem, { onClick: signOut, children: [_jsx(LogOutIcon, {}), m.user_button_logout()] })] }) })] })), _jsx(Dialog, { open: canManageUserSettings && settingsDialog === "account", onOpenChange: (open) => {
|
|
419
419
|
setSettingsDialog((current) => open ? "account" : current === "account" ? null : current);
|
|
420
420
|
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_form_title() }), _jsx(DialogDescription, { children: m.user_form_description() })] }), _jsx(Separator, {}), isPending ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : (_jsxs("div", { className: "flex flex-col gap-6", children: [_jsx(UserForm, { defaultValues: {
|
|
421
421
|
name: displayName ?? "",
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { AuthClientApi, AuthServiceApi } from "./api";
|
|
|
5
5
|
export { AuthService, type AuthServiceLayerOptions } from "./service";
|
|
6
6
|
export { AuthClientConfig } from "./config";
|
|
7
7
|
export { proxyAuthRequest } from "./server/proxy";
|
|
8
|
-
export { OrganizationSwitcher, MemberRequired, ProjectAccessMatrix, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, type AuthUiClient, type MemberRequiredMessages, type MemberRequiredProps, type ProjectAccessMatrixAccess, type ProjectAccessMatrixMessages, type ProjectAccessLabels, type ProjectAccessLabelCatalog, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type OrganizationSwitcherFeatures, type OrganizationSwitcherProps, type UserButtonDialog, useAuthClient, useAdminUsersTotal, } from "./components";
|
|
8
|
+
export { OrganizationSwitcher, MemberRequired, ProjectAccessMatrix, KrakstackAuthProvider, ForgotPassword, ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, type AuthUiClient, type MemberRequiredMessages, type MemberRequiredProps, type ProjectAccessMatrixAccess, type ProjectAccessMatrixMessages, type ProjectAccessLabels, type ProjectAccessLabelCatalog, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type OrganizationSwitcherFeatures, type OrganizationSwitcherProps, type UserButtonDialog, type UserButtonProps, useAuthClient, useAdminUsersTotal, } from "./components";
|
|
9
9
|
export * as BetterAuth from "./better-auth/api.group";
|
|
10
10
|
export * as Extra from "./extra/api.group";
|
|
11
11
|
export * as Server from "./server";
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export { AuthClientApi, AuthServiceApi } from "./api";
|
|
|
5
5
|
export { AuthService } from "./service";
|
|
6
6
|
export { AuthClientConfig } from "./config";
|
|
7
7
|
export { proxyAuthRequest } from "./server/proxy";
|
|
8
|
-
export { OrganizationSwitcher, MemberRequired, ProjectAccessMatrix, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, useAuthClient, useAdminUsersTotal, } from "./components";
|
|
8
|
+
export { OrganizationSwitcher, MemberRequired, ProjectAccessMatrix, KrakstackAuthProvider, ForgotPassword, ResetPassword, Signin, Signup, TwoFactor, VerifyEmail, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, useAuthClient, useAdminUsersTotal, } from "./components";
|
|
9
9
|
export * as BetterAuth from "./better-auth/api.group";
|
|
10
10
|
export * as Extra from "./extra/api.group";
|
|
11
11
|
export * as Server from "./server";
|
package/dist/server/actor.d.ts
CHANGED
|
@@ -52,23 +52,13 @@ declare const OrganizationApiKeyActorRequired_base: HttpApiMiddleware.ServiceCla
|
|
|
52
52
|
}, HttpApiMiddleware.HttpApiMiddleware<CurrentActor, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden], AuthService>>;
|
|
53
53
|
declare class OrganizationApiKeyActorRequired extends OrganizationApiKeyActorRequired_base {
|
|
54
54
|
}
|
|
55
|
-
declare const ServiceApiKeyActorRequired_base: HttpApiMiddleware.ServiceClass<ServiceApiKeyActorRequired, "@krak-stack/auth/ActorRequired/ApiKey/Service", {
|
|
56
|
-
requires: AuthService;
|
|
57
|
-
provides: CurrentActor;
|
|
58
|
-
error: readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden];
|
|
59
|
-
clientError: never;
|
|
60
|
-
requiredForClient: false;
|
|
61
|
-
security: never;
|
|
62
|
-
}, HttpApiMiddleware.HttpApiMiddleware<CurrentActor, readonly [typeof HttpApiError.Unauthorized, typeof HttpApiError.Forbidden], AuthService>>;
|
|
63
|
-
declare class ServiceApiKeyActorRequired extends ServiceApiKeyActorRequired_base {
|
|
64
|
-
}
|
|
65
55
|
export type ActorConstraint = {
|
|
66
56
|
readonly type: "user";
|
|
67
57
|
} | {
|
|
68
58
|
readonly type: "apiKey";
|
|
69
|
-
readonly ownerType?: "user" | "organization" |
|
|
59
|
+
readonly ownerType?: "user" | "organization" | undefined;
|
|
70
60
|
};
|
|
71
|
-
declare const actorRequiredLayer: <Project extends string, Action extends string>(access: ProjectAccessDefinition<Project, Action>) => Layer.Layer<AnyActorRequired | ApiKeyActorRequired | OrganizationApiKeyActorRequired |
|
|
61
|
+
declare const actorRequiredLayer: <Project extends string, Action extends string>(access: ProjectAccessDefinition<Project, Action>) => Layer.Layer<AnyActorRequired | ApiKeyActorRequired | OrganizationApiKeyActorRequired | UserActorRequired | UserApiKeyActorRequired, never, never>;
|
|
72
62
|
type ActorRequiredFactory = {
|
|
73
63
|
(): typeof AnyActorRequired;
|
|
74
64
|
(constraint: {
|
|
@@ -82,10 +72,6 @@ type ActorRequiredFactory = {
|
|
|
82
72
|
readonly type: "apiKey";
|
|
83
73
|
readonly ownerType: "organization";
|
|
84
74
|
}): typeof OrganizationApiKeyActorRequired;
|
|
85
|
-
(constraint: {
|
|
86
|
-
readonly type: "apiKey";
|
|
87
|
-
readonly ownerType: "service";
|
|
88
|
-
}): typeof ServiceApiKeyActorRequired;
|
|
89
75
|
(constraint: {
|
|
90
76
|
readonly type: "apiKey";
|
|
91
77
|
}): typeof ApiKeyActorRequired;
|
package/dist/server/actor.js
CHANGED
|
@@ -16,13 +16,6 @@ const resolveCurrentActor = (access) => Effect.gen(function* () {
|
|
|
16
16
|
if (session.authMethod.type === "apiKey") {
|
|
17
17
|
const apiKey = session.authMethod.apiKey;
|
|
18
18
|
const grant = yield* Schema.decodeUnknownEffect(ApiKeyPermissionGrant)(apiKey.permissions ?? {}).pipe(Effect.mapError(() => new HttpApiError.Unauthorized({})));
|
|
19
|
-
if (apiKey.configId === "service") {
|
|
20
|
-
return access.actorForApiKey({
|
|
21
|
-
apiKeyId: apiKey.id,
|
|
22
|
-
owner: { type: "service", serviceId: apiKey.referenceId },
|
|
23
|
-
grant,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
19
|
const organizationId = session.session.activeOrganizationId;
|
|
27
20
|
if (!organizationId)
|
|
28
21
|
return yield* new HttpApiError.Unauthorized({});
|
|
@@ -86,10 +79,6 @@ class OrganizationApiKeyActorRequired extends HttpApiMiddleware.Service()("@krak
|
|
|
86
79
|
error: [HttpApiError.Unauthorized, HttpApiError.Forbidden],
|
|
87
80
|
}) {
|
|
88
81
|
}
|
|
89
|
-
class ServiceApiKeyActorRequired extends HttpApiMiddleware.Service()("@krak-stack/auth/ActorRequired/ApiKey/Service", {
|
|
90
|
-
error: [HttpApiError.Unauthorized, HttpApiError.Forbidden],
|
|
91
|
-
}) {
|
|
92
|
-
}
|
|
93
82
|
const matchesConstraint = (actor, constraint) => {
|
|
94
83
|
if (!constraint)
|
|
95
84
|
return true;
|
|
@@ -111,16 +100,11 @@ const actorRequired = (constraint) => {
|
|
|
111
100
|
if (constraint.ownerType === "organization") {
|
|
112
101
|
return OrganizationApiKeyActorRequired;
|
|
113
102
|
}
|
|
114
|
-
if (constraint.ownerType === "service")
|
|
115
|
-
return ServiceApiKeyActorRequired;
|
|
116
103
|
return ApiKeyActorRequired;
|
|
117
104
|
};
|
|
118
105
|
const actorRequiredLayer = (access) => Layer.mergeAll(Layer.succeed(AnyActorRequired, (httpEffect) => requiredActor(access).pipe(Effect.flatMap((actor) => httpEffect.pipe(Effect.provideService(CurrentActor, actor))))), Layer.succeed(UserActorRequired, (httpEffect) => requiredActor(access, { type: "user" }).pipe(Effect.flatMap((actor) => httpEffect.pipe(Effect.provideService(CurrentActor, actor))))), Layer.succeed(ApiKeyActorRequired, (httpEffect) => requiredActor(access, { type: "apiKey" }).pipe(Effect.flatMap((actor) => httpEffect.pipe(Effect.provideService(CurrentActor, actor))))), Layer.succeed(UserApiKeyActorRequired, (httpEffect) => requiredActor(access, { type: "apiKey", ownerType: "user" }).pipe(Effect.flatMap((actor) => httpEffect.pipe(Effect.provideService(CurrentActor, actor))))), Layer.succeed(OrganizationApiKeyActorRequired, (httpEffect) => requiredActor(access, {
|
|
119
106
|
type: "apiKey",
|
|
120
107
|
ownerType: "organization",
|
|
121
|
-
}).pipe(Effect.flatMap((actor) => httpEffect.pipe(Effect.provideService(CurrentActor, actor))))), Layer.succeed(ServiceApiKeyActorRequired, (httpEffect) => requiredActor(access, {
|
|
122
|
-
type: "apiKey",
|
|
123
|
-
ownerType: "service",
|
|
124
108
|
}).pipe(Effect.flatMap((actor) => httpEffect.pipe(Effect.provideService(CurrentActor, actor))))));
|
|
125
109
|
export const ActorRequired = Object.assign(actorRequired, {
|
|
126
110
|
layer: actorRequiredLayer,
|
|
@@ -41,11 +41,11 @@ export const makeAuthenticationLive = (options = {}) => {
|
|
|
41
41
|
return yield* new HttpApiError.Forbidden({});
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
return
|
|
44
|
+
return auth;
|
|
45
45
|
}).pipe(Effect.mapError((error) => error instanceof HttpApiError.Unauthorized ||
|
|
46
46
|
error instanceof HttpApiError.Forbidden
|
|
47
47
|
? error
|
|
48
|
-
: new HttpApiError.Unauthorized({}))),
|
|
48
|
+
: new HttpApiError.Unauthorized({})), Effect.flatMap((auth) => httpEffect.pipe(Effect.provideService(AuthService, auth)))),
|
|
49
49
|
};
|
|
50
50
|
}));
|
|
51
51
|
};
|