@krak-stack/auth 0.1.29 → 0.1.31

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.
@@ -1,11 +1,12 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useAtomSet } from "@effect/atom-react";
2
+ import { useAtomRefresh, useAtomSet, useAtomValue } from "@effect/atom-react";
3
3
  import {} from "@tanstack/react-table";
4
4
  import { useNavigate, useRouterState, } from "@tanstack/react-router";
5
- import { Schema } from "effect";
5
+ import { Effect, Schema } from "effect";
6
+ import { AsyncResult, Atom } from "effect/unstable/reactivity";
6
7
  import { Check, Copy, KeyRound, LogOutIcon, ShieldCheck, Trash2, UserCircleIcon, UserIcon, } from "lucide-react";
7
8
  import { QRCode } from "react-qr-code";
8
- import { createContext, useContext, useEffect, useEffectEvent, useState, } from "react";
9
+ import { createContext, useContext, useState, } from "react";
9
10
  import { DataTable } from "@/components/ui/data-table";
10
11
  import { AppBrand } from "@/components/ui/app-brand";
11
12
  import { useAppForm } from "@/components/ui/form";
@@ -18,7 +19,8 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem,
18
19
  import { Separator } from "@/components/ui/separator";
19
20
  import { authApiClient } from "./auth-api-client";
20
21
  import { createApiKey } from "./api-key";
21
- import { ExtraPresignedUpload } from "../extra/schema";
22
+ import { useOpenedOnce } from "./hooks";
23
+ import { ExtraUploadedAsset } from "../extra/schema";
22
24
  import { assetPath, assetUrl } from "./utils";
