@krak-stack/auth 0.1.37 → 0.1.39

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.
@@ -2,6 +2,7 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
2
2
  // @ts-nocheck
3
3
  import { useAtomSuspense } from "@effect/atom-react";
4
4
  import { Link, useNavigate, useRouterState } from "@tanstack/react-router";
5
+ import { Atom, AsyncResult } from "effect/unstable/reactivity";
5
6
  import { REGEXP_ONLY_DIGITS } from "input-otp";
6
7
  import { KeyRound, Mail } from "lucide-react";
7
8
  import { useEffect, useState } from "react";
@@ -131,39 +132,44 @@ const useAuthFormOptions = ({ authClient, baseUrl, locale }) => {
131
132
  authClient: resolvedAuthClient,
132
133
  baseUrl: baseUrl ?? auth?.baseUrl,
133
134
  labels: labels(locale ?? auth?.locale ?? "en"),
135
+ projectConfig: auth?.projectConfig,
134
136
  };
135
137
  };
136
- const useAuthProjectConfig = (baseUrl, searchString) => {
138
+ const useAuthProjectConfig = (baseUrl, searchString, projectConfig) => {
137
139
  const projectId = getSearchParam(searchString, "projectId");
138
140
  const clientId = getSearchParam(searchString, "client_id");
139
141
  const host = getBrowserAuthHost();
140
- const result = useAtomSuspense(authApiClient(baseUrl).query("authExtra", "getProjectPublicConfig", {
141
- query: {
142
- ...(projectId ? { projectId } : {}),
143
- ...(clientId ? { clientId } : {}),
144
- ...(host ? { host } : {}),
145
- },
146
- timeToLive: "5 minutes",
147
- reactivityKeys: [
148
- "project-public-config",
149
- ...(projectId ? [`project:${projectId}`] : []),
150
- ...(clientId ? [`client:${clientId}`] : []),
151
- ...(host ? [`host:${host}`] : []),
152
- ],
153
- serializationKey: `project-public-config:${projectId ?? ""}:${clientId ?? ""}:${host ?? ""}`,
154
- }), { suspendOnWaiting: true });
142
+ const atom = projectConfig === undefined
143
+ ? authApiClient(baseUrl).query("authExtra", "getProjectPublicConfig", {
144
+ query: {
145
+ ...(projectId ? { projectId } : {}),
146
+ ...(clientId ? { clientId } : {}),
147
+ ...(host ? { host } : {}),
148
+ },
149
+ timeToLive: "5 minutes",
150
+ reactivityKeys: [
151
+ "project-public-config",
152
+ ...(projectId ? [`project:${projectId}`] : []),
153
+ ...(clientId ? [`client:${clientId}`] : []),
154
+ ...(host ? [`host:${host}`] : []),
155
+ ],
156
+ serializationKey: `project-public-config:${projectId ?? ""}:${clientId ?? ""}:${host ?? ""}`,
157
+ })
158
+ : Atom.make(AsyncResult.success(projectConfig));
159
+ const result = useAtomSuspense(atom, { suspendOnWaiting: true });
155
160
  return result.value;
156
161
  };
157
162
  const text = (value, params) => Object.entries(params ?? {}).reduce((current, [key, replacement]) => current.replace(`{${key}}`, replacement), value);
158
163
  const authLinkClassName = cn(buttonVariants({ variant: "link" }), "h-auto px-0 align-baseline");
164
+ const lastLoginMethodToAuthMethod = (method) => method === "email" ? "password" : "emailOtp";
159
165
  const searchObject = (searchString) => Object.fromEntries(new URLSearchParams(searchString));
160
166
  export function Signin(props) {
161
- const { authClient, baseUrl, labels: m } = useAuthFormOptions(props);
167
+ const { authClient, baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
162
168
  const navigate = useNavigate();
163
169
  const searchString = useRouterState({
164
170
  select: (state) => state.location.searchStr,
165
171
  });
166
- const projectConfig = useAuthProjectConfig(baseUrl, searchString);
172
+ const projectConfig = useAuthProjectConfig(baseUrl, searchString, providedProjectConfig);
167
173
  const redirectTarget = getRedirectTarget(searchString, projectConfig?.authDomain, projectConfig?.rootDomain);
168
174
  const socialRedirectTarget = getSocialRedirectTarget(searchString, projectConfig?.authDomain, projectConfig?.rootDomain);
169
175
  const oauthQuery = getOAuthQuery(searchString);
@@ -177,7 +183,7 @@ export function Signin(props) {
177
183
  signUp: authOptions.signUp ?? true,
178
184
  };
179
185
  const [emailSubmitted, setEmailSubmitted] = useState(false);
180
- const [authMethod, setAuthMethod] = useState("password");
186
+ const [authMethod, setAuthMethod] = useState(() => lastLoginMethodToAuthMethod(authClient.getLastUsedLoginMethod?.()));
181
187
  const [otpSentTo, setOtpSentTo] = useState("");
182
188
  const [emailOtpResendAvailableAt, setEmailOtpResendAvailableAt] = useState(0);
183
189
  const [emailOtpResendSeconds, setEmailOtpResendSeconds] = useState(0);
@@ -344,7 +350,12 @@ export function Signin(props) {
344
350
  event.preventDefault();
345
351
  event.stopPropagation();
346
352
  form.handleSubmit();
347
- }, children: [!emailSubmitted ? (_jsx(form.AppField, { name: "email", children: (field) => (_jsx(field.TextField, { label: m.field_email, type: "email", autoComplete: "email", required: true })) })) : null, emailSubmitted && selectedAuthMethod === "password" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.field_password, type: "password", autoComplete: "current-password", required: true })) }), _jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: [_jsx(Link, { className: authLinkClassName, to: "/forgot-password", search: searchObject(searchString), children: m.sign_in_forgot_password }), canChangeAuthMethod ? (_jsxs(Button, { type: "button", variant: "link", className: "h-auto px-0", onClick: switchAuthMethod, children: [_jsx(Mail, {}), m.sign_in_use_email_otp] })) : null] })] })) : null, emailSubmitted && selectedAuthMethod === "emailOtp" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.AppField, { name: "otp", children: (field) => (_jsx(OtpInput, { field: field, label: m.sign_in_email_otp_code })) }), _jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: [otpSentTo ? (_jsx(Button, { type: "button", variant: "link", className: "h-auto px-0", disabled: emailOtpResendSeconds > 0, onClick: resendEmailOtp, children: emailOtpResendSeconds > 0
353
+ }, children: [!emailSubmitted ? (_jsx(form.AppField, { name: "email", children: (field) => (_jsx(field.TextField, { label: m.field_email, type: "email", autoComplete: "email", onKeyDown: (event) => {
354
+ if (event.key !== "Enter")
355
+ return;
356
+ event.preventDefault();
357
+ form.handleSubmit();
358
+ }, required: true })) })) : null, emailSubmitted && selectedAuthMethod === "password" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.field_password, type: "password", autoComplete: "current-password", required: true })) }), _jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: [_jsx(Link, { className: authLinkClassName, to: "/forgot-password", search: searchObject(searchString), children: m.sign_in_forgot_password }), canChangeAuthMethod ? (_jsxs(Button, { type: "button", variant: "link", className: "h-auto px-0", onClick: switchAuthMethod, children: [_jsx(Mail, {}), m.sign_in_use_email_otp] })) : null] })] })) : null, emailSubmitted && selectedAuthMethod === "emailOtp" ? (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(form.AppField, { name: "otp", children: (field) => (_jsx(OtpInput, { field: field, label: m.sign_in_email_otp_code })) }), _jsxs("div", { className: "flex flex-wrap gap-x-4 gap-y-2 text-sm", children: [otpSentTo ? (_jsx(Button, { type: "button", variant: "link", className: "h-auto px-0", disabled: emailOtpResendSeconds > 0, onClick: resendEmailOtp, children: emailOtpResendSeconds > 0
348
359
  ? text(m.sign_in_email_otp_resend_countdown, {
349
360
  seconds: String(emailOtpResendSeconds),
350
361
  })
@@ -355,12 +366,12 @@ export function Signin(props) {
355
366
  : m.auth_sign_in }) })] }) })) : null, options.google && !emailSubmitted ? (_jsxs("div", { className: "mt-4 flex flex-col gap-3", children: [hasPrimaryAuth ? (_jsx(Divider, { label: m.auth_or_continue_with })) : null, _jsxs(Button, { type: "button", variant: "outline", className: "w-full", onClick: signInWithGoogle, children: [_jsx(GoogleLogo, {}), m.auth_continue_with_google] })] })) : null, !hasPrimaryAuth && !options.google ? (_jsx("p", { className: "text-muted-foreground text-sm", children: m.oauth_client_no_auth_methods })) : null, options.signUp ? (_jsxs("p", { className: "text-muted-foreground mt-6 text-center text-sm", children: [m.sign_in_need_account, " ", _jsx(Link, { className: authLinkClassName, to: "/sign-up", search: searchObject(searchString), children: m.auth_sign_up })] })) : null] })] }));
