@krak-stack/auth 0.1.47 → 0.1.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +22 -2
- package/dist/components/admin-organization-form.js +0 -1
- package/dist/components/admin-organizations.js +0 -1
- package/dist/components/admin-required.d.ts +43 -0
- package/dist/components/admin-required.js +183 -0
- package/dist/components/admin-users.js +0 -1
- package/dist/components/auth-client-api.d.ts +11 -1
- package/dist/components/auth-client.d.ts +24 -55
- package/dist/components/auth-client.js +23 -12
- package/dist/components/auth-forms.js +15 -12
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +1 -0
- package/dist/components/organization-switcher.d.ts +4 -0
- package/dist/components/organization-switcher.js +69 -26
- package/dist/extra/api.group.d.ts +11 -1
- package/dist/extra/api.group.js +10 -1
- package/dist/extra/schema.d.ts +14 -0
- package/dist/extra/schema.js +32 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/service.d.ts +28 -0
- package/package.json +3 -3
package/dist/api.d.ts
CHANGED
|
@@ -64,7 +64,17 @@ export declare const AuthServiceApi: HttpApi.HttpApi<"AuthServiceApi", import("e
|
|
|
64
64
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
65
65
|
readonly id: import("effect/Schema").String;
|
|
66
66
|
readonly key: import("effect/Schema").String;
|
|
67
|
-
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError | typeof import("./extra/schema").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"
|
|
67
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError | typeof import("./extra/schema").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getOrganizationPublicProfile", "GET", "/api/auth/organization-profile", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
68
|
+
readonly organizationId: import("effect/Schema").String;
|
|
69
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
70
|
+
readonly id: import("effect/Schema").String;
|
|
71
|
+
readonly name: import("effect/Schema").String;
|
|
72
|
+
readonly slug: import("effect/Schema").String;
|
|
73
|
+
readonly displayName: import("effect/Schema").String;
|
|
74
|
+
readonly contactEmail: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
75
|
+
readonly logo: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
76
|
+
readonly icon: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
77
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getProjectPublicConfig", "GET", "/api/auth/project-config", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
68
78
|
readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
69
79
|
readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
70
80
|
readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
@@ -695,7 +705,17 @@ export declare const AuthClientApi: HttpApi.HttpApi<"AuthClientApi", import("eff
|
|
|
695
705
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
696
706
|
readonly id: import("effect/Schema").String;
|
|
697
707
|
readonly key: import("effect/Schema").String;
|
|
698
|
-
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError | typeof import("./extra/schema").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"
|
|
708
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError | typeof import("./extra/schema").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getOrganizationPublicProfile", "GET", "/api/auth/organization-profile", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
709
|
+
readonly organizationId: import("effect/Schema").String;
|
|
710
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
711
|
+
readonly id: import("effect/Schema").String;
|
|
712
|
+
readonly name: import("effect/Schema").String;
|
|
713
|
+
readonly slug: import("effect/Schema").String;
|
|
714
|
+
readonly displayName: import("effect/Schema").String;
|
|
715
|
+
readonly contactEmail: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
716
|
+
readonly logo: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
717
|
+
readonly icon: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
718
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getProjectPublicConfig", "GET", "/api/auth/project-config", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
699
719
|
readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
700
720
|
readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
701
721
|
readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { AuthUiClient } from "./auth-client";
|
|
3
|
+
declare const defaultMessages: {
|
|
4
|
+
readonly en: {
|
|
5
|
+
readonly admin_required_title: "Admin access required";
|
|
6
|
+
readonly admin_required_description: "You need administrator access to continue.";
|
|
7
|
+
readonly admin_required_org_description: "You need access to {organization} before opening the admin area.";
|
|
8
|
+
readonly admin_required_no_permission: "Your account is signed in, but it does not have the required admin access.";
|
|
9
|
+
readonly admin_required_invite_found: "You have a pending invitation to {organization}. Accept it to continue.";
|
|
10
|
+
readonly admin_required_accept_invite: "Accept invitation";
|
|
11
|
+
readonly admin_required_accepting_invite: "Accepting...";
|
|
12
|
+
readonly admin_required_accept_error: "Could not accept the invitation.";
|
|
13
|
+
readonly admin_required_contact: "Contact organization";
|
|
14
|
+
readonly admin_required_contact_description: "If you expected access, contact the organization administrator.";
|
|
15
|
+
readonly admin_required_copy_email: "Copy email";
|
|
16
|
+
readonly admin_required_copied_email: "Copied email";
|
|
17
|
+
};
|
|
18
|
+
readonly fr: {
|
|
19
|
+
readonly admin_required_title: "Accès administrateur requis";
|
|
20
|
+
readonly admin_required_description: "Vous devez disposer d'un accès administrateur pour continuer.";
|
|
21
|
+
readonly admin_required_org_description: "Vous devez avoir accès à {organization} avant d'ouvrir l'administration.";
|
|
22
|
+
readonly admin_required_no_permission: "Votre compte est connecté, mais il ne dispose pas de l'accès administrateur requis.";
|
|
23
|
+
readonly admin_required_invite_found: "Vous avez une invitation en attente pour {organization}. Acceptez-la pour continuer.";
|
|
24
|
+
readonly admin_required_accept_invite: "Accepter l'invitation";
|
|
25
|
+
readonly admin_required_accepting_invite: "Acceptation...";
|
|
26
|
+
readonly admin_required_accept_error: "Impossible d'accepter l'invitation.";
|
|
27
|
+
readonly admin_required_contact: "Contacter l'organisation";
|
|
28
|
+
readonly admin_required_contact_description: "Si vous pensiez avoir accès, contactez l'administrateur de l'organisation.";
|
|
29
|
+
readonly admin_required_copy_email: "Copier l'e-mail";
|
|
30
|
+
readonly admin_required_copied_email: "E-mail copié";
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
type AdminRequiredLabels = (typeof defaultMessages)["en"];
|
|
34
|
+
export type AdminRequiredMessages = Partial<AdminRequiredLabels>;
|
|
35
|
+
export type AdminRequiredProps = {
|
|
36
|
+
authClient?: AuthUiClient | undefined;
|
|
37
|
+
organizationId: string;
|
|
38
|
+
contactEmail?: string | undefined;
|
|
39
|
+
children?: ReactNode;
|
|
40
|
+
messages?: AdminRequiredMessages | undefined;
|
|
41
|
+
};
|
|
42
|
+
export declare function AdminRequired({ authClient: providedAuthClient, organizationId, contactEmail, children, messages, }: AdminRequiredProps): import("react").JSX.Element;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useAtomSuspense } from "@effect/atom-react";
|
|
3
|
+
import { Effect } from "effect";
|
|
4
|
+
import { Atom } from "effect/unstable/reactivity";
|
|
5
|
+
import { Check, Loader2, Mail, ShieldAlert } from "lucide-react";
|
|
6
|
+
import { useEffect, useState } from "react";
|
|
7
|
+
import { Button } from "@/components/ui/button";
|
|
8
|
+
import { CopyButton } from "@/components/ui/copy-button";
|
|
9
|
+
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card";
|
|
10
|
+
import { useKrakstackAuth } from "./auth-provider";
|
|
11
|
+
const defaultMessages = {
|
|
12
|
+
en: {
|
|
13
|
+
admin_required_title: "Admin access required",
|
|
14
|
+
admin_required_description: "You need administrator access to continue.",
|
|
15
|
+
admin_required_org_description: "You need access to {organization} before opening the admin area.",
|
|
16
|
+
admin_required_no_permission: "Your account is signed in, but it does not have the required admin access.",
|
|
17
|
+
admin_required_invite_found: "You have a pending invitation to {organization}. Accept it to continue.",
|
|
18
|
+
admin_required_accept_invite: "Accept invitation",
|
|
19
|
+
admin_required_accepting_invite: "Accepting...",
|
|
20
|
+
admin_required_accept_error: "Could not accept the invitation.",
|
|
21
|
+
admin_required_contact: "Contact organization",
|
|
22
|
+
admin_required_contact_description: "If you expected access, contact the organization administrator.",
|
|
23
|
+
admin_required_copy_email: "Copy email",
|
|
24
|
+
admin_required_copied_email: "Copied email",
|
|
25
|
+
},
|
|
26
|
+
fr: {
|
|
27
|
+
admin_required_title: "Accès administrateur requis",
|
|
28
|
+
admin_required_description: "Vous devez disposer d'un accès administrateur pour continuer.",
|
|
29
|
+
admin_required_org_description: "Vous devez avoir accès à {organization} avant d'ouvrir l'administration.",
|
|
30
|
+
admin_required_no_permission: "Votre compte est connecté, mais il ne dispose pas de l'accès administrateur requis.",
|
|
31
|
+
admin_required_invite_found: "Vous avez une invitation en attente pour {organization}. Acceptez-la pour continuer.",
|
|
32
|
+
admin_required_accept_invite: "Accepter l'invitation",
|
|
33
|
+
admin_required_accepting_invite: "Acceptation...",
|
|
34
|
+
admin_required_accept_error: "Impossible d'accepter l'invitation.",
|
|
35
|
+
admin_required_contact: "Contacter l'organisation",
|
|
36
|
+
admin_required_contact_description: "Si vous pensiez avoir accès, contactez l'administrateur de l'organisation.",
|
|
37
|
+
admin_required_copy_email: "Copier l'e-mail",
|
|
38
|
+
admin_required_copied_email: "E-mail copié",
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
const isFullOrganization = (value) => {
|
|
42
|
+
if (typeof value !== "object" || value === null)
|
|
43
|
+
return false;
|
|
44
|
+
if (!("id" in value) || typeof value.id !== "string")
|
|
45
|
+
return false;
|
|
46
|
+
if (!("name" in value) || typeof value.name !== "string")
|
|
47
|
+
return false;
|
|
48
|
+
if (!("slug" in value) || typeof value.slug !== "string")
|
|
49
|
+
return false;
|
|
50
|
+
if (!("displayName" in value) || typeof value.displayName !== "string") {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
};
|
|
55
|
+
const interpolate = (value, params) => Object.entries(params ?? {}).reduce((current, [key, replacement]) => current.replace(`{${key}}`, replacement), value);
|
|
56
|
+
const labels = (locale, overrides) => ({
|
|
57
|
+
...(locale === "fr" ? defaultMessages.fr : defaultMessages.en),
|
|
58
|
+
...overrides,
|
|
59
|
+
});
|
|
60
|
+
const invitationMatches = (invitation, organizationId) => invitation.status === "pending" && invitation.organizationId === organizationId;
|
|
61
|
+
const organizationContactEmail = (organization, fallback) => organization?.contactEmail ?? fallback ?? null;
|
|
62
|
+
const organizationDisplayName = (invitation, organization, fallback) => organization?.displayName ??
|
|
63
|
+
organization?.name ??
|
|
64
|
+
invitation?.organization?.name ??
|
|
65
|
+
invitation?.organizationName ??
|
|
66
|
+
fallback;
|
|
67
|
+
const organizationProfileUrl = (baseUrl, organizationId) => {
|
|
68
|
+
const root = baseUrl?.trim() ||
|
|
69
|
+
(typeof window === "undefined" ? "" : window.location.origin);
|
|
70
|
+
const url = new URL("/api/auth/organization-profile", root);
|
|
71
|
+
url.searchParams.set("organizationId", organizationId);
|
|
72
|
+
return url;
|
|
73
|
+
};
|
|
74
|
+
const getOrganizationPublicProfile = async (baseUrl, organizationId) => {
|
|
75
|
+
const response = await fetch(organizationProfileUrl(baseUrl, organizationId), {
|
|
76
|
+
credentials: "include",
|
|
77
|
+
});
|
|
78
|
+
if (!response.ok)
|
|
79
|
+
return null;
|
|
80
|
+
const body = await response.json();
|
|
81
|
+
return isFullOrganization(body) ? body : null;
|
|
82
|
+
};
|
|
83
|
+
const accessAtom = Atom.family((authClient) => Atom.family((key) => {
|
|
84
|
+
const { baseUrl, isAdmin, organizationId } = JSON.parse(key);
|
|
85
|
+
return Atom.keepAlive(Atom.make(Effect.tryPromise({
|
|
86
|
+
try: async () => {
|
|
87
|
+
if (isAdmin) {
|
|
88
|
+
const activeResult = await authClient.organization.setActive({
|
|
89
|
+
organizationId,
|
|
90
|
+
});
|
|
91
|
+
if (!activeResult.error)
|
|
92
|
+
return { allowed: true };
|
|
93
|
+
}
|
|
94
|
+
const [organization, invitationsResult] = await Promise.all([
|
|
95
|
+
getOrganizationPublicProfile(baseUrl, organizationId).catch(() => null),
|
|
96
|
+
authClient.organization.listUserInvitations({}),
|
|
97
|
+
]);
|
|
98
|
+
return {
|
|
99
|
+
allowed: false,
|
|
100
|
+
organization,
|
|
101
|
+
invitation: invitationsResult.data?.find((item) => invitationMatches(item, organizationId)) ?? null,
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
catch: (error) => error,
|
|
105
|
+
})));
|
|
106
|
+
}));
|
|
107
|
+
const accessAtomKey = ({ baseUrl, isAdmin, organizationId, userId, }) => JSON.stringify({ baseUrl, isAdmin, organizationId, userId });
|
|
108
|
+
export function AdminRequired({ authClient: providedAuthClient, organizationId, contactEmail, children, messages, }) {
|
|
109
|
+
const auth = useKrakstackAuth();
|
|
110
|
+
const authClient = providedAuthClient ?? auth?.authClient;
|
|
111
|
+
const baseUrl = auth?.baseUrl;
|
|
112
|
+
const locale = auth?.locale;
|
|
113
|
+
const refreshAuth = auth?.refreshAuth;
|
|
114
|
+
if (!authClient) {
|
|
115
|
+
throw new Error("KrakstackAuthProvider is required to use authClient.");
|
|
116
|
+
}
|
|
117
|
+
const session = authClient.useSession();
|
|
118
|
+
const userId = session.data?.user.id;
|
|
119
|
+
const role = session.data?.user.role;
|
|
120
|
+
const isAdmin = typeof role === "string" &&
|
|
121
|
+
role.split(",").some((item) => item.trim() === "admin");
|
|
122
|
+
const currentAccessKey = accessAtomKey({
|
|
123
|
+
baseUrl,
|
|
124
|
+
isAdmin,
|
|
125
|
+
organizationId,
|
|
126
|
+
userId,
|
|
127
|
+
});
|
|
128
|
+
const [allowedAccessKey, setAllowedAccessKey] = useState(null);
|
|
129
|
+
if (allowedAccessKey === currentAccessKey)
|
|
130
|
+
return _jsx(_Fragment, { children: children });
|
|
131
|
+
return (_jsx(AdminRequiredGate, { accessKey: currentAccessKey, authClient: authClient, contactEmail: contactEmail, isAdmin: isAdmin, locale: locale, messages: messages, onAccessAllowed: () => setAllowedAccessKey(currentAccessKey), organizationId: organizationId, refreshAuth: refreshAuth, children: children }));
|
|
132
|
+
}
|
|
133
|
+
function AdminRequiredGate({ accessKey, authClient, contactEmail, children, isAdmin, locale, messages, onAccessAllowed, organizationId, refreshAuth, }) {
|
|
134
|
+
const m = labels(locale, messages);
|
|
135
|
+
const accessResult = useAtomSuspense(accessAtom(authClient)(accessKey), {
|
|
136
|
+
suspendOnWaiting: true,
|
|
137
|
+
});
|
|
138
|
+
const [accepting, setAccepting] = useState(false);
|
|
139
|
+
const [error, setError] = useState(null);
|
|
140
|
+
const access = accessResult.value;
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
if (!access.allowed)
|
|
143
|
+
return;
|
|
144
|
+
onAccessAllowed();
|
|
145
|
+
}, [access.allowed, onAccessAllowed]);
|
|
146
|
+
if (access.allowed)
|
|
147
|
+
return _jsx(_Fragment, { children: children });
|
|
148
|
+
const { invitation, organization } = access;
|
|
149
|
+
const displayName = organizationDisplayName(invitation, organization, organizationId);
|
|
150
|
+
const resolvedContactEmail = organizationContactEmail(organization, contactEmail);
|
|
151
|
+
const acceptInvitation = async () => {
|
|
152
|
+
if (!invitation)
|
|
153
|
+
return;
|
|
154
|
+
setAccepting(true);
|
|
155
|
+
setError(null);
|
|
156
|
+
const result = await authClient.organization.acceptInvitation({
|
|
157
|
+
invitationId: invitation.id,
|
|
158
|
+
});
|
|
159
|
+
if (result.error) {
|
|
160
|
+
setAccepting(false);
|
|
161
|
+
setError(result.error.message ?? m.admin_required_accept_error);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
await authClient.organization.setActive({
|
|
165
|
+
organizationId: invitation.organizationId,
|
|
166
|
+
});
|
|
167
|
+
refreshAuth?.();
|
|
168
|
+
onAccessAllowed();
|
|
169
|
+
setAccepting(false);
|
|
170
|
+
};
|
|
171
|
+
return (_jsx("main", { className: "relative grid min-h-screen place-items-center px-6 py-10", children: _jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx("div", { className: "bg-destructive/10 text-destructive mb-2 flex size-10 items-center justify-center rounded-md", children: _jsx(ShieldAlert, {}) }), _jsx(CardTitle, { children: m.admin_required_title }), _jsx(CardDescription, { children: isAdmin
|
|
172
|
+
? interpolate(m.admin_required_org_description, {
|
|
173
|
+
organization: displayName,
|
|
174
|
+
})
|
|
175
|
+
: m.admin_required_no_permission })] }), _jsxs(CardContent, { className: "space-y-3", children: [invitation ? (_jsx("p", { className: "text-muted-foreground text-sm", children: interpolate(m.admin_required_invite_found, {
|
|
176
|
+
organization: displayName,
|
|
177
|
+
}) })) : (_jsx("p", { className: "text-muted-foreground text-sm", children: m.admin_required_contact_description })), resolvedContactEmail ? (_jsxs("div", { className: "bg-muted/50 flex items-center justify-between gap-3 rounded-md border px-3 py-2 text-sm", children: [_jsxs("span", { className: "flex min-w-0 items-center gap-2 font-medium", children: [_jsx(Mail, { className: "text-muted-foreground size-4 shrink-0" }), _jsx("span", { className: "truncate", children: resolvedContactEmail })] }), _jsx(CopyButton, { value: resolvedContactEmail, valueDescription: resolvedContactEmail, variant: "ghost", className: "shrink-0", messages: {
|
|
178
|
+
copy: m.admin_required_copy_email,
|
|
179
|
+
copied: m.admin_required_copied_email,
|
|
180
|
+
} })] })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }), _jsx(CardFooter, { className: "flex flex-wrap gap-2", children: invitation ? (_jsxs(Button, { onClick: acceptInvitation, disabled: accepting, children: [accepting ? (_jsx(Loader2, { className: "size-4 animate-spin" })) : (_jsx(Check, { className: "size-4" })), accepting
|
|
181
|
+
? m.admin_required_accepting_invite
|
|
182
|
+
: m.admin_required_accept_invite] })) : null })] }) }));
|
|
183
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
// @ts-nocheck
|
|
3
2
|
import { useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
4
3
|
import { useNavigate, useRouter, } from "@tanstack/react-router";
|
|
5
4
|
import {} from "@tanstack/react-table";
|
|
@@ -380,7 +380,17 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
380
380
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
381
381
|
readonly id: import("effect/Schema").String;
|
|
382
382
|
readonly key: import("effect/Schema").String;
|
|
383
|
-
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError | typeof import("../extra/schema").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"
|
|
383
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError | typeof import("../extra/schema").ExtraBadRequest>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getOrganizationPublicProfile", "GET", "/api/auth/organization-profile", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
384
|
+
readonly organizationId: import("effect/Schema").String;
|
|
385
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
386
|
+
readonly id: import("effect/Schema").String;
|
|
387
|
+
readonly name: import("effect/Schema").String;
|
|
388
|
+
readonly slug: import("effect/Schema").String;
|
|
389
|
+
readonly displayName: import("effect/Schema").String;
|
|
390
|
+
readonly contactEmail: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
391
|
+
readonly logo: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
392
|
+
readonly icon: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
393
|
+
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getProjectPublicConfig", "GET", "/api/auth/project-config", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
384
394
|
readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
385
395
|
readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
386
396
|
readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
@@ -1,60 +1,29 @@
|
|
|
1
1
|
import { apiKeyClient } from "@better-auth/api-key/client";
|
|
2
|
-
import { adminClient, emailOTPClient, genericOAuthClient, lastLoginMethodClient, organizationClient, twoFactorClient } from "better-auth/client/plugins";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
session: {
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { adminClient, emailOTPClient, genericOAuthClient, inferAdditionalFields, lastLoginMethodClient, organizationClient, twoFactorClient } from "better-auth/client/plugins";
|
|
3
|
+
import { type ReactAuthClient } from "better-auth/react";
|
|
4
|
+
declare const additionalFields: {
|
|
5
|
+
readonly session: {
|
|
6
|
+
readonly impersonatedByOrganizationId: {
|
|
7
|
+
readonly type: "string";
|
|
8
|
+
readonly required: false;
|
|
9
|
+
readonly input: false;
|
|
10
|
+
};
|
|
8
11
|
};
|
|
9
|
-
user: {
|
|
10
|
-
id: string;
|
|
11
|
-
name: string;
|
|
12
|
-
email: string;
|
|
13
|
-
image?: string | null | undefined;
|
|
14
|
-
role?: string | null | undefined;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
type Query<T> = {
|
|
18
|
-
data: T | null | undefined;
|
|
19
|
-
isPending: boolean;
|
|
20
|
-
refetch: () => Promise<unknown>;
|
|
21
12
|
};
|
|
22
|
-
type
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
data: Session | null;
|
|
36
|
-
error: unknown;
|
|
37
|
-
}>;
|
|
38
|
-
organization: {
|
|
39
|
-
setActive: (input: {
|
|
40
|
-
organizationId: string;
|
|
41
|
-
}) => Promise<{
|
|
42
|
-
data: unknown;
|
|
43
|
-
error: unknown;
|
|
44
|
-
}>;
|
|
45
|
-
};
|
|
46
|
-
useSession: () => Query<Session>;
|
|
47
|
-
useActiveOrganization: () => Query<{
|
|
48
|
-
id: string;
|
|
49
|
-
name: string;
|
|
50
|
-
slug: string;
|
|
51
|
-
createdAt: Date | string;
|
|
52
|
-
members: unknown[];
|
|
53
|
-
invitations: unknown[];
|
|
54
|
-
}>;
|
|
55
|
-
useActiveMemberRole: () => Query<{
|
|
56
|
-
role: string;
|
|
57
|
-
}>;
|
|
13
|
+
type AuthUiClientPlugins = [
|
|
14
|
+
ReturnType<typeof inferAdditionalFields<never, typeof additionalFields>>,
|
|
15
|
+
ReturnType<typeof adminClient<{}>>,
|
|
16
|
+
ReturnType<typeof emailOTPClient>,
|
|
17
|
+
ReturnType<typeof lastLoginMethodClient>,
|
|
18
|
+
ReturnType<typeof organizationClient<{}>>,
|
|
19
|
+
ReturnType<typeof twoFactorClient>,
|
|
20
|
+
ReturnType<typeof apiKeyClient>,
|
|
21
|
+
ReturnType<typeof genericOAuthClient>
|
|
22
|
+
];
|
|
23
|
+
type AuthUiClientOptions = {
|
|
24
|
+
baseURL?: string | undefined;
|
|
25
|
+
plugins: AuthUiClientPlugins;
|
|
58
26
|
};
|
|
59
|
-
export
|
|
27
|
+
export type AuthUiClient = ReactAuthClient<AuthUiClientOptions>;
|
|
28
|
+
export declare const createAuthUiClient: (baseUrl?: string | undefined) => ReactAuthClient<AuthUiClientOptions>;
|
|
60
29
|
export {};
|
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
import { apiKeyClient } from "@better-auth/api-key/client";
|
|
2
|
-
import { adminClient, emailOTPClient, genericOAuthClient, lastLoginMethodClient, organizationClient, twoFactorClient, } from "better-auth/client/plugins";
|
|
2
|
+
import { adminClient, emailOTPClient, genericOAuthClient, inferAdditionalFields, lastLoginMethodClient, organizationClient, twoFactorClient, } from "better-auth/client/plugins";
|
|
3
3
|
import { createAuthClient } from "better-auth/react";
|
|
4
|
+
const additionalFields = {
|
|
5
|
+
session: {
|
|
6
|
+
impersonatedByOrganizationId: {
|
|
7
|
+
type: "string",
|
|
8
|
+
required: false,
|
|
9
|
+
input: false,
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
const authUiClientPlugins = [
|
|
14
|
+
inferAdditionalFields(additionalFields),
|
|
15
|
+
adminClient(),
|
|
16
|
+
emailOTPClient(),
|
|
17
|
+
lastLoginMethodClient({
|
|
18
|
+
cookieName: "krakstack-auth.last_used_login_method",
|
|
19
|
+
}),
|
|
20
|
+
organizationClient(),
|
|
21
|
+
twoFactorClient(),
|
|
22
|
+
apiKeyClient(),
|
|
23
|
+
genericOAuthClient(),
|
|
24
|
+
];
|
|
4
25
|
export const createAuthUiClient = (baseUrl) => createAuthClient({
|
|
5
26
|
...(baseUrl ? { baseURL: baseUrl } : {}),
|
|
6
|
-
plugins:
|
|
7
|
-
adminClient(),
|
|
8
|
-
emailOTPClient(),
|
|
9
|
-
lastLoginMethodClient({
|
|
10
|
-
cookieName: "krakstack-auth.last_used_login_method",
|
|
11
|
-
}),
|
|
12
|
-
organizationClient(),
|
|
13
|
-
twoFactorClient(),
|
|
14
|
-
apiKeyClient(),
|
|
15
|
-
genericOAuthClient(),
|
|
16
|
-
],
|
|
27
|
+
plugins: authUiClientPlugins,
|
|
17
28
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
// @ts-nocheck
|
|
3
2
|
import { useAtomSuspense } from "@effect/atom-react";
|
|
4
3
|
import { Link, useNavigate, useRouterState } from "@tanstack/react-router";
|
|
4
|
+
import { Schema } from "effect";
|
|
5
5
|
import { Atom, AsyncResult } from "effect/unstable/reactivity";
|
|
6
6
|
import { REGEXP_ONLY_DIGITS } from "input-otp";
|
|
7
7
|
import { KeyRound, Mail } from "lucide-react";
|
|
@@ -14,6 +14,7 @@ import { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, } from "@/com
|
|
|
14
14
|
import { authClientApi } from "./auth-client-api";
|
|
15
15
|
import { useKrakstackAuth } from "./auth-provider";
|
|
16
16
|
import { cn } from "./utils";
|
|
17
|
+
import { ExtraProjectPublicConfig as ExtraProjectPublicConfigSchema, } from "../extra/schema";
|
|
17
18
|
const EMAIL_OTP_RESEND_COOLDOWN_SECONDS = 60;
|
|
18
19
|
const defaultMessages = {
|
|
19
20
|
en: {
|
|
@@ -157,7 +158,9 @@ const useAuthProjectConfig = (baseUrl, searchString, projectConfig) => {
|
|
|
157
158
|
})
|
|
158
159
|
: Atom.make(AsyncResult.success(projectConfig));
|
|
159
160
|
const result = useAtomSuspense(atom, { suspendOnWaiting: true });
|
|
160
|
-
return result.value
|
|
161
|
+
return result.value === null
|
|
162
|
+
? null
|
|
163
|
+
: Schema.decodeUnknownSync(ExtraProjectPublicConfigSchema)(result.value);
|
|
161
164
|
};
|
|
162
165
|
const text = (value, params) => Object.entries(params ?? {}).reduce((current, [key, replacement]) => current.replace(`{${key}}`, replacement), value);
|
|
163
166
|
const authLinkClassName = cn(buttonVariants({ variant: "link" }), "h-auto px-0 align-baseline");
|
|
@@ -173,14 +176,14 @@ export function Signin(props) {
|
|
|
173
176
|
const redirectTarget = getRedirectTarget(searchString, projectConfig?.authDomain, projectConfig?.rootDomain);
|
|
174
177
|
const socialRedirectTarget = getSocialRedirectTarget(searchString, projectConfig?.authDomain, projectConfig?.rootDomain);
|
|
175
178
|
const oauthQuery = getOAuthQuery(searchString);
|
|
176
|
-
const authOptions = projectConfig?.authOptions
|
|
179
|
+
const authOptions = projectConfig?.authOptions;
|
|
177
180
|
const onNavigate = (target) => navigateTarget(target, navigate);
|
|
178
181
|
const onTwoFactorRedirect = (href) => navigate({ href });
|
|
179
182
|
const options = {
|
|
180
|
-
emailPassword: authOptions
|
|
181
|
-
emailOtp: authOptions
|
|
182
|
-
google: authOptions
|
|
183
|
-
signUp: authOptions
|
|
183
|
+
emailPassword: authOptions?.emailPassword ?? true,
|
|
184
|
+
emailOtp: authOptions?.emailOtp ?? true,
|
|
185
|
+
google: authOptions?.google ?? true,
|
|
186
|
+
signUp: authOptions?.signUp ?? true,
|
|
184
187
|
};
|
|
185
188
|
const [emailSubmitted, setEmailSubmitted] = useState(false);
|
|
186
189
|
const [authMethod, setAuthMethod] = useState(() => lastLoginMethodToAuthMethod(authClient.getLastUsedLoginMethod?.()));
|
|
@@ -373,13 +376,13 @@ export function Signup(props) {
|
|
|
373
376
|
});
|
|
374
377
|
const projectConfig = useAuthProjectConfig(baseUrl, searchString, providedProjectConfig);
|
|
375
378
|
const redirectTarget = getRedirectTarget(searchString, projectConfig?.authDomain, projectConfig?.rootDomain);
|
|
376
|
-
const authOptions = projectConfig?.authOptions
|
|
379
|
+
const authOptions = projectConfig?.authOptions;
|
|
377
380
|
const onNavigate = (target) => navigate({ href: target });
|
|
378
381
|
const onVerifyEmail = (email) => navigate({ to: "/verify-email", search: { email } });
|
|
379
382
|
const options = {
|
|
380
|
-
google: authOptions
|
|
381
|
-
signUp: authOptions
|
|
382
|
-
signUpName: authOptions
|
|
383
|
+
google: authOptions?.google ?? true,
|
|
384
|
+
signUp: authOptions?.signUp ?? true,
|
|
385
|
+
signUpName: authOptions?.signUpName ?? true,
|
|
383
386
|
};
|
|
384
387
|
const form = useAppForm({
|
|
385
388
|
defaultValues: { name: "", email: "", password: "" },
|
|
@@ -566,7 +569,7 @@ export function TwoFactor(props) {
|
|
|
566
569
|
}
|
|
567
570
|
const OtpInput = ({ field, label }) => {
|
|
568
571
|
const invalid = !field.state.meta.isValid;
|
|
569
|
-
return (_jsxs(Field, { "data-invalid": invalid, children: [_jsx(FieldLabel, { htmlFor: field.name, children: label }), _jsxs(InputOTP, { id: field.name, name: field.name, maxLength: 6, value: field.state.value ?? "", onChange: (value) => field.handleChange(value), onBlur: field.handleBlur, autoComplete: "one-time-code", inputMode: "numeric", pattern: REGEXP_ONLY_DIGITS, required: true, children: [_jsxs(InputOTPGroup, { children: [_jsx(InputOTPSlot, { index: 0, "aria-invalid": invalid }), _jsx(InputOTPSlot, { index: 1, "aria-invalid": invalid }), _jsx(InputOTPSlot, { index: 2, "aria-invalid": invalid })] }), _jsx(InputOTPSeparator, {}), _jsxs(InputOTPGroup, { children: [_jsx(InputOTPSlot, { index: 3, "aria-invalid": invalid }), _jsx(InputOTPSlot, { index: 4, "aria-invalid": invalid }), _jsx(InputOTPSlot, { index: 5, "aria-invalid": invalid })] })] }), _jsx(FieldError, { errors: field.getMeta().errors })] }));
|
|
572
|
+
return (_jsxs(Field, { "data-invalid": invalid, children: [_jsx(FieldLabel, { htmlFor: field.name, children: label }), _jsxs(InputOTP, { id: field.name, name: field.name, maxLength: 6, value: field.state.value ?? "", onChange: (value) => field.handleChange(value), onBlur: field.handleBlur, autoComplete: "one-time-code", inputMode: "numeric", pattern: REGEXP_ONLY_DIGITS, required: true, children: [_jsxs(InputOTPGroup, { children: [_jsx(InputOTPSlot, { index: 0, "aria-invalid": invalid }), _jsx(InputOTPSlot, { index: 1, "aria-invalid": invalid }), _jsx(InputOTPSlot, { index: 2, "aria-invalid": invalid })] }), _jsx(InputOTPSeparator, {}), _jsxs(InputOTPGroup, { children: [_jsx(InputOTPSlot, { index: 3, "aria-invalid": invalid }), _jsx(InputOTPSlot, { index: 4, "aria-invalid": invalid }), _jsx(InputOTPSlot, { index: 5, "aria-invalid": invalid })] })] }), _jsx(FieldError, { errors: field.getMeta().errors ?? [] })] }));
|
|
570
573
|
};
|
|
571
574
|
const Divider = ({ label }) => (_jsxs("div", { className: "text-muted-foreground flex items-center gap-3 text-xs", children: [_jsx("span", { className: "bg-border h-px flex-1" }), label, _jsx("span", { className: "bg-border h-px flex-1" })] }));
|
|
572
575
|
const GoogleLogo = () => (_jsxs("svg", { "aria-hidden": "true", className: "size-[18px]", viewBox: "0 0 18 18", xmlns: "http://www.w3.org/2000/svg", children: [_jsx("path", { d: "M17.64 9.204c0-.638-.057-1.252-.164-1.84H9v3.481h4.844a4.14 4.14 0 0 1-1.796 2.716v2.259h2.908c1.702-1.567 2.684-3.874 2.684-6.616Z", fill: "#4285F4" }), _jsx("path", { d: "M9 18c2.43 0 4.467-.806 5.956-2.18l-2.908-2.259c-.806.54-1.837.86-3.048.86-2.344 0-4.328-1.583-5.036-3.711H.957v2.332A8.997 8.997 0 0 0 9 18Z", fill: "#34A853" }), _jsx("path", { d: "M3.964 10.71A5.41 5.41 0 0 1 3.682 9c0-.593.102-1.17.282-1.71V4.958H.957A8.996 8.996 0 0 0 0 9c0 1.452.348 2.827.957 4.042l3.007-2.332Z", fill: "#FBBC05" }), _jsx("path", { d: "M9 3.58c1.321 0 2.508.454 3.44 1.346l2.582-2.58C13.463.891 11.426 0 9 0A8.997 8.997 0 0 0 .957 4.958L3.964 7.29C4.672 5.162 6.656 3.58 9 3.58Z", fill: "#EA4335" })] }));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { KrakstackAuthProvider, useAuthClient, useKrakstackAuth, useKrakstackAuthProjectConfig, } from "./auth-provider";
|
|
2
2
|
export { createAuthUiClient } from "./auth-client";
|
|
3
3
|
export { OrganizationSwitcher } from "./organization-switcher";
|
|
4
|
+
export { AdminRequired } from "./admin-required";
|
|
4
5
|
export { ResetPassword, Signin, Signup, TwoFactor } from "./auth-forms";
|
|
5
6
|
export { UserButton } from "./user-button";
|
|
6
7
|
export { AdminOrganizationsTable } from "./admin-organizations";
|
|
@@ -11,3 +12,4 @@ export type { KrakstackAuthContextValue, KrakstackAuthLocale, KrakstackAuthProvi
|
|
|
11
12
|
export type { OrganizationSwitcherDialog, OrganizationSwitcherProps, } from "./organization-switcher";
|
|
12
13
|
export type { UserButtonDialog } from "./user-button";
|
|
13
14
|
export type { AuthUiClient } from "./auth-client";
|
|
15
|
+
export type { AdminRequiredMessages, AdminRequiredProps } from "./admin-required";
|
package/dist/components/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { KrakstackAuthProvider, useAuthClient, useKrakstackAuth, useKrakstackAuthProjectConfig, } from "./auth-provider";
|
|
2
2
|
export { createAuthUiClient } from "./auth-client";
|
|
3
3
|
export { OrganizationSwitcher } from "./organization-switcher";
|
|
4
|
+
export { AdminRequired } from "./admin-required";
|
|
4
5
|
export { ResetPassword, Signin, Signup, TwoFactor } from "./auth-forms";
|
|
5
6
|
export { UserButton } from "./user-button";
|
|
6
7
|
export { AdminOrganizationsTable } from "./admin-organizations";
|
|
@@ -39,6 +39,8 @@ declare const messages: {
|
|
|
39
39
|
readonly organization_logo_upload_error: "Could not upload the organization logo.";
|
|
40
40
|
readonly organization_member_email: "Email";
|
|
41
41
|
readonly organization_member_joined: "Joined";
|
|
42
|
+
readonly organization_member_leave: "Leave organization";
|
|
43
|
+
readonly organization_member_leave_error: "Could not leave the organization.";
|
|
42
44
|
readonly organization_member_remove: "Remove member";
|
|
43
45
|
readonly organization_member_remove_error: "Could not remove the member.";
|
|
44
46
|
readonly organization_member_role: "Role";
|
|
@@ -119,6 +121,8 @@ declare const messages: {
|
|
|
119
121
|
readonly organization_logo_upload_error: "Impossible de téléverser le logo de l'organisation.";
|
|
120
122
|
readonly organization_member_email: "Courriel";
|
|
121
123
|
readonly organization_member_joined: "Arrivée";
|
|
124
|
+
readonly organization_member_leave: "Quitter l'organisation";
|
|
125
|
+
readonly organization_member_leave_error: "Impossible de quitter l'organisation.";
|
|
122
126
|
readonly organization_member_remove: "Retirer le membre";
|
|
123
127
|
readonly organization_member_remove_error: "Impossible de retirer le membre.";
|
|
124
128
|
readonly organization_member_role: "Rôle";
|
|
@@ -4,7 +4,7 @@ import { useStore } from "@tanstack/react-form";
|
|
|
4
4
|
import {} from "@tanstack/react-table";
|
|
5
5
|
import { Effect, Schema } from "effect";
|
|
6
6
|
import { AsyncResult, Atom } from "effect/unstable/reactivity";
|
|
7
|
-
import { Building2, Check, ChevronsUpDown, Copy, KeyRound, Mail, PencilIcon, Plus, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
|
|
7
|
+
import { Building2, Check, ChevronsUpDown, Copy, KeyRound, LogOut, Mail, PencilIcon, Plus, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
|
|
8
8
|
import { createContext, useContext, useEffect, useEffectEvent, useRef, useState, } from "react";
|
|
9
9
|
import { DataTable, DataTableRelationshipCell, } from "@/components/ui/data-table";
|
|
10
10
|
import { EditingLocaleSwitcher } from "@/components/ui/editing-locale-switcher";
|
|
@@ -61,6 +61,8 @@ const messages = {
|
|
|
61
61
|
organization_logo_upload_error: "Could not upload the organization logo.",
|
|
62
62
|
organization_member_email: "Email",
|
|
63
63
|
organization_member_joined: "Joined",
|
|
64
|
+
organization_member_leave: "Leave organization",
|
|
65
|
+
organization_member_leave_error: "Could not leave the organization.",
|
|
64
66
|
organization_member_remove: "Remove member",
|
|
65
67
|
organization_member_remove_error: "Could not remove the member.",
|
|
66
68
|
organization_member_role: "Role",
|
|
@@ -141,6 +143,8 @@ const messages = {
|
|
|
141
143
|
organization_logo_upload_error: "Impossible de téléverser le logo de l'organisation.",
|
|
142
144
|
organization_member_email: "Courriel",
|
|
143
145
|
organization_member_joined: "Arrivée",
|
|
146
|
+
organization_member_leave: "Quitter l'organisation",
|
|
147
|
+
organization_member_leave_error: "Impossible de quitter l'organisation.",
|
|
144
148
|
organization_member_remove: "Retirer le membre",
|
|
145
149
|
organization_member_remove_error: "Impossible de retirer le membre.",
|
|
146
150
|
organization_member_role: "Rôle",
|
|
@@ -204,6 +208,10 @@ const organizationMessageFns = (labels) => new Proxy({}, {
|
|
|
204
208
|
});
|
|
205
209
|
const OrganizationMessagesContext = createContext(organizationMessageFns(organizationSwitcherMessages()));
|
|
206
210
|
const useOrganizationMessages = () => useContext(OrganizationMessagesContext);
|
|
211
|
+
const normalizeInvitationRole = (role) => {
|
|
212
|
+
const normalized = normalizeOrganizationRole(role);
|
|
213
|
+
return normalized === "support" ? "member" : normalized;
|
|
214
|
+
};
|
|
207
215
|
const userInvitationsAtom = Atom.family((authClient) => Atom.keepAlive(Atom.make(Effect.tryPromise({
|
|
208
216
|
try: async () => {
|
|
209
217
|
const result = await authClient.organization.listUserInvitations({});
|
|
@@ -215,7 +223,10 @@ const userInvitationsAtom = Atom.family((authClient) => Atom.keepAlive(Atom.make
|
|
|
215
223
|
},
|
|
216
224
|
catch: (error) => error,
|
|
217
225
|
}))));
|
|
218
|
-
const emptyUserInvitationsAtom = Atom.make(Effect.
|
|
226
|
+
const emptyUserInvitationsAtom = Atom.make(Effect.try({
|
|
227
|
+
try: () => [],
|
|
228
|
+
catch: (error) => error,
|
|
229
|
+
}));
|
|
219
230
|
const organizationMembersAtom = Atom.family((authClient) => Atom.family((organizationId) => Atom.keepAlive(Atom.make(Effect.tryPromise({
|
|
220
231
|
try: async () => {
|
|
221
232
|
const [membersResult, invitationsResult] = await Promise.all([
|
|
@@ -413,6 +424,7 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
413
424
|
const loadingUserInvitations = invitationsResult._tag === "Initial";
|
|
414
425
|
const activeMemberRole = normalizeOrganizationRole(activeOrganization.data?.members.find((member) => member.userId === session.data?.user.id)?.role);
|
|
415
426
|
const canManageApiKeys = activeMemberRole === "owner" || activeMemberRole === "admin";
|
|
427
|
+
const canUpdateOrganization = canManageApiKeys;
|
|
416
428
|
const setDialog = (next) => {
|
|
417
429
|
const nextDialog = typeof next === "function" ? next(dialog) : next;
|
|
418
430
|
if (nextDialog === dialog)
|
|
@@ -481,9 +493,12 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
481
493
|
? m.organization_switcher_no_other_organizations()
|
|
482
494
|
: m.organization_switcher_empty() })) : null, !locked ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { onClick: openCreate, children: [_jsx(Plus, {}), m.organization_create_title()] }), _jsxs(DropdownMenuItem, { onClick: () => {
|
|
483
495
|
setDialog("invitations");
|
|
484
|
-
}, children: [_jsx(Mail, {}), _jsxs("span", { className: "flex flex-1 items-center justify-between gap-3", children: [m.organization_user_invitations_title(), userInvitations.length ? (_jsx(Badge, { variant: "secondary", children: userInvitations.length })) : null] })] })] })) : null, activeOrganization.data ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}),
|
|
485
|
-
|
|
486
|
-
|
|
496
|
+
}, children: [_jsx(Mail, {}), _jsxs("span", { className: "flex flex-1 items-center justify-between gap-3", children: [m.organization_user_invitations_title(), userInvitations.length ? (_jsx(Badge, { variant: "secondary", children: userInvitations.length })) : null] })] })] })) : null, activeOrganization.data ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), (() => {
|
|
497
|
+
const organizationId = activeOrganization.data.id;
|
|
498
|
+
return (_jsxs(DropdownMenuItem, { onClick: () => {
|
|
499
|
+
void navigator.clipboard.writeText(organizationId);
|
|
500
|
+
}, children: [_jsx(Copy, {}), m.organization_copy_id()] }));
|
|
501
|
+
})(), canUpdateOrganization ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("manage"), children: [_jsx(PencilIcon, {}), m.organization_switcher_manage()] })) : null, _jsxs(DropdownMenuItem, { onClick: () => setDialog("members"), children: [_jsx(Users, {}), m.organization_members_title()] }), canManageApiKeys ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] })) : null] })) : null] }) })] })), _jsx(Dialog, { open: dialog === "create", onOpenChange: (open) => {
|
|
487
502
|
setDialog((current) => open ? "create" : current === "create" ? null : current);
|
|
488
503
|
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_create_title() }), _jsx(DialogDescription, { children: m.organization_create_description() })] }), _jsx(Separator, {}), _jsx(CreateOrganizationSection, { authClient: authClient, baseUrl: baseUrl, onCreated: async (organization) => {
|
|
489
504
|
setDialog(null);
|
|
@@ -495,15 +510,22 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
495
510
|
onCreate?.(organization);
|
|
496
511
|
onChange?.(organization);
|
|
497
512
|
}
|
|
498
|
-
} })] }) }), _jsx(Dialog, { open: dialog === "manage", onOpenChange: (open) => {
|
|
513
|
+
} })] }) }), _jsx(Dialog, { open: dialog === "manage" && canUpdateOrganization, onOpenChange: (open) => {
|
|
499
514
|
setDialog((current) => open ? "manage" : current === "manage" ? null : current);
|
|
500
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_switcher_manage() }), _jsx(DialogDescription, { children: m.organization_edit_description() })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(EditOrganizationSection, { authClient: authClient, baseUrl: baseUrl, organization: activeOrganization.data, onUpdated: refresh })) : null] }) }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
|
|
515
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_switcher_manage() }), _jsx(DialogDescription, { children: m.organization_edit_description() })] }), _jsx(Separator, {}), activeOrganization.data && canUpdateOrganization ? (_jsx(EditOrganizationSection, { authClient: authClient, baseUrl: baseUrl, organization: activeOrganization.data, onUpdated: refresh })) : null] }) }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
|
|
501
516
|
setDialog((current) => open ? "members" : current === "members" ? null : current);
|
|
502
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_members_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationMembersManager, { authClient: authClient, baseUrl: baseUrl, organization: activeOrganization.data, currentUserId: session.data.user.id, active: dialog === "members"
|
|
517
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_members_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationMembersManager, { authClient: authClient, baseUrl: baseUrl, organization: activeOrganization.data, currentUserId: session.data.user.id, active: dialog === "members", onLeft: async () => {
|
|
518
|
+
setDialog(null);
|
|
519
|
+
auth?.refreshAuth();
|
|
520
|
+
await refresh();
|
|
521
|
+
onChange?.(null);
|
|
522
|
+
} })) : null] }) }), _jsx(Dialog, { open: dialog === "apiKeys" && canManageApiKeys, onOpenChange: (open) => {
|
|
503
523
|
setDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
504
524
|
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_api_keys_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationApiKeyManager, { authClient: authClient, organization: activeOrganization.data, active: dialog === "apiKeys" && canManageApiKeys })) : null] }) }), _jsx(Dialog, { open: dialog === "invitations" && !locked, onOpenChange: (open) => {
|
|
505
525
|
setDialog((current) => open ? "invitations" : current === "invitations" ? null : current);
|
|
506
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_user_invitations_title() }), _jsx(DialogDescription, { children: m.organization_user_invitations_description() })] }), _jsx(Separator, {}), _jsx(UserInvitationsManager, { authClient: authClient, invitations: userInvitations, loading: loadingUserInvitations, error: userInvitationsError,
|
|
526
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_user_invitations_title() }), _jsx(DialogDescription, { children: m.organization_user_invitations_description() })] }), _jsx(Separator, {}), _jsx(UserInvitationsManager, { authClient: authClient, invitations: userInvitations, loading: loadingUserInvitations, error: userInvitationsError, ...(activeOrganization.data
|
|
527
|
+
? { activeOrganizationId: activeOrganization.data.id }
|
|
528
|
+
: {}), onActionComplete: refreshAfterInvitationAction })] }) })] }));
|
|
507
529
|
}
|
|
508
530
|
function UserInvitationsManager({ authClient, invitations, loading, error, activeOrganizationId, onActionComplete, }) {
|
|
509
531
|
const m = useOrganizationMessages();
|
|
@@ -647,16 +669,6 @@ function EditOrganizationSection({ authClient, baseUrl, organization, onUpdated,
|
|
|
647
669
|
suggestedHeight: 512,
|
|
648
670
|
} })) }), _jsx(form.AppField, { name: "frContactEmail", children: (field) => (_jsx(field.TextField, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" })) }), _jsx(form.AppField, { name: "frLocation", children: (field) => (_jsx(field.TextField, { label: m.organization_location() })) })] })), _jsx(form.FormError, {}), _jsx(form.SubmitButton, {})] }) }) }));
|
|
649
671
|
}
|
|
650
|
-
function CreateOrganizationSlugAutoFill({ form, }) {
|
|
651
|
-
const name = useStore(form.store, (state) => state.values.name);
|
|
652
|
-
const slugIsDirty = useStore(form.store, (state) => state.fieldMeta.slug?.isDirty ?? false);
|
|
653
|
-
useEffect(() => {
|
|
654
|
-
if (!slugIsDirty) {
|
|
655
|
-
form.setFieldValue("slug", slugify(name), { dontUpdateMeta: true });
|
|
656
|
-
}
|
|
657
|
-
}, [form, name, slugIsDirty]);
|
|
658
|
-
return null;
|
|
659
|
-
}
|
|
660
672
|
function CreateOrganizationSection({ authClient, baseUrl, onCreated, }) {
|
|
661
673
|
const m = useOrganizationMessages();
|
|
662
674
|
const uploadImage = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadUserImage"), { mode: "promise" });
|
|
@@ -713,11 +725,18 @@ function CreateOrganizationSection({ authClient, baseUrl, onCreated, }) {
|
|
|
713
725
|
}
|
|
714
726
|
},
|
|
715
727
|
});
|
|
728
|
+
const name = useStore(form.store, (state) => state.values.name);
|
|
729
|
+
const slugIsDirty = useStore(form.store, (state) => state.fieldMeta.slug?.isDirty ?? false);
|
|
730
|
+
useEffect(() => {
|
|
731
|
+
if (!slugIsDirty) {
|
|
732
|
+
form.setFieldValue("slug", slugify(name), { dontUpdateMeta: true });
|
|
733
|
+
}
|
|
734
|
+
}, [form, name, slugIsDirty]);
|
|
716
735
|
return (_jsx("section", { className: "flex flex-col gap-4", children: _jsx(form.AppForm, { children: _jsxs("form", { className: "flex max-w-xl flex-col gap-4", onSubmit: (event) => {
|
|
717
736
|
event.preventDefault();
|
|
718
737
|
event.stopPropagation();
|
|
719
738
|
form.handleSubmit();
|
|
720
|
-
}, children: [_jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.organization_name(), required: true })) }), _jsx(form.AppField, { name: "slug", children: (field) => (_jsx(field.TextField, { label: m.organization_slug(), description: m.organization_slug_description() })) }), _jsx(
|
|
739
|
+
}, children: [_jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.organization_name(), required: true })) }), _jsx(form.AppField, { name: "slug", children: (field) => (_jsx(field.TextField, { label: m.organization_slug(), description: m.organization_slug_description() })) }), _jsx(Separator, { className: "my-2" }), editingLocale === "en" ? (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "en", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "enName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name(), required: true })) }), _jsx(form.AppField, { name: "enLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), size: {
|
|
721
740
|
width: 175,
|
|
722
741
|
height: 50,
|
|
723
742
|
suggestedWidth: 350,
|
|
@@ -746,7 +765,7 @@ function OrganizationTranslationHeader({ locale, editingLocale, onEditingLocaleC
|
|
|
746
765
|
: m.organization_translation_french();
|
|
747
766
|
return (_jsxs("div", { className: "flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: title }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_translation_description() })] }), _jsx(EditingLocaleSwitcher, { value: editingLocale, onValueChange: onEditingLocaleChange })] }));
|
|
748
767
|
}
|
|
749
|
-
function OrganizationMembersManager({ authClient, baseUrl, organization, currentUserId, active, }) {
|
|
768
|
+
function OrganizationMembersManager({ authClient, baseUrl, organization, currentUserId, active, onLeft, }) {
|
|
750
769
|
const m = useOrganizationMessages();
|
|
751
770
|
const hasOpened = useOpenedOnce(active);
|
|
752
771
|
const membersAtom = hasOpened
|
|
@@ -756,6 +775,7 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
756
775
|
const refreshMembers = useAtomRefresh(membersAtom);
|
|
757
776
|
const [error, setError] = useState(null);
|
|
758
777
|
const [cancellingInvitationId, setCancellingInvitationId] = useState(null);
|
|
778
|
+
const [leavingOrganization, setLeavingOrganization] = useState(false);
|
|
759
779
|
const membersData = AsyncResult.match(membersResult, {
|
|
760
780
|
onInitial: () => ({ members: [], invitations: [] }),
|
|
761
781
|
onFailure: () => ({ members: [], invitations: [] }),
|
|
@@ -779,6 +799,7 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
779
799
|
"owner",
|
|
780
800
|
"admin",
|
|
781
801
|
]);
|
|
802
|
+
const canInviteMembers = canChangeMemberRoles;
|
|
782
803
|
const canRemoveMembers = canChangeMemberRoles;
|
|
783
804
|
const inviteForm = useAppForm({
|
|
784
805
|
defaultValues: { email: "", role: "member" },
|
|
@@ -786,7 +807,7 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
786
807
|
formApi.setErrorMap({ onSubmit: undefined });
|
|
787
808
|
const result = await authClient.organization.inviteMember({
|
|
788
809
|
email: value.email.trim(),
|
|
789
|
-
role:
|
|
810
|
+
role: normalizeInvitationRole(value.role),
|
|
790
811
|
organizationId: organization.id,
|
|
791
812
|
});
|
|
792
813
|
if (result.error) {
|
|
@@ -836,6 +857,19 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
836
857
|
}
|
|
837
858
|
refreshMembers();
|
|
838
859
|
};
|
|
860
|
+
const leaveOrganization = async () => {
|
|
861
|
+
setLeavingOrganization(true);
|
|
862
|
+
setError(null);
|
|
863
|
+
const result = await authClient.organization.leave({
|
|
864
|
+
organizationId: organization.id,
|
|
865
|
+
});
|
|
866
|
+
setLeavingOrganization(false);
|
|
867
|
+
if (result.error) {
|
|
868
|
+
setError(result.error.message ?? m.organization_member_leave_error());
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
await onLeft();
|
|
872
|
+
};
|
|
839
873
|
const cancelInvitation = async (invitation) => {
|
|
840
874
|
setCancellingInvitationId(invitation.id);
|
|
841
875
|
setError(null);
|
|
@@ -849,14 +883,14 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
849
883
|
}
|
|
850
884
|
refreshMembers();
|
|
851
885
|
};
|
|
852
|
-
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-5", children: [_jsx(inviteForm.AppForm, { children: _jsxs("form", { className: "grid gap-4 rounded-lg border p-4 sm:grid-cols-[minmax(0,1fr)_12rem_auto] sm:items-end", onSubmit: (event) => {
|
|
886
|
+
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-5", children: [canInviteMembers ? (_jsx(inviteForm.AppForm, { children: _jsxs("form", { className: "grid gap-4 rounded-lg border p-4 sm:grid-cols-[minmax(0,1fr)_12rem_auto] sm:items-end", onSubmit: (event) => {
|
|
853
887
|
event.preventDefault();
|
|
854
888
|
event.stopPropagation();
|
|
855
889
|
inviteForm.handleSubmit();
|
|
856
890
|
}, children: [_jsxs("div", { className: "sm:col-span-3", children: [_jsxs("div", { className: "flex items-center gap-2 font-medium", children: [_jsx(UserPlus, { className: "size-4" }), m.organization_invite_member_title()] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_invite_member_description() })] }), _jsx(inviteForm.AppField, { name: "email", children: (field) => (_jsx(field.TextField, { label: m.organization_member_email(), placeholder: "teammate@example.com", type: "email", required: true })) }), _jsx(inviteForm.AppField, { name: "role", children: (field) => (_jsx(field.SelectField, { label: m.organization_member_role(), options: organizationRoles.map((role) => ({
|
|
857
891
|
label: organizationRoleLabel(role, m),
|
|
858
892
|
value: role,
|
|
859
|
-
})) })) }), _jsx("div", { className: "self-end", children: _jsx(inviteForm.SubmitButton, {}) }), _jsx(inviteForm.FormError, {})] }) }), membersError ? (_jsx("p", { className: "text-destructive text-sm", children: membersError })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_members_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_members_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: memberColumns({
|
|
893
|
+
})) })) }), _jsx("div", { className: "self-end", children: _jsx(inviteForm.SubmitButton, {}) }), _jsx(inviteForm.FormError, {})] }) })) : null, membersError ? (_jsx("p", { className: "text-destructive text-sm", children: membersError })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_members_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_members_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: memberColumns({
|
|
860
894
|
m,
|
|
861
895
|
baseUrl,
|
|
862
896
|
canChangeRoles: canChangeMemberRoles,
|
|
@@ -865,6 +899,8 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
865
899
|
m,
|
|
866
900
|
canRemoveMembers,
|
|
867
901
|
currentUserId,
|
|
902
|
+
leavingOrganization,
|
|
903
|
+
onLeave: leaveOrganization,
|
|
868
904
|
onRemove: removeMember,
|
|
869
905
|
}) }) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_invitations_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_invitations_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: invitationColumns({
|
|
870
906
|
m,
|
|
@@ -899,7 +935,7 @@ const memberColumns = ({ m, baseUrl, canChangeRoles, onRoleChange, }) => [
|
|
|
899
935
|
return (_jsx(DataTableRelationshipCell, { emptyLabel: m.organization_member_role(), manageLabel: m.organization_member_role(), options: organizationRoles.map((role) => ({
|
|
900
936
|
label: organizationRoleLabel(role, m),
|
|
901
937
|
value: role,
|
|
902
|
-
})), value: roleOptions, onAdd: (value) => {
|
|
938
|
+
})), value: roleOptions, from: "/", onAdd: (value) => {
|
|
903
939
|
if (!isOrganizationRole(value))
|
|
904
940
|
return;
|
|
905
941
|
onRoleChange(member, Array.from(new Set([...roles, value])));
|
|
@@ -917,7 +953,14 @@ const memberColumns = ({ m, baseUrl, canChangeRoles, onRoleChange, }) => [
|
|
|
917
953
|
cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(row.original.createdAt) })),
|
|
918
954
|
},
|
|
919
955
|
];
|
|
920
|
-
const memberRowActions = ({ m, canRemoveMembers, currentUserId, onRemove, }) => [
|
|
956
|
+
const memberRowActions = ({ m, canRemoveMembers, currentUserId, leavingOrganization, onLeave, onRemove, }) => [
|
|
957
|
+
{
|
|
958
|
+
name: m.organization_member_leave(),
|
|
959
|
+
icon: _jsx(LogOut, {}),
|
|
960
|
+
variant: "destructive",
|
|
961
|
+
visible: (member) => member.userId === currentUserId && !leavingOrganization,
|
|
962
|
+
onClick: onLeave,
|
|
963
|
+
},
|
|
921
964
|
{
|
|
922
965
|
name: m.organization_member_remove(),
|
|
923
966
|
icon: _jsx(Trash2, {}),
|
|
@@ -10,7 +10,17 @@ export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpA
|
|
|
10
10
|
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
|
|
11
11
|
readonly id: import("effect/Schema").String;
|
|
12
12
|
readonly key: import("effect/Schema").String;
|
|
13
|
-
}>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"
|
|
13
|
+
}>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getOrganizationPublicProfile", "GET", "/auth/organization-profile", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<import("effect/Schema").Struct<{
|
|
14
|
+
readonly organizationId: import("effect/Schema").String;
|
|
15
|
+
}>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
|
|
16
|
+
readonly id: import("effect/Schema").String;
|
|
17
|
+
readonly name: import("effect/Schema").String;
|
|
18
|
+
readonly slug: import("effect/Schema").String;
|
|
19
|
+
readonly displayName: import("effect/Schema").String;
|
|
20
|
+
readonly contactEmail: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
21
|
+
readonly logo: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
22
|
+
readonly icon: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
23
|
+
}>>, HttpApiEndpoint.Json<typeof HttpApiError.NotFound | typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getProjectPublicConfig", "GET", "/auth/project-config", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<import("effect/Schema").Struct<{
|
|
14
24
|
readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
15
25
|
readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
16
26
|
readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
|
package/dist/extra/api.group.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OpenApi } from "effect/unstable/httpapi";
|
|
2
2
|
import { HttpApiEndpoint, HttpApiError, HttpApiGroup, } from "effect/unstable/httpapi";
|
|
3
|
-
import { ExtraBadRequest, ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, ExtraImageUploadMultipartPayload, ExtraOkResponse, ExtraProjectPublicConfig, ExtraProjectPublicConfigQuery, ExtraSetPasswordPayload, ExtraUploadedAsset, ExtraVerifyApiKeyPayload, ExtraVerifyApiKeyResponse, ExtraVerifyPasswordPayload, } from "./schema";
|
|
3
|
+
import { ExtraBadRequest, ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, ExtraImageUploadMultipartPayload, ExtraOkResponse, ExtraOrganizationPublicProfile, ExtraOrganizationPublicProfileQuery, ExtraProjectPublicConfig, ExtraProjectPublicConfigQuery, ExtraSetPasswordPayload, ExtraUploadedAsset, ExtraVerifyApiKeyPayload, ExtraVerifyApiKeyResponse, ExtraVerifyPasswordPayload, } from "./schema";
|
|
4
4
|
export * from "./schema";
|
|
5
5
|
export const ExtraApiGroup = HttpApiGroup.make("authExtra")
|
|
6
6
|
.add(HttpApiEndpoint.get("getProjectPublicConfig", "/auth/project-config", {
|
|
@@ -11,6 +11,15 @@ export const ExtraApiGroup = HttpApiGroup.make("authExtra")
|
|
|
11
11
|
title: "Get project public config",
|
|
12
12
|
summary: "Get host-aware project white-label config",
|
|
13
13
|
description: "Returns resolved public branding and authentication options through the proxied auth API.",
|
|
14
|
+
})))
|
|
15
|
+
.add(HttpApiEndpoint.get("getOrganizationPublicProfile", "/auth/organization-profile", {
|
|
16
|
+
query: ExtraOrganizationPublicProfileQuery,
|
|
17
|
+
success: ExtraOrganizationPublicProfile,
|
|
18
|
+
error: [HttpApiError.NotFound, HttpApiError.InternalServerError],
|
|
19
|
+
}).annotateMerge(OpenApi.annotations({
|
|
20
|
+
title: "Get organization public profile",
|
|
21
|
+
summary: "Get public organization display metadata",
|
|
22
|
+
description: "Returns public organization metadata used by access and invitation screens.",
|
|
14
23
|
})))
|
|
15
24
|
.add(HttpApiEndpoint.post("setPassword", "/auth/set-password", {
|
|
16
25
|
payload: ExtraSetPasswordPayload,
|
package/dist/extra/schema.d.ts
CHANGED
|
@@ -97,6 +97,18 @@ export declare const ExtraProjectPublicConfig: Schema.Struct<{
|
|
|
97
97
|
readonly signUpName: Schema.Boolean;
|
|
98
98
|
}>;
|
|
99
99
|
}>;
|
|
100
|
+
export declare const ExtraOrganizationPublicProfileQuery: Schema.Struct<{
|
|
101
|
+
readonly organizationId: Schema.String;
|
|
102
|
+
}>;
|
|
103
|
+
export declare const ExtraOrganizationPublicProfile: Schema.Struct<{
|
|
104
|
+
readonly id: Schema.String;
|
|
105
|
+
readonly name: Schema.String;
|
|
106
|
+
readonly slug: Schema.String;
|
|
107
|
+
readonly displayName: Schema.String;
|
|
108
|
+
readonly contactEmail: Schema.NullOr<Schema.String>;
|
|
109
|
+
readonly logo: Schema.NullOr<Schema.String>;
|
|
110
|
+
readonly icon: Schema.NullOr<Schema.String>;
|
|
111
|
+
}>;
|
|
100
112
|
export declare const ExtraOkResponse: Schema.Struct<{
|
|
101
113
|
readonly ok: Schema.Boolean;
|
|
102
114
|
}>;
|
|
@@ -119,5 +131,7 @@ export type ExtraVerifyApiKeyPayload = typeof ExtraVerifyApiKeyPayload.Type;
|
|
|
119
131
|
export type ExtraVerifyApiKeyResponse = typeof ExtraVerifyApiKeyResponse.Type;
|
|
120
132
|
export type ExtraProjectPublicConfigQuery = typeof ExtraProjectPublicConfigQuery.Type;
|
|
121
133
|
export type ExtraProjectPublicConfig = typeof ExtraProjectPublicConfig.Type;
|
|
134
|
+
export type ExtraOrganizationPublicProfileQuery = typeof ExtraOrganizationPublicProfileQuery.Type;
|
|
135
|
+
export type ExtraOrganizationPublicProfile = typeof ExtraOrganizationPublicProfile.Type;
|
|
122
136
|
export type ExtraOkResponse = typeof ExtraOkResponse.Type;
|
|
123
137
|
export {};
|
package/dist/extra/schema.js
CHANGED
|
@@ -203,6 +203,38 @@ export const ExtraProjectPublicConfig = Schema.Struct({
|
|
|
203
203
|
},
|
|
204
204
|
],
|
|
205
205
|
});
|
|
206
|
+
export const ExtraOrganizationPublicProfileQuery = Schema.Struct({
|
|
207
|
+
organizationId: Schema.String,
|
|
208
|
+
}).annotate({
|
|
209
|
+
identifier: "ExtraOrganizationPublicProfileQuery",
|
|
210
|
+
title: "Extra organization public profile query",
|
|
211
|
+
description: "Organization ID used to resolve public organization display metadata.",
|
|
212
|
+
examples: [{ organizationId: "org_1" }],
|
|
213
|
+
});
|
|
214
|
+
export const ExtraOrganizationPublicProfile = Schema.Struct({
|
|
215
|
+
id: Schema.String,
|
|
216
|
+
name: Schema.String,
|
|
217
|
+
slug: Schema.String,
|
|
218
|
+
displayName: Schema.String,
|
|
219
|
+
contactEmail: Schema.NullOr(Schema.String),
|
|
220
|
+
logo: Schema.NullOr(Schema.String),
|
|
221
|
+
icon: Schema.NullOr(Schema.String),
|
|
222
|
+
}).annotate({
|
|
223
|
+
identifier: "ExtraOrganizationPublicProfile",
|
|
224
|
+
title: "Extra organization public profile",
|
|
225
|
+
description: "Public organization display metadata used for access and invitation screens.",
|
|
226
|
+
examples: [
|
|
227
|
+
{
|
|
228
|
+
id: "org_1",
|
|
229
|
+
name: "Krak",
|
|
230
|
+
slug: "krak",
|
|
231
|
+
displayName: "Krak",
|
|
232
|
+
contactEmail: null,
|
|
233
|
+
logo: null,
|
|
234
|
+
icon: null,
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
});
|
|
206
238
|
export const ExtraOkResponse = Schema.Struct({
|
|
207
239
|
ok: Schema.Boolean,
|
|
208
240
|
}).annotate({
|
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, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, type AuthUiClient, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type OrganizationSwitcherProps, type UserButtonDialog, useAuthClient, useAdminUsersTotal, } from "./components";
|
|
8
|
+
export { OrganizationSwitcher, AdminRequired, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, type AuthUiClient, type AdminRequiredMessages, type AdminRequiredProps, type KrakstackAuthContextValue, type KrakstackAuthLocale, type KrakstackAuthProviderProps, type OrganizationSwitcherDialog, type OrganizationSwitcherProps, type UserButtonDialog, 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, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, AdminOrganizationForm, AdminOrganizationsTable, AdminUsersTable, UserButton, assetUrl, createAuthUiClient, useAuthClient, useAdminUsersTotal, } from "./components";
|
|
8
|
+
export { OrganizationSwitcher, AdminRequired, KrakstackAuthProvider, ResetPassword, Signin, Signup, TwoFactor, 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/service.d.ts
CHANGED
|
@@ -117,6 +117,20 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
117
117
|
readonly id: import("effect/Schema").String;
|
|
118
118
|
readonly key: import("effect/Schema").String;
|
|
119
119
|
}, "Type">, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("./extra/schema").ExtraBadRequest | HttpApiError.Forbidden | HttpApiError.InternalServerError | import("effect/Schema").SchemaError | HttpApiError.Unauthorized), [Mode] extends ["response-only"] ? never : never>;
|
|
120
|
+
readonly getOrganizationPublicProfile: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
|
|
121
|
+
readonly query: import("effect/Schema").Struct.ReadonlySide<{
|
|
122
|
+
readonly organizationId: import("effect/Schema").String;
|
|
123
|
+
}, "Type">;
|
|
124
|
+
readonly responseMode?: Mode;
|
|
125
|
+
}) => Effect.Effect<HttpApiClient.Client.Response<import("effect/Schema").Struct.ReadonlySide<{
|
|
126
|
+
readonly id: import("effect/Schema").String;
|
|
127
|
+
readonly name: import("effect/Schema").String;
|
|
128
|
+
readonly slug: import("effect/Schema").String;
|
|
129
|
+
readonly displayName: import("effect/Schema").String;
|
|
130
|
+
readonly contactEmail: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
131
|
+
readonly logo: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
132
|
+
readonly icon: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
133
|
+
}, "Type">, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : HttpApiError.InternalServerError | HttpApiError.NotFound | import("effect/Schema").SchemaError), [Mode] extends ["response-only"] ? never : never>;
|
|
120
134
|
readonly getProjectPublicConfig: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
|
|
121
135
|
readonly query: {
|
|
122
136
|
readonly projectId?: string | undefined;
|
|
@@ -529,6 +543,20 @@ declare const AuthService_base: Context.ServiceClass<AuthService, "@krak-stack/a
|
|
|
529
543
|
readonly id: import("effect/Schema").String;
|
|
530
544
|
readonly key: import("effect/Schema").String;
|
|
531
545
|
}, "Type">, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : import("./extra/schema").ExtraBadRequest | HttpApiError.Forbidden | HttpApiError.InternalServerError | import("effect/Schema").SchemaError | HttpApiError.Unauthorized), [Mode] extends ["response-only"] ? never : never>;
|
|
546
|
+
readonly getOrganizationPublicProfile: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
|
|
547
|
+
readonly query: import("effect/Schema").Struct.ReadonlySide<{
|
|
548
|
+
readonly organizationId: import("effect/Schema").String;
|
|
549
|
+
}, "Type">;
|
|
550
|
+
readonly responseMode?: Mode;
|
|
551
|
+
}) => Effect.Effect<HttpApiClient.Client.Response<import("effect/Schema").Struct.ReadonlySide<{
|
|
552
|
+
readonly id: import("effect/Schema").String;
|
|
553
|
+
readonly name: import("effect/Schema").String;
|
|
554
|
+
readonly slug: import("effect/Schema").String;
|
|
555
|
+
readonly displayName: import("effect/Schema").String;
|
|
556
|
+
readonly contactEmail: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
557
|
+
readonly logo: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
558
|
+
readonly icon: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
559
|
+
}, "Type">, Mode>, import("effect/unstable/http/HttpClientError").HttpClientError | ([Mode] extends ["response-only"] ? never : HttpApiError.InternalServerError | HttpApiError.NotFound | import("effect/Schema").SchemaError), [Mode] extends ["response-only"] ? never : never>;
|
|
532
560
|
readonly getProjectPublicConfig: <Mode extends HttpApiClient.Client.ResponseMode = import("effect/unstable/httpapi/HttpApiEndpoint").ClientResponseMode>(request: {
|
|
533
561
|
readonly query: {
|
|
534
562
|
readonly projectId?: string | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krak-stack/auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.48",
|
|
4
4
|
"description": "Effect HttpApi clients and schemas for KrakStack Auth.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
|
-
"build": "rm -rf dist && tsc -p tsconfig.json",
|
|
64
|
-
"build:watch": "rm -rf dist && tsc -p tsconfig.json --watch --preserveWatchOutput",
|
|
63
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
64
|
+
"build:watch": "rm -rf dist && tsc -p tsconfig.build.json --watch --preserveWatchOutput",
|
|
65
65
|
"dev": "bun run build:watch",
|
|
66
66
|
"prepack": "bun run build",
|
|
67
67
|
"type:check": "tsc -p tsconfig.json --noEmit"
|