23
25
  const messages = {
24
26
  en: {
@@ -95,6 +97,7 @@ const messages = {
95
97
  user_two_factor_disabled: "Disabled",
96
98
  user_two_factor_disabled_message: "Two-factor authentication is disabled.",
97
99
  user_two_factor_enable_error: "Could not start two-factor setup.",
100
+ user_two_factor_enable_submit: "Enable",
98
101
  user_two_factor_enabled: "Enabled",
99
102
  user_two_factor_enabled_message: "Two-factor authentication is enabled.",
100
103
  user_two_factor_scan_description: "Add this account to your authenticator app, then enter the generated code below.",
@@ -176,6 +179,7 @@ const messages = {
176
179
  user_two_factor_disabled: "Désactivée",
177
180
  user_two_factor_disabled_message: "L'authentification à deux facteurs est désactivée.",
178
181
  user_two_factor_enable_error: "Impossible de démarrer la configuration à deux facteurs.",
182
+ user_two_factor_enable_submit: "Activer",
179
183
  user_two_factor_enabled: "Activée",
180
184
  user_two_factor_enabled_message: "L'authentification à deux facteurs est activée.",
181
185
  user_two_factor_scan_description: "Ajoutez ce compte à votre application d'authentification, puis saisissez le code généré ci-dessous.",
@@ -204,13 +208,41 @@ const userButtonMessageFns = (labels) => new Proxy({}, {
204
208
  const UserButtonMessagesContext = createContext(userButtonMessageFns(userButtonMessages()));
205
209
  const useUserButtonMessages = () => useContext(UserButtonMessagesContext);
206
210
  const isFile = (value) => value instanceof File;
207
- const decodePresignedUpload = Schema.decodeUnknownPromise(ExtraPresignedUpload);
208
- const presignUserImageUpload = async (file, m, presignUserImage) => {
209
- const contentType = file.type || "image/png";
210
- return await decodePresignedUpload(await presignUserImage({
211
- payload: { fileName: file.name, contentType },
212
- }));
211
+ const decodeUploadedAsset = Schema.decodeUnknownPromise(ExtraUploadedAsset);
212
+ const uploadUserImageAsset = async (file, m, uploadUserImage) => {
213
+ const payload = new FormData();
214
+ payload.append("file", file);
215
+ try {
216
+ return await decodeUploadedAsset(await uploadUserImage({ payload }));
217
+ }
218
+ catch {
219
+ throw new Error(m.user_profile_image_upload_error());
220
+ }
213
221
  };
222
+ const userAccountsAtom = Atom.family((authClient) => Atom.keepAlive(Atom.make(Effect.tryPromise({
223
+ try: async () => {
224
+ const result = await authClient.listAccounts();
225
+ if (result.error) {
226
+ throw new Error(result.error.message ?? "Could not load accounts.");
227
+ }
228
+ return result.data ?? [];
229
+ },
230
+ catch: (error) => error,
231
+ }))));
232
+ const emptyAccountsAtom = Atom.make(Effect.succeed([]));
233
+ const userApiKeysAtom = Atom.family((authClient) => Atom.keepAlive(Atom.make(Effect.tryPromise({
234
+ try: async () => {
235
+ const result = await authClient.apiKey.list({
236
+ query: { configId: "user" },
237
+ });
238
+ if (result.error) {
239
+ throw new Error(result.error.message ?? "Could not load API keys.");
240
+ }
241
+ return result.data?.apiKeys ?? [];
242
+ },
243
+ catch: (error) => error,
244
+ }))));
245
+ const emptyApiKeysAtom = Atom.make(Effect.succeed([]));
214
246
  export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side = "bottom", defaultDialog = null, hideTrigger = false, renderUnauthenticated, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }) => {
215
247
  const labels = userButtonMessages(messages);
216
248
  const m = userButtonMessageFns(labels);
@@ -222,7 +254,27 @@ export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side =
222
254
  const [uncontrolledDialog, setUncontrolledDialog] = useState(defaultDialog);
223
255
  const settingsDialog = controlledDialog !== undefined ? controlledDialog : uncontrolledDialog;
224
256
  const [formError, setFormError] = useState(null);
225
- const presignUserImage = useAtomSet(authApiClient(baseUrl).mutation("authExtra", "presignUserImageUpload"), { mode: "promise" });
257
+ const shouldLoadAccounts = Boolean(session) &&
258
+ (settingsDialog === "account" || settingsDialog === "security");
259
+ const accountsAtom = shouldLoadAccounts
260
+ ? userAccountsAtom(authClient)
261
+ : emptyAccountsAtom;
262
+ const accountsResult = useAtomValue(accountsAtom);
263
+ const refreshAccounts = useAtomRefresh(accountsAtom);
264
+ const uploadUserImage = useAtomSet(authApiClient(baseUrl).mutation("authExtra", "uploadUserImage"), { mode: "promise" });
265
+ const accountCache = {
266
+ accounts: AsyncResult.match(accountsResult, {
267
+ onInitial: () => null,
268
+ onFailure: () => null,
269
+ onSuccess: ({ value }) => Array.from(value),
270
+ }),
271
+ error: AsyncResult.match(accountsResult, {
272
+ onInitial: () => null,
273
+ onFailure: () => m.user_accounts_load_error(),
274
+ onSuccess: () => null,
275
+ }),
276
+ reload: async () => refreshAccounts(),
277
+ };
226
278
  const setSettingsDialog = (next) => {
227
279
  const nextDialog = typeof next === "function" ? next(settingsDialog) : next;
228
280
  if (nextDialog === settingsDialog)
@@ -249,16 +301,8 @@ export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side =
249
301
  const imageFile = isFile(values.image) ? values.image : null;
250
302
  const image = imageFile
251
303
  ? await (async () => {
252
- const presigned = await presignUserImageUpload(imageFile, m, presignUserImage);
253
- const uploadResponse = await fetch(presigned.uploadUrl, {
254
- method: "PUT",
255
- headers: { "Content-Type": imageFile.type || "image/png" },
256
- body: imageFile,
257
- });
258
- if (!uploadResponse.ok) {
259
- throw new Error(m.user_profile_image_upload_error());
260
- }
261
- return assetPath(presigned.url);
304
+ const uploaded = await uploadUserImageAsset(imageFile, m, uploadUserImage);
305
+ return assetPath(uploaded.url);
262
306
  })()
263
307
  : typeof values.image === "string"
264
308
  ? assetPath(values.image)
@@ -287,34 +331,17 @@ export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side =
287
331
  ? error.message
288
332
  : m.user_form_update_error());
289
333
  }
290
- } }), _jsx(Separator, {}), _jsx(ConnectedAccounts, { authClient: authClient, currentSiteHref: currentSiteHref, navigate: navigate }), _jsx(Separator, {}), _jsx(PasswordSettings, { authClient: authClient })] }))] }) }), _jsx(Dialog, { open: settingsDialog === "security", onOpenChange: (open) => {
334
+ } }), _jsx(Separator, {}), _jsx(ConnectedAccounts, { authClient: authClient, baseUrl: baseUrl, accountCache: accountCache, currentSiteHref: currentSiteHref, navigate: navigate })] }))] }) }), _jsx(Dialog, { open: settingsDialog === "security", onOpenChange: (open) => {
291
335
  setSettingsDialog((current) => open ? "security" : current === "security" ? null : current);
292
- }, 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_security_title() }), _jsx(DialogDescription, { children: m.user_security_description() })] }), _jsx(Separator, {}), _jsx(AccountSecuritySettings, { authClient: authClient })] }) }), _jsx(Dialog, { open: settingsDialog === "apiKeys", onOpenChange: (open) => {
336
+ }, 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_security_title() }), _jsx(DialogDescription, { children: m.user_security_description() })] }), _jsx(Separator, {}), _jsxs("div", { className: "flex flex-col gap-6", children: [_jsx(PasswordSettings, { authClient: authClient, baseUrl: baseUrl, accountCache: accountCache }), _jsx(Separator, {}), _jsx(AccountSecuritySettings, { authClient: authClient, accountCache: accountCache })] })] }) }), _jsx(Dialog, { open: settingsDialog === "apiKeys", onOpenChange: (open) => {
293
337
  setSettingsDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
294
- }, 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: m.user_api_keys_description() })] }), _jsx(Separator, {}), _jsx(ApiKeyManager, { authClient: authClient, permissions: apiKeyPermissions ?? {} })] }) })] }));
338
+ }, 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: m.user_api_keys_description() })] }), _jsx(Separator, {}), _jsx(ApiKeyManager, { authClient: authClient, active: settingsDialog === "apiKeys", permissions: apiKeyPermissions ?? {} })] }) })] }));
295
339
  };