356
367
  }
357
368
  export function Signup(props) {
358
- const { authClient, baseUrl, labels: m } = useAuthFormOptions(props);
369
+ const { authClient, baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
359
370
  const navigate = useNavigate();
360
371
  const searchString = useRouterState({
361
372
  select: (state) => state.location.searchStr,
362
373
  });
363
- const projectConfig = useAuthProjectConfig(baseUrl, searchString);
374
+ const projectConfig = useAuthProjectConfig(baseUrl, searchString, providedProjectConfig);
364
375
  const redirectTarget = getRedirectTarget(searchString, projectConfig?.authDomain, projectConfig?.rootDomain);
365
376
  const authOptions = projectConfig?.authOptions ?? {};
366
377
  const onNavigate = (target) => navigate({ href: target });
@@ -479,12 +490,12 @@ export function ResetPassword(props) {
479
490
  }, children: [_jsx(form.AppField, { name: "password", children: (field) => (_jsx(field.TextField, { label: m.reset_password_new_password, type: "password", autoComplete: "new-password", minLength: 8, required: true })) }), _jsx(form.FormError, {}), _jsx(form.SubmitButton, {})] }) }) })] }));
480
491
  }
481
492
  export function TwoFactor(props) {
482
- const { authClient, baseUrl, labels: m } = useAuthFormOptions(props);
493
+ const { authClient, baseUrl, labels: m, projectConfig: providedProjectConfig, } = useAuthFormOptions(props);
483
494
  const navigate = useNavigate();
484
495
  const searchString = useRouterState({
485
496
  select: (state) => state.location.searchStr,
486
497
  });
487
- const projectConfig = useAuthProjectConfig(baseUrl, searchString);
498
+ const projectConfig = useAuthProjectConfig(baseUrl, searchString, providedProjectConfig);
488
499
  const redirectTarget = getRedirectTarget(searchString, projectConfig?.authDomain, projectConfig?.rootDomain);
489
500
  const oauthQuery = getOAuthQuery(searchString);
490
501
  const onNavigate = (target) => navigateTarget(target, navigate);
@@ -630,28 +641,8 @@ const getAuthRedirectParam = (searchString) => {
630
641
  search.get("redirectTo") ??
631
642
  search.get("returnTo"));
632
643
  };
