@krak-stack/auth 0.1.46 → 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.
@@ -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";
@@ -56,7 +56,26 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
56
56
  readonly users: import("effect/Schema").Number;
57
57
  readonly organizations: import("effect/Schema").Number;
58
58
  }>>;
59
- }>>, 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>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"deleteDomain", "DELETE", "/api/auth/admin/domains/:id", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
59
+ }>>, 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>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"deleteApiKey", "DELETE", "/api/auth/admin/api-keys/:id", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
60
+ readonly id: import("effect/Schema").String;
61
+ }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
62
+ readonly id: import("effect/Schema").String;
63
+ readonly configId: import("effect/Schema").String;
64
+ readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
65
+ readonly start: import("effect/Schema").NullOr<import("effect/Schema").String>;
66
+ readonly referenceId: import("effect/Schema").String;
67
+ readonly prefix: import("effect/Schema").NullOr<import("effect/Schema").String>;
68
+ readonly enabled: import("effect/Schema").Boolean;
69
+ readonly rateLimitEnabled: import("effect/Schema").Boolean;
70
+ readonly rateLimitTimeWindow: import("effect/Schema").NullOr<import("effect/Schema").Number>;
71
+ readonly rateLimitMax: import("effect/Schema").NullOr<import("effect/Schema").Number>;
72
+ readonly requestCount: import("effect/Schema").Number;
73
+ readonly remaining: import("effect/Schema").NullOr<import("effect/Schema").Number>;
74
+ readonly lastRequest: import("effect/Schema").NullOr<import("effect/Schema").Date>;
75
+ readonly expiresAt: import("effect/Schema").NullOr<import("effect/Schema").Date>;
76
+ readonly createdAt: import("effect/Schema").Date;
77
+ readonly updatedAt: import("effect/Schema").Date;
78
+ }>>, 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").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"deleteDomain", "DELETE", "/api/auth/admin/domains/:id", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
60
79
  readonly id: import("effect/Schema").NonEmptyString;
61
80
  }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
62
81
  readonly id: import("effect/Schema").String;
@@ -83,6 +102,44 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
83
102
  readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
84
103
  readonly memberCount: import("effect/Schema").optional<import("effect/Schema").Number>;
85
104
  readonly createdAt: import("effect/Schema").Date;
105
+ }>>, 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").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"disableApiKeyRateLimit", "POST", "/api/auth/admin/api-keys/:id/disable-rate-limit", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
106
+ readonly id: import("effect/Schema").String;
107
+ }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
108
+ readonly id: import("effect/Schema").String;
109
+ readonly configId: import("effect/Schema").String;
110
+ readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
111
+ readonly start: import("effect/Schema").NullOr<import("effect/Schema").String>;
112
+ readonly referenceId: import("effect/Schema").String;
113
+ readonly prefix: import("effect/Schema").NullOr<import("effect/Schema").String>;
114
+ readonly enabled: import("effect/Schema").Boolean;
115
+ readonly rateLimitEnabled: import("effect/Schema").Boolean;
116
+ readonly rateLimitTimeWindow: import("effect/Schema").NullOr<import("effect/Schema").Number>;
117
+ readonly rateLimitMax: import("effect/Schema").NullOr<import("effect/Schema").Number>;
118
+ readonly requestCount: import("effect/Schema").Number;
119
+ readonly remaining: import("effect/Schema").NullOr<import("effect/Schema").Number>;
120
+ readonly lastRequest: import("effect/Schema").NullOr<import("effect/Schema").Date>;
121
+ readonly expiresAt: import("effect/Schema").NullOr<import("effect/Schema").Date>;
122
+ readonly createdAt: import("effect/Schema").Date;
123
+ readonly updatedAt: import("effect/Schema").Date;
124
+ }>>, 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").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"enableApiKeyRateLimit", "POST", "/api/auth/admin/api-keys/:id/enable-rate-limit", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
125
+ readonly id: import("effect/Schema").String;
126
+ }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
127
+ readonly id: import("effect/Schema").String;
128
+ readonly configId: import("effect/Schema").String;
129
+ readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
130
+ readonly start: import("effect/Schema").NullOr<import("effect/Schema").String>;
131
+ readonly referenceId: import("effect/Schema").String;
132
+ readonly prefix: import("effect/Schema").NullOr<import("effect/Schema").String>;
133
+ readonly enabled: import("effect/Schema").Boolean;
134
+ readonly rateLimitEnabled: import("effect/Schema").Boolean;
135
+ readonly rateLimitTimeWindow: import("effect/Schema").NullOr<import("effect/Schema").Number>;
136
+ readonly rateLimitMax: import("effect/Schema").NullOr<import("effect/Schema").Number>;
137
+ readonly requestCount: import("effect/Schema").Number;
138
+ readonly remaining: import("effect/Schema").NullOr<import("effect/Schema").Number>;
139
+ readonly lastRequest: import("effect/Schema").NullOr<import("effect/Schema").Date>;
140
+ readonly expiresAt: import("effect/Schema").NullOr<import("effect/Schema").Date>;
141
+ readonly createdAt: import("effect/Schema").Date;
142
+ readonly updatedAt: import("effect/Schema").Date;
86
143
  }>>, 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").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getDomainRecords", "GET", "/api/auth/admin/domains/:id/records", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