296
- function ConnectedAccounts({ authClient, currentSiteHref, navigate, }) {
340
+ function ConnectedAccounts({ authClient, baseUrl, accountCache, currentSiteHref, navigate, }) {
297
341
  const m = useUserButtonMessages();
298
- const [accounts, setAccounts] = useState([]);
299
- const [error, setError] = useState(null);
300
- const [loading, setLoading] = useState(true);
301
342
  const [isLinking, setIsLinking] = useState(false);
302
343
  const [revokingAccount, setRevokingAccount] = useState(null);
303
- const loadAccounts = useEffectEvent(async () => {
304
- setLoading(true);
305
- setError(null);
306
- const result = await authClient.listAccounts();
307
- if (result.error) {
308
- setError(result.error.message ?? m.user_accounts_load_error());
309
- setLoading(false);
310
- return;
311
- }
312
- setAccounts(result.data ?? []);
313
- setLoading(false);
314
- });
315
- useEffect(() => {
316
- void loadAccounts();
317
- }, []);
344
+ const accounts = accountCache.accounts ?? [];
318
345
  const googleAccount = accounts.find((account) => account.providerId === "google");
319
346
  const hasPassword = accounts.some((account) => account.providerId === "credential");
320
347
  const canRevokeAccount = accounts.length > 1;
@@ -347,37 +374,24 @@ function ConnectedAccounts({ authClient, currentSiteHref, navigate, }) {
347
374
  return;
348
375
  }
349
376
  setRevokingAccount(null);
350
- await loadAccounts();
377
+ await accountCache.reload();
351
378
  };
352
- return (_jsxs("section", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_accounts_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_accounts_description() })] }), loading ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : null, _jsx(AccountProviderRow, { initial: "G", title: m.user_account_google_title(), description: m.user_account_google_description(), account: googleAccount, connected: Boolean(googleAccount), canRevoke: canRevokeAccount, connectLabel: m.user_account_google_connect(), revokeLabel: m.user_account_revoke(), onlyMethodLabel: m.user_account_only_method(), isConnecting: isLinking, renderDisconnected: undefined, onConnect: linkGoogle, onRevoke: (account) => setRevokingAccount(account) }), revokingAccount ? (_jsx(RevokeAccountForm, { authClient: authClient, account: revokingAccount, requirePassword: hasPassword, onCancel: () => setRevokingAccount(null), onRevoke: revokeAccount })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }));
379
+ return (_jsxs("section", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_accounts_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_accounts_description() })] }), accountCache.accounts ? (_jsxs(_Fragment, { children: [_jsx(AccountProviderRow, { icon: _jsx(GoogleLogo, {}), title: m.user_account_google_title(), description: m.user_account_google_description(), account: googleAccount, connected: Boolean(googleAccount), canRevoke: canRevokeAccount, connectLabel: m.user_account_google_connect(), revokeLabel: m.user_account_revoke(), onlyMethodLabel: m.user_account_only_method(), isConnecting: isLinking, renderDisconnected: undefined, onConnect: linkGoogle, onRevoke: (account) => setRevokingAccount(account) }), revokingAccount ? (_jsx(RevokeAccountForm, { baseUrl: baseUrl, account: revokingAccount, requirePassword: hasPassword, onCancel: () => setRevokingAccount(null), onRevoke: revokeAccount })) : null] })) : !accountCache.error ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : null, accountCache.error ? (_jsx("p", { className: "text-destructive text-sm", children: accountCache.error })) : null] }));
353
380
  }
354
- function AccountProviderRow({ initial, title, description, account, connected, canRevoke, connectLabel, revokeLabel, onlyMethodLabel, isConnecting, renderDisconnected, onConnect, onRevoke, }) {
381
+ function AccountProviderRow({ icon, title, description, account, connected, canRevoke, connectLabel, revokeLabel, onlyMethodLabel, isConnecting, renderDisconnected, onConnect, onRevoke, }) {
355
382
  const m = useUserButtonMessages();
356
- return (_jsx("div", { className: "flex flex-col gap-3 rounded-lg border p-4", children: _jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [_jsxs("div", { className: "flex min-w-0 items-center gap-3", children: [_jsx("span", { className: "bg-background flex size-9 shrink-0 items-center justify-center rounded-full border text-sm font-semibold", children: initial }), _jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("p", { className: "font-medium", children: title }), _jsx(Badge, { variant: connected ? "default" : "secondary", children: connected
383
+ return (_jsx("div", { className: "flex flex-col gap-3 rounded-lg border p-4", children: _jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [_jsxs("div", { className: "flex min-w-0 items-center gap-3", children: [_jsx("span", { className: "bg-background flex size-9 shrink-0 items-center justify-center rounded-full border text-sm font-semibold", children: icon }), _jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("p", { className: "font-medium", children: title }), _jsx(Badge, { variant: connected ? "default" : "secondary", children: connected
357
384
  ? m.user_account_connected()
358
385
  : m.user_account_not_connected() })] }), _jsx("p", { className: "text-muted-foreground text-sm", children: description })] })] }), connected && account ? (_jsx(Button, { type: "button", variant: "outline", disabled: !canRevoke, onClick: () => onRevoke(account), children: canRevoke ? revokeLabel : onlyMethodLabel })) : renderDisconnected ? (renderDisconnected) : (_jsx(Button, { type: "button", variant: "outline", disabled: isConnecting, onClick: onConnect, children: connectLabel }))] }) }));
359
386
  }
360
- function PasswordSettings({ authClient }) {
361
- const m = useUserButtonMessages();
362
- const [accounts, setAccounts] = useState([]);
387
+ function GoogleLogo() {
388
+ return (_jsxs("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", className: "size-5", children: [_jsx("path", { fill: "#4285F4", d: "M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" }), _jsx("path", { fill: "#34A853", d: "M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" }), _jsx("path", { fill: "#FBBC05", d: "M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" }), _jsx("path", { fill: "#EA4335", d: "M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84C6.71 7.31 9.14 5.38 12 5.38z" })] }));
389
+ }
390
+ function PasswordSettings({ authClient, baseUrl, accountCache, }) {
363
391
  const [error, setError] = useState(null);
364
- const [loading, setLoading] = useState(true);
365
392
  const [revokingAccount, setRevokingAccount] = useState(null);
366
- const loadAccounts = useEffectEvent(async () => {
367
- setLoading(true);
368
- setError(null);
369
- const result = await authClient.listAccounts();
370
- if (result.error) {
371
- setError(result.error.message ?? m.user_accounts_load_error());
372
- setLoading(false);
373
- return;
374
- }
375
- setAccounts(result.data ?? []);
376
- setLoading(false);
377
- });
378
- useEffect(() => {
379
- void loadAccounts();
380
- }, []);
393
+ const m = useUserButtonMessages();
394
+ const accounts = accountCache.accounts ?? [];
381
395
  const passwordAccount = accounts.find((account) => account.providerId === "credential");
382
396
  const hasPassword = Boolean(passwordAccount);
383
397
  const canRevokeAccount = accounts.length > 1;
@@ -392,11 +406,11 @@ function PasswordSettings({ authClient }) {
392
406
  return;
393
407
  }
394
408
  setRevokingAccount(null);
395
- await loadAccounts();
409
+ await accountCache.reload();
396
410
  };
397
- return (_jsxs("section", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_account_password_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_account_password_description() })] }), loading ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : null, hasPassword && passwordAccount ? (_jsxs("div", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3 rounded-lg border p-4", children: [_jsxs("div", { className: "flex flex-col gap-1", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("p", { className: "font-medium", children: m.user_account_password_title() }), _jsx(Badge, { children: m.user_account_connected() })] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_account_password_connected_description() })] }), _jsx(Button, { type: "button", variant: "outline", disabled: !canRevokeAccount, onClick: () => setRevokingAccount(passwordAccount), children: canRevokeAccount
411
+ return (_jsxs("section", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_account_password_title() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_account_password_description() })] }), accountCache.accounts && hasPassword && passwordAccount ? (_jsxs("div", { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3 rounded-lg border p-4", children: [_jsxs("div", { className: "flex flex-col gap-1", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("p", { className: "font-medium", children: m.user_account_password_title() }), _jsx(Badge, { children: m.user_account_connected() })] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_account_password_connected_description() })] }), _jsx(Button, { type: "button", variant: "outline", disabled: !canRevokeAccount, onClick: () => setRevokingAccount(passwordAccount), children: canRevokeAccount
398
412
  ? m.user_account_revoke()
399
- : m.user_account_only_method() })] }), revokingAccount ? (_jsx(RevokeAccountForm, { authClient: authClient, account: revokingAccount, requirePassword: true, onCancel: () => setRevokingAccount(null), onRevoke: revokePassword })) : null, _jsx(Separator, {}), _jsx(ChangePasswordForm, { authClient: authClient })] })) : (_jsx(SetPasswordForm, { authClient: authClient, onSaved: loadAccounts })), error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }));
413
+ : m.user_account_only_method() })] }), revokingAccount ? (_jsx(RevokeAccountForm, { baseUrl: baseUrl, account: revokingAccount, requirePassword: true, onCancel: () => setRevokingAccount(null), onRevoke: revokePassword })) : null, _jsx(Separator, {}), _jsx(ChangePasswordForm, { authClient: authClient })] })) : accountCache.accounts ? (_jsx(SetPasswordForm, { authClient: authClient, onSaved: accountCache.reload })) : !accountCache.error ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.user_loading() })) : null, accountCache.error ? (_jsx("p", { className: "text-destructive text-sm", children: accountCache.error })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }));
400
414
  }