633
- const getDefaultAuthRedirectTarget = (projectAuthDomain, projectRootDomain) => {
634
- if (typeof window === "undefined")
635
- return "/admin";
636
- const currentHost = normalizeAuthHost(window.location.host);
637
- const isProjectDomain = normalizeAuthHost(projectAuthDomain) === currentHost;
638
- if (!isProjectDomain)
639
- return "/admin";
640
- const rootDomain = normalizeAuthHost(projectRootDomain);
641
- if (!rootDomain)
642
- return "/admin";
643
- return `${window.location.protocol}//${rootDomain}`;
644
- };
645
- const normalizeAuthHost = (value) => {
646
- const raw = value?.trim().toLowerCase();
647
- if (!raw)
648
- return null;
649
- try {
650
- return new URL(raw.includes("://") ? raw : `https://${raw}`).host;
651
- }
652
- catch {
653
- return raw.split("/")[0]?.trim() || null;
654
- }
644
+ const getDefaultAuthRedirectTarget = (_projectAuthDomain, _projectRootDomain) => {
645
+ return "/admin";
655
646
  };
656
647
  const getSearchParam = (searchString, key) => new URLSearchParams(searchString).get(key);
657
648
  const getBrowserAuthHost = () => typeof window === "undefined" ? null : window.location.host;
@@ -1,16 +1,34 @@
1
1
  import { type ReactNode } from "react";
2
2
  import type { AuthUiClient } from "./auth-client";
3
+ import type { ExtraProjectPublicConfig } from "../extra/schema";
3
4
  export type KrakstackAuthLocale = "en" | "fr";
4
5
  export type KrakstackAuthProviderProps = {
5
6
  children: ReactNode;
6
7
  locale?: KrakstackAuthLocale | undefined;
7
8
  baseUrl?: string | undefined;
9
+ projectId?: string | null | undefined;
8
10
  authClient?: AuthUiClient | undefined;
9
11
  };
10
12
  export type KrakstackAuthContextValue = {
11
13
  locale: KrakstackAuthLocale;
12
14
  baseUrl?: string | undefined;
13
15
  authClient: AuthUiClient;
16
+ projectConfig: ExtraProjectPublicConfig | null;
14
17
  };
15
- export declare function KrakstackAuthProvider({ children, locale, baseUrl, authClient, }: KrakstackAuthProviderProps): import("react").JSX.Element;
18
+ export declare function KrakstackAuthProvider({ children, locale, baseUrl, projectId, authClient, }: KrakstackAuthProviderProps): import("react").JSX.Element;
16
19
  export declare const useKrakstackAuth: () => KrakstackAuthContextValue | null;
20
+ export declare const useKrakstackAuthProjectConfig: () => {
21
+ readonly projectKey: string;
22
+ readonly name: string | null;
23
+ readonly logoUrl: string | null;
24
+ readonly authDomain: string | null;
25
+ readonly rootDomain: string | null;
26
+ readonly themeCss: string | null;
27
+ readonly authOptions: {
28
+ readonly emailPassword: boolean;
29
+ readonly emailOtp: boolean;
30
+ readonly google: boolean;
31
+ readonly signUp: boolean;
32
+ readonly signUpName: boolean;
33
+ };
34
+ } | null;
@@ -1,22 +1,79 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { apiKeyClient } from "@better-auth/api-key/client";
3
- import { emailOTPClient, genericOAuthClient, organizationClient, twoFactorClient, } from "better-auth/client/plugins";
3
+ import { useAtomSuspense } from "@effect/atom-react";
4
+ import { useRouterState } from "@tanstack/react-router";
5
+ import { emailOTPClient, genericOAuthClient, lastLoginMethodClient, organizationClient, twoFactorClient, } from "better-auth/client/plugins";
4
6
  import { createAuthClient } from "better-auth/react";
5
7
  import { createContext, useContext, useMemo } from "react";
8
+ import { authApiClient } from "./auth-api-client";
6
9
  const KrakstackAuthContext = createContext(null);
7
10
  const createAuthUiClient = (baseUrl) => createAuthClient({
8
11
  ...(baseUrl ? { baseURL: baseUrl } : {}),
9
12
  plugins: [
10
13
  emailOTPClient(),
14
+ lastLoginMethodClient(),
11
15
  organizationClient(),
12
16
  twoFactorClient(),
13
17
  apiKeyClient(),
14
18
  genericOAuthClient(),
15
19
  ],
16
20
  });
17
- export function KrakstackAuthProvider({ children, locale = "en", baseUrl, authClient, }) {
21
+ const getSearchParam = (searchString, key) => {
22
+ if (!searchString)
23
+ return null;
24
+ return new URLSearchParams(searchString).get(key);
25
+ };
26
+ const getBrowserAuthHost = () => typeof window === "undefined" ? null : window.location.host;
27
+ const getRedirectHost = (searchString) => {
28
+ if (!searchString)
29
+ return null;
30
+ const search = new URLSearchParams(searchString);
31
+ const target = search.get("callbackURL") ??
32
+ search.get("redirect") ??
33
+ search.get("redirectTo") ??
34
+ search.get("returnTo") ??
35
+ search.get("redirect_uri");
36
+ if (!target)
37
+ return null;
38
+ try {
39
+ return new URL(target).host;
40
+ }
41
+ catch {
42
+ return null;
43
+ }
44
+ };
45
+ const useProjectConfig = (baseUrl, providedProjectId) => {
46
+ const searchString = useRouterState({
47
+ select: (state) => state.location.searchStr,
48
+ });
49
+ const projectId = providedProjectId ?? getSearchParam(searchString, "projectId");
50
+ const clientId = getSearchParam(searchString, "client_id");
51
+ const host = getBrowserAuthHost();
52
+ const rootHost = getRedirectHost(searchString);
53
+ const result = useAtomSuspense(authApiClient(baseUrl).query("authExtra", "getProjectPublicConfig", {
54
+ query: {
55
+ ...(projectId ? { projectId } : {}),
56
+ ...(clientId ? { clientId } : {}),
57
+ ...(host ? { host } : {}),
58
+ ...(rootHost ? { rootHost } : {}),
59
+ },
60
+ timeToLive: "5 minutes",
61
+ reactivityKeys: [
62
+ "project-public-config",
63
+ ...(projectId ? [`project:${projectId}`] : []),
64
+ ...(clientId ? [`client:${clientId}`] : []),
65
+ ...(host ? [`host:${host}`] : []),
66
+ ...(rootHost ? [`root-host:${rootHost}`] : []),
67
+ ],
68
+ serializationKey: `project-public-config:${projectId ?? ""}:${clientId ?? ""}:${host ?? ""}:${rootHost ?? ""}`,
69
+ }), { suspendOnWaiting: true });
70
+ return result.value;
71
+ };
72
+ export function KrakstackAuthProvider({ children, locale = "en", baseUrl, projectId, authClient, }) {
18
73
  const resolvedAuthClient = useMemo(() => authClient ?? createAuthUiClient(baseUrl), [authClient, baseUrl]);
19
- const value = useMemo(() => ({ authClient: resolvedAuthClient, baseUrl, locale }), [resolvedAuthClient, baseUrl, locale]);
74
+ const projectConfig = useProjectConfig(baseUrl, projectId);
75
+ const value = useMemo(() => ({ authClient: resolvedAuthClient, baseUrl, locale, projectConfig }), [resolvedAuthClient, baseUrl, locale, projectConfig]);
20
76
  return (_jsx(KrakstackAuthContext.Provider, { value: value, children: children }));
21
77
  }
22
78
  export const useKrakstackAuth = () => useContext(KrakstackAuthContext);
79
+ export const useKrakstackAuthProjectConfig = () => useKrakstackAuth()?.projectConfig ?? null;
@@ -1,4 +1,4 @@
1
- export { KrakstackAuthProvider, useKrakstackAuth } from "./auth-provider";
1
+ export { KrakstackAuthProvider, useKrakstackAuth, useKrakstackAuthProjectConfig, } from "./auth-provider";
2
2
  export { OrganizationSwitcher } from "./organization-switcher";
3
3
  export { ResetPassword, Signin, Signup, TwoFactor } from "./auth-forms";
4
4
  export { UserButton } from "./user-button";
@@ -1,4 +1,4 @@
1
- export { KrakstackAuthProvider, useKrakstackAuth } from "./auth-provider";
1
+ export { KrakstackAuthProvider, useKrakstackAuth, useKrakstackAuthProjectConfig, } from "./auth-provider";
2
2
  export { OrganizationSwitcher } from "./organization-switcher";
3
3
  export { ResetPassword, Signin, Signup, TwoFactor } from "./auth-forms";
4
4
  export { UserButton } from "./user-button";
@@ -18,6 +18,7 @@ import { Field, FieldContent, FieldDescription, FieldGroup, FieldLabel, FieldLeg
18
18
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
19
19
  import { Separator } from "@/components/ui/separator";
20
20
  import { authApiClient } from "./auth-api-client";
21
+ import { useKrakstackAuthProjectConfig } from "./auth-provider";
21
22
  import { createApiKey } from "./api-key";
22
23
  import { useOpenedOnce } from "./hooks";
23
24
  import { ExtraUploadedAsset } from "../extra/schema";
@@ -219,6 +220,7 @@ const uploadUserImageAsset = async (file, m, uploadUserImage) => {
219
220
  throw new Error(m.user_profile_image_upload_error());
220
221
  }
221
222
  };
223
+ const requiresPasswordForAccountRevoke = (accounts) => accounts.some((account) => account.providerId === "credential");
222
224
  const userAccountsAtom = Atom.family((authClient) => Atom.keepAlive(Atom.make(Effect.tryPromise({
223
225
  try: async () => {
224
226
  const result = await authClient.listAccounts();
@@ -246,6 +248,7 @@ const emptyApiKeysAtom = Atom.make(Effect.succeed([]));
246
248
  export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side = "bottom", defaultDialog = null, hideTrigger = false, renderUnauthenticated, apiKeyPermissions, messages, dialog: controlledDialog, onDialogChange, }) => {
247
249
  const labels = userButtonMessages(messages);
248
250
  const m = userButtonMessageFns(labels);
251
+ const projectConfig = useKrakstackAuthProjectConfig();
249
252
  const navigate = useNavigate();
250
253
  const currentSiteHref = useRouterState({
251
254
  select: (state) => `${import.meta.env.VITE_SITE_URL}${state.location.href}`,
@@ -331,21 +334,27 @@ export const UserButton = ({ authClient, baseUrl, signOutRedirect = "/", side =
331
334
  ? error.message
332
335
  : m.user_form_update_error());
333
336
  }
334
- } }), _jsx(Separator, {}), _jsx(ConnectedAccounts, { authClient: authClient, baseUrl: baseUrl, accountCache: accountCache, currentSiteHref: currentSiteHref, navigate: navigate })] }))] }) }), _jsx(Dialog, { open: settingsDialog === "security", onOpenChange: (open) => {
337
+ } }), _jsx(Separator, {}), _jsx(ConnectedAccounts, { authClient: authClient, baseUrl: baseUrl, accountCache: accountCache, googleEnabled: projectConfig?.authOptions.google ?? true, currentSiteHref: currentSiteHref, navigate: navigate })] }))] }) }), _jsx(Dialog, { open: settingsDialog === "security", onOpenChange: (open) => {
335
338
  setSettingsDialog((current) => open ? "security" : current === "security" ? null : current);
336
339
  }, 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) => {
337
340
  setSettingsDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
338
341
  }, 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 ?? {} })] }) })] }));