87
144
  readonly id: import("effect/Schema").NonEmptyString;
88
145
  }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").$Array<import("effect/Schema").Struct<{
@@ -91,7 +148,24 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
91
148
  readonly type: import("effect/Schema").String;
92
149
  readonly name: import("effect/Schema").String;
93
150
  readonly value: import("effect/Schema").String;
94
- }>>>, 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").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"listDomains", "GET", "/api/auth/admin/domains", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").$Array<import("effect/Schema").Struct<{
151
+ }>>>, 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").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"listApiKeys", "GET", "/api/auth/admin/api-keys", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").$Array<import("effect/Schema").Struct<{
152
+ readonly id: import("effect/Schema").String;
153
+ readonly configId: import("effect/Schema").String;
154
+ readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
155
+ readonly start: import("effect/Schema").NullOr<import("effect/Schema").String>;
156
+ readonly referenceId: import("effect/Schema").String;
157
+ readonly prefix: import("effect/Schema").NullOr<import("effect/Schema").String>;
158
+ readonly enabled: import("effect/Schema").Boolean;
159
+ readonly rateLimitEnabled: import("effect/Schema").Boolean;
160
+ readonly rateLimitTimeWindow: import("effect/Schema").NullOr<import("effect/Schema").Number>;
161
+ readonly rateLimitMax: import("effect/Schema").NullOr<import("effect/Schema").Number>;
162
+ readonly requestCount: import("effect/Schema").Number;
163
+ readonly remaining: import("effect/Schema").NullOr<import("effect/Schema").Number>;
164
+ readonly lastRequest: import("effect/Schema").NullOr<import("effect/Schema").Date>;
165
+ readonly expiresAt: import("effect/Schema").NullOr<import("effect/Schema").Date>;
166
+ readonly createdAt: import("effect/Schema").Date;
167
+ readonly updatedAt: import("effect/Schema").Date;
168
+ }>>>, 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>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"listDomains", "GET", "/api/auth/admin/domains", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").$Array<import("effect/Schema").Struct<{
95
169
  readonly id: import("effect/Schema").String;
96
170
  readonly hostname: import("effect/Schema").String;
97
171
  readonly rootHostname: import("effect/Schema").String;
@@ -160,7 +234,51 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
160
234
  readonly total: import("effect/Schema").Int;
161
235
  readonly pageCount: import("effect/Schema").Int;
162
236
  }>;