401
415
  function ChangePasswordForm({ authClient }) {
402
416
  const m = useUserButtonMessages();
@@ -458,21 +472,23 @@ function SetPasswordForm({ authClient, onSaved, }) {
458
472
  form.handleSubmit();
459
473
  }, children: [_jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.user_account_new_password(), type: "password", autoComplete: "new-password", required: true })) }), _jsx(form.FormError, {}), _jsx(Button, { type: "submit", className: "self-start", children: m.user_account_password_set() })] }) }));
460
474
  }
461
- function RevokeAccountForm({ authClient, account, requirePassword, onCancel, onRevoke, }) {
475
+ function RevokeAccountForm({ baseUrl, account, requirePassword, onCancel, onRevoke, }) {
462
476
  const m = useUserButtonMessages();
477
+ const verifyPassword = useAtomSet(authApiClient(baseUrl).mutation("authExtra", "verifyPassword"), { mode: "promise" });
463
478
  const form = useAppForm({
464
479
  defaultValues: { password: "" },
465
480
  onSubmit: async ({ value, formApi }) => {
466
481
  formApi.setErrorMap({ onSubmit: undefined });
467
482
  if (requirePassword) {
468
- const verified = await authClient.$fetch("/verify-password", {
469
- method: "POST",
470
- body: { password: value.password },
471
- });
472
- if (verified.error) {
483
+ try {
484
+ await verifyPassword({ payload: { password: value.password } });
485
+ }
486
+ catch (error) {
473
487
  formApi.setErrorMap({
474
488
  onSubmit: {
475
- form: m.user_account_password_verify_error(),
489
+ form: error instanceof Error
490
+ ? error.message
491
+ : m.user_account_password_verify_error(),
476
492
  fields: {},
477
493
  },
478
494
  });
@@ -514,32 +530,35 @@ const UserForm = ({ defaultValues, error, onSubmit, }) => {
514
530
  suggestedHeight: 512,
515
531
  } })) }), _jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.user_form_name_label(), autoComplete: "name", required: true })) }), error && (_jsx("p", { role: "alert", className: "text-destructive text-sm", children: error })), _jsx(form.SubmitButton, {})] }) })] }));
516
532
  };
517
- function AccountSecuritySettings({ authClient }) {
533
+ function AccountSecuritySettings({ authClient, accountCache, }) {
518
534
  const m = useUserButtonMessages();
519
535
  const session = authClient.useSession();
520
536
  const [setup, setSetup] = useState(null);
521
537
  const [message, setMessage] = useState(null);
522
538
  const twoFactorEnabled = hasTwoFactorEnabled(session.data?.user);
539
+ const requirePassword = accountCache.accounts
540
+ ? accountCache.accounts.some((account) => account.providerId === "credential")
541
+ : null;
523
542
  return (_jsxs("div", { className: "flex flex-col gap-6", children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("h2", { className: "text-sm leading-none font-medium", children: m.user_two_factor_title() }), _jsx("p", { className: "text-muted-foreground text-xs", children: m.user_two_factor_description() })] }), _jsx(Badge, { variant: twoFactorEnabled ? "default" : "secondary", children: twoFactorEnabled
524
543
  ? m.user_two_factor_enabled()
525
- : m.user_two_factor_disabled() })] }), twoFactorEnabled ? (_jsx(DisableTotpForm, { authClient: authClient, onDisabled: async () => {
544
+ : m.user_two_factor_disabled() })] }), requirePassword === null ? (_jsx("p", { className: accountCache.error
545
+ ? "text-destructive text-sm"
546
+ : "text-muted-foreground text-sm", children: accountCache.error ?? m.user_loading() })) : twoFactorEnabled ? (_jsx(DisableTotpForm, { authClient: authClient, requirePassword: requirePassword, onDisabled: async () => {
526
547
  setMessage(m.user_two_factor_disabled_message());
527
548
  await session.refetch();
528
549
  } })) : setup ? (_jsx(VerifyTotpSetup, { authClient: authClient, setup: setup, onVerified: async () => {
529
550
  setSetup(null);
530
551
  setMessage(m.user_two_factor_enabled_message());
531
552
  await session.refetch();
532
- } })) : (_jsx(EnableTotpForm, { authClient: authClient, onEnabled: setSetup })), message ? (_jsx("p", { className: "text-muted-foreground text-sm", children: message })) : null] }));
553
+ } })) : (_jsx(EnableTotpForm, { authClient: authClient, requirePassword: requirePassword, onEnabled: setSetup })), message ? (_jsx("p", { className: "text-muted-foreground text-sm", children: message })) : null] }));
533
554
  }