339
342
  };
340
- function ConnectedAccounts({ authClient, baseUrl, accountCache, currentSiteHref, navigate, }) {
343
+ function ConnectedAccounts({ authClient, baseUrl, accountCache, googleEnabled, currentSiteHref, navigate, }) {
341
344
  const m = useUserButtonMessages();
345
+ const [error, setError] = useState(null);
342
346
  const [isLinking, setIsLinking] = useState(false);
343
347
  const [revokingAccount, setRevokingAccount] = useState(null);
344
348
  const accounts = accountCache.accounts ?? [];
345
349
  const googleAccount = accounts.find((account) => account.providerId === "google");
346
- const hasPassword = accounts.some((account) => account.providerId === "credential");
347
- const canRevokeAccount = accounts.length > 1;
350
+ const requirePassword = requiresPasswordForAccountRevoke(accounts);
351
+ const showGoogleAccount = googleEnabled || Boolean(googleAccount);
352
+ if (accountCache.accounts && (accounts.length === 0 || !showGoogleAccount)) {
353
+ return null;
354
+ }
348
355
  const linkGoogle = async () => {
356
+ if (!googleEnabled)
357
+ return;
349
358
  setError(null);
350
359
  setIsLinking(true);
351
360
  const result = await authClient.linkSocial({
@@ -376,13 +385,13 @@ function ConnectedAccounts({ authClient, baseUrl, accountCache, currentSiteHref,
376
385
  setRevokingAccount(null);
377
386
  await accountCache.reload();
378
387
  };
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] }));
388
+ 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: [showGoogleAccount ? (_jsx(AccountProviderRow, { icon: _jsx(GoogleLogo, {}), title: m.user_account_google_title(), description: m.user_account_google_description(), account: googleAccount, connected: Boolean(googleAccount), connectLabel: m.user_account_google_connect(), revokeLabel: m.user_account_revoke(), isConnecting: isLinking, renderDisconnected: undefined, onConnect: linkGoogle, onRevoke: (account) => setRevokingAccount(account) })) : null, revokingAccount ? (_jsx(RevokeAccountForm, { baseUrl: baseUrl, account: revokingAccount, requirePassword: requirePassword, 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, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }));
380
389
  }
381
- function AccountProviderRow({ icon, title, description, account, connected, canRevoke, connectLabel, revokeLabel, onlyMethodLabel, isConnecting, renderDisconnected, onConnect, onRevoke, }) {
390
+ function AccountProviderRow({ icon, title, description, account, connected, connectLabel, revokeLabel, isConnecting, renderDisconnected, onConnect, onRevoke, }) {
382
391
  const m = useUserButtonMessages();
383
392
  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
384
393
  ? m.user_account_connected()
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 }))] }) }));
394
+ : m.user_account_not_connected() })] }), _jsx("p", { className: "text-muted-foreground text-sm", children: description })] })] }), connected && account ? (_jsx(Button, { type: "button", variant: "outline", onClick: () => onRevoke(account), children: revokeLabel })) : renderDisconnected ? (renderDisconnected) : (_jsx(Button, { type: "button", variant: "outline", disabled: isConnecting, onClick: onConnect, children: connectLabel }))] }) }));
386
395
  }