163
- }>>, 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>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"updateDomain", "PATCH", "/api/auth/admin/domains/:id", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
237
+ }>>, 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>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"resetApiKeyRateLimit", "POST", "/api/auth/admin/api-keys/:id/reset-rate-limit", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
238
+ readonly id: import("effect/Schema").String;
239
+ }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
240
+ readonly id: import("effect/Schema").String;
241
+ readonly configId: import("effect/Schema").String;
242
+ readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
243
+ readonly start: import("effect/Schema").NullOr<import("effect/Schema").String>;
244
+ readonly referenceId: import("effect/Schema").String;
245
+ readonly prefix: import("effect/Schema").NullOr<import("effect/Schema").String>;
246
+ readonly enabled: import("effect/Schema").Boolean;
247
+ readonly rateLimitEnabled: import("effect/Schema").Boolean;
248
+ readonly rateLimitTimeWindow: import("effect/Schema").NullOr<import("effect/Schema").Number>;
249
+ readonly rateLimitMax: import("effect/Schema").NullOr<import("effect/Schema").Number>;
250
+ readonly requestCount: import("effect/Schema").Number;
251
+ readonly remaining: import("effect/Schema").NullOr<import("effect/Schema").Number>;
252
+ readonly lastRequest: import("effect/Schema").NullOr<import("effect/Schema").Date>;
253
+ readonly expiresAt: import("effect/Schema").NullOr<import("effect/Schema").Date>;
254
+ readonly createdAt: import("effect/Schema").Date;
255
+ readonly updatedAt: import("effect/Schema").Date;
256
+ }>>, 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").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"updateApiKey", "PATCH", "/api/auth/admin/api-keys/:id", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
257
+ readonly id: import("effect/Schema").String;
258
+ }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
259
+ readonly name: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
260
+ readonly enabled: import("effect/Schema").optional<import("effect/Schema").Boolean>;
261
+ readonly rateLimitEnabled: import("effect/Schema").optional<import("effect/Schema").Boolean>;
262
+ readonly rateLimitMax: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Number>>;
263
+ readonly rateLimitTimeWindow: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").Number>>;
264
+ }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
265
+ readonly id: import("effect/Schema").String;
266
+ readonly configId: import("effect/Schema").String;
267
+ readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
268
+ readonly start: import("effect/Schema").NullOr<import("effect/Schema").String>;
269
+ readonly referenceId: import("effect/Schema").String;
270
+ readonly prefix: import("effect/Schema").NullOr<import("effect/Schema").String>;
271
+ readonly enabled: import("effect/Schema").Boolean;
272
+ readonly rateLimitEnabled: import("effect/Schema").Boolean;
273
+ readonly rateLimitTimeWindow: import("effect/Schema").NullOr<import("effect/Schema").Number>;
274
+ readonly rateLimitMax: import("effect/Schema").NullOr<import("effect/Schema").Number>;
275
+ readonly requestCount: import("effect/Schema").Number;
276
+ readonly remaining: import("effect/Schema").NullOr<import("effect/Schema").Number>;
277
+ readonly lastRequest: import("effect/Schema").NullOr<import("effect/Schema").Date>;
278
+ readonly expiresAt: import("effect/Schema").NullOr<import("effect/Schema").Date>;
279
+ readonly createdAt: import("effect/Schema").Date;
280
+ readonly updatedAt: import("effect/Schema").Date;
281
+ }>>, 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").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"updateDomain", "PATCH", "/api/auth/admin/domains/:id", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
164
282
  readonly id: import("effect/Schema").NonEmptyString;
165
283
  }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
166
284
  readonly hostname: import("effect/Schema").NonEmptyString;
@@ -262,7 +380,17 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
262
380
  }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
263
381
  readonly id: import("effect/Schema").String;
264
382
  readonly key: import("effect/Schema").String;
265
- }>>, 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<"getProjectPublicConfig", "GET", "/api/auth/project-config", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
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<{
266
394
  readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
267
395
  readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
268
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 { createAuthClient } from "better-auth/react";
4
- type Session = {
5
- session: {
6
- activeOrganizationId?: string | null | undefined;
7
- impersonatedBy?: string | null | undefined;
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 BaseAuthUiClient = ReturnType<typeof createAuthClient<{
23
- plugins: [
24
- ReturnType<typeof adminClient>,
25
- ReturnType<typeof emailOTPClient>,
26
- ReturnType<typeof lastLoginMethodClient>,
27
- ReturnType<typeof organizationClient>,
28
- ReturnType<typeof twoFactorClient>,
29
- ReturnType<typeof apiKeyClient>,
30
- ReturnType<typeof genericOAuthClient>
31
- ];
32
- }>>;
33
- export type AuthUiClient = Omit<BaseAuthUiClient, "getSession" | "organization" | "useSession" | "useActiveOrganization" | "useActiveMemberRole"> & {
34
- getSession: () => Promise<{
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 declare const createAuthUiClient: (baseUrl?: string | undefined) => AuthUiClient;
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
  });