534
- function EnableTotpForm({ authClient, onEnabled, }) {
555
+ function EnableTotpForm({ authClient, requirePassword, onEnabled, }) {
535
556
  const m = useUserButtonMessages();
536
557
  const form = useAppForm({
537
558
  defaultValues: { password: "" },
538
559
  onSubmit: async ({ value, formApi }) => {
539
560
  formApi.setErrorMap({ onSubmit: undefined });
540
- const result = await authClient.twoFactor.enable({
541
- password: value.password,
542
- });
561
+ const result = await authClient.twoFactor.enable(requirePassword ? { password: value.password } : {});
543
562
  if (result.error || !result.data) {
544
563
  formApi.setErrorMap({
545
564
  onSubmit: {
@@ -559,7 +578,7 @@ function EnableTotpForm({ authClient, onEnabled, }) {
559
578
  event.preventDefault();
560
579
  event.stopPropagation();
561
580
  form.handleSubmit();
562
- }, children: [_jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.user_field_password(), type: "password", autoComplete: "current-password", required: true })) }), _jsx(form.FormError, {}), _jsx(form.SubmitButton, {})] }) }));
581
+ }, children: [requirePassword ? (_jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.user_field_password(), type: "password", autoComplete: "current-password", required: true })) })) : null, _jsx(form.FormError, {}), _jsx(form.SubmitButton, { children: m.user_two_factor_enable_submit() })] }) }));
563
582
  }
564
583
  function VerifyTotpSetup({ authClient, setup, onVerified, }) {
565
584
  const m = useUserButtonMessages();
@@ -588,15 +607,13 @@ function VerifyTotpSetup({ authClient, setup, onVerified, }) {
588
607
  form.handleSubmit();
589
608
  }, children: [_jsx(form.AppField, { name: "code", children: (field) => (_jsx(field.TextField, { label: m.user_two_factor_code(), autoComplete: "one-time-code", inputMode: "numeric", required: true })) }), _jsx(form.FormError, {}), _jsx(form.SubmitButton, {})] }) })] }));
590
609
  }
591
- function DisableTotpForm({ authClient, onDisabled, }) {
610
+ function DisableTotpForm({ authClient, requirePassword, onDisabled, }) {
592
611
  const m = useUserButtonMessages();
593
612
  const form = useAppForm({
594
613
  defaultValues: { password: "" },
595
614
  onSubmit: async ({ value, formApi }) => {
596
615
  formApi.setErrorMap({ onSubmit: undefined });
597
- const result = await authClient.twoFactor.disable({
598
- password: value.password,
599
- });
616
+ const result = await authClient.twoFactor.disable(requirePassword ? { password: value.password } : {});
600
617
  if (result.error) {
601
618
  formApi.setErrorMap({
602
619
  onSubmit: {
@@ -613,34 +630,30 @@ function DisableTotpForm({ authClient, onDisabled, }) {
613
630
  event.preventDefault();
614
631
  event.stopPropagation();
615
632
  form.handleSubmit();
616
- }, children: [_jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.user_field_password(), type: "password", autoComplete: "current-password", required: true })) }), _jsx(form.FormError, {}), _jsx(form.SubmitButton, {})] }) }));
633
+ }, children: [requirePassword ? (_jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.user_field_password(), type: "password", autoComplete: "current-password", required: true })) })) : null, _jsx(form.FormError, {}), _jsx(form.SubmitButton, {})] }) }));
617
634
  }