387
396
  function GoogleLogo() {
388
397
  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" })] }));
@@ -394,7 +403,7 @@ function PasswordSettings({ authClient, baseUrl, accountCache, }) {
394
403
  const accounts = accountCache.accounts ?? [];
395
404
  const passwordAccount = accounts.find((account) => account.providerId === "credential");
396
405
  const hasPassword = Boolean(passwordAccount);
397
- const canRevokeAccount = accounts.length > 1;
406
+ const requirePassword = requiresPasswordForAccountRevoke(accounts);
398
407
  const revokePassword = async (account) => {
399
408
  setError(null);
400
409
  const result = await authClient.unlinkAccount({
@@ -408,9 +417,7 @@ function PasswordSettings({ authClient, baseUrl, accountCache, }) {
408
417
  setRevokingAccount(null);
409
418
  await accountCache.reload();
410
419
  };
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
412
- ? m.user_account_revoke()
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] }));
420
+ 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", onClick: () => setRevokingAccount(passwordAccount), children: m.user_account_revoke() })] }), revokingAccount ? (_jsx(RevokeAccountForm, { baseUrl: baseUrl, account: revokingAccount, requirePassword: requirePassword, 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] }));
414
421
  }
415
422
  function ChangePasswordForm({ authClient }) {
416
423
  const m = useUserButtonMessages();
@@ -470,7 +477,7 @@ function SetPasswordForm({ authClient, onSaved, }) {
470
477
  event.preventDefault();
471
478
  event.stopPropagation();
472
479
  form.handleSubmit();
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() })] }) }));
480
+ }, 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(form.SubmitButton, { children: m.user_account_password_set() })] }) }));
474
481
  }
475
482
  function RevokeAccountForm({ baseUrl, account, requirePassword, onCancel, onRevoke, }) {
476
483
  const m = useUserButtonMessages();
@@ -13,6 +13,7 @@ export declare const ExtraApiGroup: HttpApiGroup.HttpApiGroup<"authExtra", HttpA
13
13
  readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
14
14
  readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
15
15
  readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
16
+ readonly rootHost: import("effect/Schema").optional<import("effect/Schema").String>;
16
17
  }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
17
18
  readonly projectKey: import("effect/Schema").String;
18
19
  readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
@@ -80,6 +81,7 @@ export declare const ExtraApi: HttpApi.HttpApi<"ExtraApi", HttpApiGroup.HttpApiG
80
81
  readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
81
82
  readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
82
83
  readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
84
+ readonly rootHost: import("effect/Schema").optional<import("effect/Schema").String>;
83
85
  }>>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.StringTree<never>, HttpApiEndpoint.Json<import("effect/Schema").Struct<{
84
86
  readonly projectKey: import("effect/Schema").String;
85
87
  readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
@@ -11,6 +11,7 @@ declare const ExtraApiClient_base: AtomHttpApi.AtomHttpApiClient<ExtraApiClient,
11
11
  readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
12
12
  readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
13
13
  readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
14
+ readonly rootHost: import("effect/Schema").optional<import("effect/Schema").String>;
14
15
  }>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