618
- function ApiKeyManager({ authClient, permissions = {}, }) {
635
+ function ApiKeyManager({ authClient, active, permissions = {}, }) {
619
636
  const m = useUserButtonMessages();
620
- const [keys, setKeys] = useState([]);
637
+ const hasOpened = useOpenedOnce(active);
638
+ const keysAtom = hasOpened ? userApiKeysAtom(authClient) : emptyApiKeysAtom;
639
+ const keysResult = useAtomValue(keysAtom);
640
+ const refreshKeys = useAtomRefresh(keysAtom);
621
641
  const [createdKey, setCreatedKey] = useState(null);
622
642
  const [copiedKey, setCopiedKey] = useState(false);
623
643
  const [error, setError] = useState(null);
624
- const [loading, setLoading] = useState(true);
625
644
  const permissionOptions = getPermissionOptions(permissions);
626
645
  const [selectedPermissions, setSelectedPermissions] = useState({});
627
- const loadKeys = useEffectEvent(async () => {
628
- setLoading(true);
629
- setError(null);
630
- const result = await authClient.apiKey.list({
631
- query: { configId: "user" },
632
- });
633
- if (result.error) {
634
- setError(result.error.message ?? m.user_api_keys_load_error());
635
- setLoading(false);
636
- return;
637
- }
638
- setKeys(result.data?.apiKeys ?? []);
639
- setLoading(false);
646
+ const keys = AsyncResult.match(keysResult, {
647
+ onInitial: () => [],
648
+ onFailure: () => [],
649
+ onSuccess: ({ value }) => Array.from(value),
650
+ });
651
+ const keysError = AsyncResult.match(keysResult, {
652
+ onInitial: () => null,
653
+ onFailure: () => m.user_api_keys_load_error(),
654
+ onSuccess: () => null,
640
655
  });
641
- useEffect(() => {
642
- void loadKeys();
643
- }, []);
656
+ const loading = keysResult._tag === "Initial";
644
657
  const createForm = useAppForm({
645
658
  defaultValues: { name: "" },
646
659
  onSubmit: async ({ value, formApi }) => {
@@ -657,7 +670,7 @@ function ApiKeyManager({ authClient, permissions = {}, }) {
657
670
  setCreatedKey(created.key);
658
671
  createForm.reset();
659
672
  setSelectedPermissions({});
660
- await loadKeys();
673
+ refreshKeys();
661
674
  }
662
675
  catch (cause) {
663
676
  formApi.setErrorMap({
@@ -690,13 +703,13 @@ function ApiKeyManager({ authClient, permissions = {}, }) {
690
703
  setError(result.error.message ?? m.user_api_key_delete_error());
691
704
  return;
692
705
  }
693
- await loadKeys();
706
+ refreshKeys();
694
707
  };
695
708
  return (_jsxs("div", { className: "flex flex-col gap-5", children: [_jsx(createForm.AppForm, { children: _jsxs("form", { className: "flex max-w-xl flex-col gap-4", onSubmit: (event) => {
696
709
  event.preventDefault();
697
710
  event.stopPropagation();
698
711
  createForm.handleSubmit();
699
- }, children: [_jsx("p", { className: "text-muted-foreground text-sm", children: m.api_key_rate_limit_notice() }), _jsx(createForm.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.user_api_key_name(), required: true })) }), permissionOptions.length > 0 ? (_jsxs(FieldSet, { children: [_jsx(FieldLegend, { children: m.user_api_key_permissions() }), _jsx(FieldDescription, { children: m.user_api_key_permissions_description() }), _jsx(FieldGroup, { "data-slot": "checkbox-group", className: "gap-3", children: permissionOptions.map((permission) => (_jsxs(Field, { orientation: "horizontal", children: [_jsx(Checkbox, { id: permission.id, checked: selectedPermissions[permission.id] ?? false, onCheckedChange: (checked) => togglePermission(permission.id, checked) }), _jsx(FieldContent, { children: _jsx(FieldLabel, { htmlFor: permission.id, children: permission.id }) })] }, permission.id))) })] })) : null, _jsx(createForm.FormError, {}), _jsx(createForm.SubmitButton, {})] }) }), createdKey ? (_jsxs("div", { className: "flex flex-col gap-2 rounded-lg border p-4", children: [_jsxs("div", { className: "flex items-center gap-2 font-medium", children: [_jsx(KeyRound, {}), m.user_api_key_created_title()] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_api_key_created_description() }), _jsxs("div", { className: "grid min-w-0 gap-2 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center", children: [_jsx("code", { className: "bg-muted block max-w-full overflow-x-auto rounded-md p-3 text-sm whitespace-nowrap", children: createdKey }), _jsxs(Button, { type: "button", variant: "outline", onClick: copyCreatedKey, className: "self-start sm:self-auto", children: [copiedKey ? _jsx(Check, {}) : _jsx(Copy, {}), copiedKey ? m.user_api_key_copied() : m.user_api_key_copy()] })] })] })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsx(Separator, {}), _jsx(DataTable, { columns: apiKeyColumns({ m }), data: keys, emptyLabel: loading ? m.user_loading() : m.table_empty(), exportFileName: m.user_api_keys_export_file_name(), features: { gallery: false }, rowActions: apiKeyRowActions({ m, onDelete: deleteKey }) })] }));
712
+ }, children: [_jsx("p", { className: "text-muted-foreground text-sm", children: m.api_key_rate_limit_notice() }), _jsx(createForm.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.user_api_key_name(), required: true })) }), permissionOptions.length > 0 ? (_jsxs(FieldSet, { children: [_jsx(FieldLegend, { children: m.user_api_key_permissions() }), _jsx(FieldDescription, { children: m.user_api_key_permissions_description() }), _jsx(FieldGroup, { "data-slot": "checkbox-group", className: "gap-3", children: permissionOptions.map((permission) => (_jsxs(Field, { orientation: "horizontal", children: [_jsx(Checkbox, { id: permission.id, checked: selectedPermissions[permission.id] ?? false, onCheckedChange: (checked) => togglePermission(permission.id, checked) }), _jsx(FieldContent, { children: _jsx(FieldLabel, { htmlFor: permission.id, children: permission.id }) })] }, permission.id))) })] })) : null, _jsx(createForm.FormError, {}), _jsx(createForm.SubmitButton, {})] }) }), createdKey ? (_jsxs("div", { className: "flex flex-col gap-2 rounded-lg border p-4", children: [_jsxs("div", { className: "flex items-center gap-2 font-medium", children: [_jsx(KeyRound, {}), m.user_api_key_created_title()] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_api_key_created_description() }), _jsxs("div", { className: "grid min-w-0 gap-2 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center", children: [_jsx("code", { className: "bg-muted block max-w-full overflow-x-auto rounded-md p-3 text-sm whitespace-nowrap", children: createdKey }), _jsxs(Button, { type: "button", variant: "outline", onClick: copyCreatedKey, className: "self-start sm:self-auto", children: [copiedKey ? _jsx(Check, {}) : _jsx(Copy, {}), copiedKey ? m.user_api_key_copied() : m.user_api_key_copy()] })] })] })) : null, keysError ? (_jsx("p", { className: "text-destructive text-sm", children: keysError })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsx(Separator, {}), _jsx(DataTable, { columns: apiKeyColumns({ m }), data: keys, emptyLabel: loading ? m.user_loading() : m.table_empty(), exportFileName: m.user_api_keys_export_file_name(), features: { gallery: false }, rowActions: apiKeyRowActions({ m, onDelete: deleteKey }) })] }));
700
713
  }