15
16
  readonly projectKey: import("effect/Schema").String;
16
17
  readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
@@ -73,6 +73,7 @@ export declare const ExtraProjectPublicConfigQuery: Schema.Struct<{
73
73
  readonly projectId: Schema.optional<Schema.String>;
74
74
  readonly clientId: Schema.optional<Schema.String>;
75
75
  readonly host: Schema.optional<Schema.String>;
76
+ readonly rootHost: Schema.optional<Schema.String>;
76
77
  }>;
77
78
  export declare const ExtraProjectAuthOptions: Schema.Struct<{
78
79
  readonly emailPassword: Schema.Boolean;
@@ -139,6 +139,7 @@ export const ExtraProjectPublicConfigQuery = Schema.Struct({
139
139
  projectId: Schema.optional(Schema.String),
140
140
  clientId: Schema.optional(Schema.String),
141
141
  host: Schema.optional(Schema.String),
142
+ rootHost: Schema.optional(Schema.String),
142
143
  }).annotate({
143
144
  identifier: "ExtraProjectPublicConfigQuery",
144
145
  title: "Extra project public config query",
@@ -147,6 +148,7 @@ export const ExtraProjectPublicConfigQuery = Schema.Struct({
147
148
  {
148
149
  projectId: "project-id",
149
150
  host: "auth.example.com",
151
+ rootHost: "example.com",
150
152
  clientId: "oauth-client-id",
151
153
  },
152
154
  ],
package/dist/schema.d.ts CHANGED
@@ -7,6 +7,7 @@ export declare const User: Schema.Struct<{
7
7
  readonly image: Schema.NullOr<Schema.String>;
8
8
  readonly role: Schema.NullOr<Schema.String>;
9
9
  readonly banned: Schema.NullOr<Schema.Boolean>;
10
+ readonly lastLoginMethod: Schema.optional<Schema.NullOr<Schema.String>>;
10
11
  readonly createdAt: Schema.Date;
11
12
  readonly updatedAt: Schema.Date;
12
13
  }>;
@@ -72,6 +73,7 @@ export declare const Member: Schema.Struct<{
72
73
  readonly image: Schema.NullOr<Schema.String>;
73
74
  readonly role: Schema.NullOr<Schema.String>;
74
75
  readonly banned: Schema.NullOr<Schema.Boolean>;
76
+ readonly lastLoginMethod: Schema.optional<Schema.NullOr<Schema.String>>;
75
77
  readonly createdAt: Schema.Date;
76
78
  readonly updatedAt: Schema.Date;
77
79
  }>;
package/dist/schema.js CHANGED
@@ -7,6 +7,7 @@ export const User = Schema.Struct({
7
7
  image: Schema.NullOr(Schema.String),
8
8
  role: Schema.NullOr(Schema.String),
9
9
  banned: Schema.NullOr(Schema.Boolean),
10
+ lastLoginMethod: Schema.optional(Schema.NullOr(Schema.String)),
10
11
  createdAt: Schema.Date,
11
12
  updatedAt: Schema.Date,
12
13
  }).annotate({
@@ -22,6 +23,7 @@ export const User = Schema.Struct({
22
23
  image: null,
23
24
  role: "admin",
24
25
  banned: false,
26
+ lastLoginMethod: "email-otp",
25
27
  createdAt: new Date("2026-01-01T00:00:00.000Z"),
26
28
  updatedAt: new Date("2026-01-01T00:00:00.000Z"),
27
29
  },
@@ -168,6 +170,7 @@ export const Member = Schema.Struct({
168
170
  image: null,
169
171
  role: "admin",
170
172
  banned: false,
173
+ lastLoginMethod: "email-otp",
171
174
  createdAt: new Date("2026-01-01T00:00:00.000Z"),
172
175
  updatedAt: new Date("2026-01-01T00:00:00.000Z"),
173
176
  },