701
714
  const apiKeyColumns = ({ m, }) => [
702
715
  {
@@ -9,23 +9,37 @@ export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpA
9
9
  }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
10
10
  readonly id: import("effect/Schema").String;
11
11
  readonly key: import("effect/Schema").String;
12
- }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"presign", "POST", "/organizations/logo/presign", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
13
- readonly fileName: import("effect/Schema").NonEmptyString;
14
- readonly contentType: import("effect/Schema").NonEmptyString;
15
- }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
16
- readonly uploadUrl: import("effect/Schema").String;
17
- readonly url: import("effect/Schema").String;
18
- }>>, HttpApiEndpoint.Json<typeof HttpApiError.BadRequest | typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"presignUserImageUpload", "POST", "/auth/image/presign", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
19
- readonly fileName: import("effect/Schema").NonEmptyString;
20
- readonly contentType: import("effect/Schema").NonEmptyString;
21
- }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
22
- readonly uploadUrl: import("effect/Schema").String;
23
- readonly url: import("effect/Schema").String;
24
- }>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"setPassword", "POST", "/auth/set-password", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
12
+ }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getProjectPublicConfig", "GET", "/auth/project-config", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<import("effect/Schema").Struct<{
13
+ readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
14
+ readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
15
+ readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
16
+ }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
17
+ readonly projectKey: import("effect/Schema").String;
18
+ readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
19
+ readonly logoUrl: import("effect/Schema").NullOr<import("effect/Schema").String>;
20
+ readonly authDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
21
+ readonly rootDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
22
+ readonly themeCss: import("effect/Schema").NullOr<import("effect/Schema").String>;
23
+ readonly authOptions: import("effect/Schema").Struct<{
24
+ readonly emailPassword: import("effect/Schema").Boolean;
25
+ readonly emailOtp: import("effect/Schema").Boolean;
26
+ readonly google: import("effect/Schema").Boolean;
27
+ readonly signUp: import("effect/Schema").Boolean;
28
+ readonly signUpName: import("effect/Schema").Boolean;
29
+ }>;
30
+ }>>, HttpApiEndpoint.Json<typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"setPassword", "POST", "/auth/set-password", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
25
31
  readonly newPassword: import("effect/Schema").NonEmptyString;
26
32
  }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
27
33
  readonly ok: import("effect/Schema").Boolean;
28
- }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"verifyApiKey", "POST", "/auth/verify-api-key", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
34
+ }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"uploadOrganizationLogo", "POST", "/organizations/logo/upload", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/unstable/httpapi/HttpApiSchema").asMultipartStream<import("effect/Schema").Struct<{
35
+ readonly file: import("effect/Schema").decodeTo<import("effect/unstable/http/Multipart").PersistedFileSchema, import("effect/Schema").$Array<import("effect/unstable/http/Multipart").PersistedFileSchema>, never, never>;
36
+ }>>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
37
+ readonly url: import("effect/Schema").String;
38
+ }>>, HttpApiEndpoint.Json<typeof HttpApiError.BadRequest | typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"uploadUserImage", "POST", "/auth/image/upload", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/unstable/httpapi/HttpApiSchema").asMultipartStream<import("effect/Schema").Struct<{
39
+ readonly file: import("effect/Schema").decodeTo<import("effect/unstable/http/Multipart").PersistedFileSchema, import("effect/Schema").$Array<import("effect/unstable/http/Multipart").PersistedFileSchema>, never, never>;
40
+ }>>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
41
+ readonly url: import("effect/Schema").String;
42
+ }>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"verifyApiKey", "POST", "/auth/verify-api-key", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
29
43
  readonly key: import("effect/Schema").NonEmptyString;
30
44
  readonly configId: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>>;
31
45
  readonly permissions: import("effect/Schema").optional<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>;
@@ -62,23 +76,37 @@ export declare const ExtraApi: HttpApi.HttpApi<"ExtraApi", HttpApiGroup.HttpApiG
62
76
  }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
63
77
  readonly id: import("effect/Schema").String;
64
78
  readonly key: import("effect/Schema").String;
65
- }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"presign", "POST", "/api/organizations/logo/presign", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
66
- readonly fileName: import("effect/Schema").NonEmptyString;
67
- readonly contentType: import("effect/Schema").NonEmptyString;
68
- }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
69
- readonly uploadUrl: import("effect/Schema").String;
70
- readonly url: import("effect/Schema").String;
71
- }>>, HttpApiEndpoint.Json<typeof HttpApiError.BadRequest | typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"presignUserImageUpload", "POST", "/api/auth/image/presign", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
72
- readonly fileName: import("effect/Schema").NonEmptyString;
73
- readonly contentType: import("effect/Schema").NonEmptyString;
74
- }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
75
- readonly uploadUrl: import("effect/Schema").String;
76
- readonly url: import("effect/Schema").String;
77
- }>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"setPassword", "POST", "/api/auth/set-password", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
79
+ }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"getProjectPublicConfig", "GET", "/api/auth/project-config", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<import("effect/Schema").Struct<{
80
+ readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
81
+ readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
82
+ readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
83
+ }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
84
+ readonly projectKey: import("effect/Schema").String;
85
+ readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
86
+ readonly logoUrl: import("effect/Schema").NullOr<import("effect/Schema").String>;
87
+ readonly authDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
88
+ readonly rootDomain: import("effect/Schema").NullOr<import("effect/Schema").String>;
89
+ readonly themeCss: import("effect/Schema").NullOr<import("effect/Schema").String>;
90
+ readonly authOptions: import("effect/Schema").Struct<{
91
+ readonly emailPassword: import("effect/Schema").Boolean;
92
+ readonly emailOtp: import("effect/Schema").Boolean;
93
+ readonly google: import("effect/Schema").Boolean;
94
+ readonly signUp: import("effect/Schema").Boolean;
95
+ readonly signUpName: import("effect/Schema").Boolean;
96
+ }>;
97
+ }>>, HttpApiEndpoint.Json<typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"setPassword", "POST", "/api/auth/set-password", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
78
98
  readonly newPassword: import("effect/Schema").NonEmptyString;
79
99
  }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
80
100
  readonly ok: import("effect/Schema").Boolean;
81
- }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"verifyApiKey", "POST", "/api/auth/verify-api-key", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
101
+ }>>, HttpApiEndpoint.Json<typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"uploadOrganizationLogo", "POST", "/api/organizations/logo/upload", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/unstable/httpapi/HttpApiSchema").asMultipartStream<import("effect/Schema").Struct<{
102
+ readonly file: import("effect/Schema").decodeTo<import("effect/unstable/http/Multipart").PersistedFileSchema, import("effect/Schema").$Array<import("effect/unstable/http/Multipart").PersistedFileSchema>, never, never>;
103
+ }>>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
104
+ readonly url: import("effect/Schema").String;
105
+ }>>, HttpApiEndpoint.Json<typeof HttpApiError.BadRequest | typeof HttpApiError.Unauthorized | typeof HttpApiError.Forbidden | typeof HttpApiError.InternalServerError>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"uploadUserImage", "POST", "/api/auth/image/upload", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/unstable/httpapi/HttpApiSchema").asMultipartStream<import("effect/Schema").Struct<{
106
+ readonly file: import("effect/Schema").decodeTo<import("effect/unstable/http/Multipart").PersistedFileSchema, import("effect/Schema").$Array<import("effect/unstable/http/Multipart").PersistedFileSchema>, never, never>;
107
+ }>>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
108
+ readonly url: import("effect/Schema").String;
109
+ }>>, HttpApiEndpoint.Json<typeof HttpApiError.Unauthorized | typeof HttpApiError.InternalServerError | typeof ExtraBadRequest>, never, never> | HttpApiEndpoint.HttpApiEndpoint<"verifyApiKey", "POST", "/api/auth/verify-api-key", HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
82
110
  readonly key: import("effect/Schema").NonEmptyString;
83
111
  readonly configId: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"user">, import("effect/Schema").Literal<"organization">, import("effect/Schema").Literal<"service">]>>;
84
112
  readonly permissions: import("effect/Schema").optional<import("effect/Schema").$Record<import("effect/Schema").String, import("effect/Schema").$Array<import("effect/Schema").String>>>;
package/dist/extra/api.js CHANGED
@@ -1,7 +1,16 @@
1
1
  import { HttpApi, OpenApi } from "effect/unstable/httpapi";
2
2
  import { HttpApiEndpoint, HttpApiError, HttpApiGroup, } from "effect/unstable/httpapi";
3
- import { ExtraBadRequest, ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, ExtraOkResponse, ExtraPresignedUpload, ExtraPresignUploadPayload, ExtraSetPasswordPayload, ExtraVerifyApiKeyPayload, ExtraVerifyApiKeyResponse, ExtraVerifyPasswordPayload, } from "./schema";
3
+ import { ExtraBadRequest, ExtraCreateApiKeyPayload, ExtraCreateApiKeyResponse, ExtraImageUploadMultipartPayload, ExtraOkResponse, ExtraProjectPublicConfig, ExtraProjectPublicConfigQuery, ExtraSetPasswordPayload, ExtraUploadedAsset, ExtraVerifyApiKeyPayload, ExtraVerifyApiKeyResponse, ExtraVerifyPasswordPayload, } from "./schema";
4
4
  export const ExtraApiGroup = HttpApiGroup.make("authExtra")
5
+ .add(HttpApiEndpoint.get("getProjectPublicConfig", "/auth/project-config", {
6
+ query: ExtraProjectPublicConfigQuery,
7
+ success: ExtraProjectPublicConfig,
8
+ error: [HttpApiError.InternalServerError],
9
+ }).annotateMerge(OpenApi.annotations({
10
+ title: "Get project public config",
11
+ summary: "Get host-aware project white-label config",
12
+ description: "Returns resolved public branding and authentication options through the proxied auth API.",
13
+ })))
5
14
  .add(HttpApiEndpoint.post("setPassword", "/auth/set-password", {
6
15
  payload: ExtraSetPasswordPayload,
7
16
  success: ExtraOkResponse,
@@ -38,22 +47,22 @@ export const ExtraApiGroup = HttpApiGroup.make("authExtra")
38
47
  summary: "Verify a remote API key",
39
48
  description: "Verifies a user or organization API key and optional permissions using Better Auth's server-side API key verifier.",
40
49
  })))
41
- .add(HttpApiEndpoint.post("presignUserImageUpload", "/auth/image/presign", {
42
- payload: ExtraPresignUploadPayload,
43
- success: ExtraPresignedUpload,
50
+ .add(HttpApiEndpoint.post("uploadUserImage", "/auth/image/upload", {
51
+ payload: ExtraImageUploadMultipartPayload,
52
+ success: ExtraUploadedAsset,
44
53
  error: [
45
54
  ExtraBadRequest,
46
55
  HttpApiError.Unauthorized,
47
56
  HttpApiError.InternalServerError,
48
57
  ],
49
58
  }).annotateMerge(OpenApi.annotations({
50
- title: "Presign user image upload",
51
- summary: "Create a presigned user image upload URL",
52
- description: "Returns a short-lived S3 upload URL and stable asset URL for the current user's profile image.",
59
+ title: "Upload user image",
60
+ summary: "Upload a user profile image",
61
+ description: "Accepts a multipart image upload and stores it as the current user's profile image asset.",
53
62
  })))
54
- .add(HttpApiEndpoint.post("presign", "/organizations/logo/presign", {
55
- payload: ExtraPresignUploadPayload,
56
- success: ExtraPresignedUpload,
63
+ .add(HttpApiEndpoint.post("uploadOrganizationLogo", "/organizations/logo/upload", {
64
+ payload: ExtraImageUploadMultipartPayload,
65
+ success: ExtraUploadedAsset,
57
66
  error: [
58
67
  HttpApiError.BadRequest,
59
68
  HttpApiError.Unauthorized,