@remit/web-client 0.0.331 → 0.0.333

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.
Files changed (46) hide show
  1. package/dist/src/auth/AccountMenu.js +1 -1
  2. package/dist/src/auth/BetterAuthShell.d.ts +12 -2
  3. package/dist/src/auth/BetterAuthShell.js +40 -7
  4. package/dist/src/auth/ResetPasswordPage.d.ts +12 -0
  5. package/dist/src/auth/ResetPasswordPage.js +98 -0
  6. package/dist/src/auth/auth-refusal.d.ts +10 -0
  7. package/dist/src/auth/auth-refusal.js +14 -0
  8. package/dist/src/auth/better-auth-config.js +4 -0
  9. package/dist/src/auth/provider.d.ts +1 -0
  10. package/dist/src/auth/session-state.d.ts +8 -3
  11. package/dist/src/auth/session-state.js +8 -3
  12. package/dist/src/components/settings/people/PeoplePanel.d.ts +1 -0
  13. package/dist/src/components/settings/people/PeoplePanel.js +72 -0
  14. package/dist/src/components/settings/people/PersonActionDialog.d.ts +11 -0
  15. package/dist/src/components/settings/people/PersonActionDialog.js +52 -0
  16. package/dist/src/components/settings/people/ResetLinkDialog.d.ts +11 -0
  17. package/dist/src/components/settings/people/ResetLinkDialog.js +23 -0
  18. package/dist/src/hooks/usePeople.d.ts +174 -0
  19. package/dist/src/hooks/usePeople.js +28 -0
  20. package/dist/src/hooks/usePersonAction.d.ts +17 -0
  21. package/dist/src/hooks/usePersonAction.js +60 -0
  22. package/dist/src/lib/error-classifier.d.ts +16 -4
  23. package/dist/src/lib/error-classifier.js +28 -7
  24. package/dist/src/lib/network-error.d.ts +8 -0
  25. package/dist/src/lib/network-error.js +12 -1
  26. package/dist/src/lib/people.d.ts +49 -0
  27. package/dist/src/lib/people.js +125 -0
  28. package/dist/src/lib/rum-adapter.js +4 -1
  29. package/dist/src/routeTree.gen.d.ts +29 -3
  30. package/dist/src/routeTree.gen.js +14 -0
  31. package/dist/src/routes/reset-password/$token.d.ts +5 -0
  32. package/dist/src/routes/reset-password/$token.js +10 -0
  33. package/dist/src/routes/settings/accounts.js +3 -2
  34. package/dist/src/routes/settings/advanced.js +3 -2
  35. package/dist/src/routes/settings/appearance.js +3 -2
  36. package/dist/src/routes/settings/calendars.js +3 -2
  37. package/dist/src/routes/settings/filters.js +3 -2
  38. package/dist/src/routes/settings/folders.js +3 -2
  39. package/dist/src/routes/settings/labels.js +3 -2
  40. package/dist/src/routes/settings/people.d.ts +1 -0
  41. package/dist/src/routes/settings/people.js +20 -0
  42. package/dist/src/routes/settings/senders.js +3 -2
  43. package/dist/src/routes/settings/warnings.js +3 -2
  44. package/dist/src/routes/settings.d.ts +5 -0
  45. package/dist/src/routes/settings.js +23 -1
  46. package/package.json +2 -2
@@ -1,4 +1,4 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { AccountMenu as AccountMenuView } from "@remit/ui";
3
3
  import { AccountSession } from "./AccountSession";
4
- export const AccountMenu = () => (_jsx(AccountSession, { children: ({ email, signOut }) => (_jsx(AccountMenuView, { email: email, onSignOut: signOut })) }));
4
+ export const AccountMenu = () => (_jsx(AccountSession, { children: ({ email, signOut, securityUrl }) => (_jsx(AccountMenuView, { email: email, securityUrl: securityUrl, onSignOut: signOut })) }));
@@ -1,18 +1,28 @@
1
1
  import { type ReactNode } from "react";
2
+ import { type AuthRefusal } from "./auth-refusal";
2
3
  import { type SessionQuery } from "./session-state";
3
4
  interface BetterAuthShellProps {
4
5
  children: ReactNode;
5
6
  }
6
- export declare const SignInForm: () => import("react").JSX.Element;
7
+ export type SignInNotice = AuthRefusal | "passwordChanged";
8
+ interface SignInFormProps {
9
+ notice?: SignInNotice;
10
+ }
11
+ export declare const SignInForm: ({ notice: initialNotice }: SignInFormProps) => import("react").JSX.Element;
7
12
  interface SessionGateProps {
8
13
  session: SessionQuery;
9
14
  onRetry: () => void;
15
+ notice?: SignInNotice;
10
16
  children: ReactNode;
11
17
  }
12
18
  /**
13
19
  * What the app shows for each state the session lookup can be in, separated
14
20
  * from the hook that feeds it so every state can be driven directly.
15
21
  */
16
- export declare const SessionGate: ({ session, onRetry, children, }: SessionGateProps) => import("react").JSX.Element;
22
+ export declare const SessionGate: ({ session, onRetry, notice, children, }: SessionGateProps) => import("react").JSX.Element;
23
+ /**
24
+ * The gate, plus the one page that stands before it: a reset link opens its
25
+ * page signed out, and setting the password leads to the sign-in form.
26
+ */
17
27
  export declare const BetterAuthShell: ({ children }: BetterAuthShellProps) => import("react").JSX.Element;
18
28
  export {};
@@ -1,12 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { AuthCard, AuthFooter, AuthHero, Banner, Button, Input, PasswordInput, } from "@remit/ui";
3
- import { useState } from "react";
3
+ import { useEffect, useRef, useState, } from "react";
4
4
  import { AppShellSkeleton } from "../components/layout/AppShellSkeleton";
5
5
  import { FatalErrorOverlay } from "../components/ui/FatalErrorOverlay";
6
6
  import { openBugReport } from "../lib/bug-report";
7
7
  import { authFooterNote } from "./account-menu-mode";
8
8
  import { authInlineMessage, classifyAuthError, reportFatalAuthError, } from "./auth-error";
9
+ import { authRefusal } from "./auth-refusal";
9
10
  import { authClient, isBetterAuthEnabled, isSignUpDisabledError, } from "./better-auth-config";
11
+ import { ResetPasswordPage, resetPasswordToken } from "./ResetPasswordPage";
10
12
  import { SessionRateLimited } from "./SessionRateLimited";
11
13
  import { classifySessionQuery } from "./session-state";
12
14
  const SIGN_UP_REQUEST = {
@@ -17,7 +19,14 @@ const SIGN_IN_REQUEST = {
17
19
  method: "POST",
18
20
  path: "/api/auth/sign-in/email",
19
21
  };
20
- export const SignInForm = () => {
22
+ const NoticeBanner = ({ notice }) => {
23
+ const ref = useRef(null);
24
+ useEffect(() => {
25
+ ref.current?.focus();
26
+ }, []);
27
+ return (_jsxs("div", { ref: ref, tabIndex: -1, className: "outline-none", children: [notice === "signInOff" && (_jsxs(Banner, { tone: "info", children: [_jsx("p", { className: "font-medium", children: "Sign-in is turned off on this server." }), _jsx("p", { className: "mt-1", children: "The person who runs this server turned it off. Ask them when it is back." })] })), notice === "accountDisabled" && (_jsxs(Banner, { tone: "danger", children: [_jsx("p", { className: "font-medium", children: "This account is disabled." }), _jsx("p", { className: "mt-1", children: "Ask the person who runs this server." })] })), notice === "passwordChanged" && (_jsx(Banner, { tone: "success", children: "Password changed. Sign in with your new password." }))] }));
28
+ };
29
+ export const SignInForm = ({ notice: initialNotice }) => {
21
30
  const [mode, setMode] = useState("signIn");
22
31
  const [name, setName] = useState("");
23
32
  const [email, setEmail] = useState("");
@@ -27,8 +36,15 @@ export const SignInForm = () => {
27
36
  // Learned from the server's rejection, never a client-side flag — the UI
28
37
  // cannot disagree with better-auth's `disableSignUp`.
29
38
  const [signUpClosed, setSignUpClosed] = useState(false);
30
- const activeMode = signUpClosed ? "signIn" : mode;
39
+ const [notice, setNotice] = useState(initialNotice);
40
+ const signInOff = notice === "signInOff";
41
+ const activeMode = signUpClosed || signInOff ? "signIn" : mode;
31
42
  const handleFailure = (failure, request) => {
43
+ const refusal = authRefusal(failure);
44
+ if (refusal) {
45
+ setNotice(refusal);
46
+ return;
47
+ }
32
48
  if (isSignUpDisabledError(failure)) {
33
49
  setSignUpClosed(true);
34
50
  setMode("signIn");
@@ -46,6 +62,7 @@ export const SignInForm = () => {
46
62
  if (submitting)
47
63
  return;
48
64
  setError(null);
65
+ setNotice(undefined);
49
66
  setSubmitting(true);
50
67
  const request = activeMode === "signUp" ? SIGN_UP_REQUEST : SIGN_IN_REQUEST;
51
68
  // better-auth returns `{ error }` for a server rejection, but a network
@@ -60,7 +77,7 @@ export const SignInForm = () => {
60
77
  if (failure)
61
78
  handleFailure(failure, request);
62
79
  };
63
- return (_jsxs(_Fragment, { children: [_jsx(FatalErrorOverlay, {}), _jsxs(AuthCard, { children: [_jsx(AuthHero, {}), _jsxs("form", { onSubmit: submit, className: "mt-6 flex flex-col gap-4 rounded-lg border border-line bg-surface p-7 shadow-lg", children: [signUpClosed ? (_jsx(Banner, { tone: "info", children: "New signups are currently closed. Sign in with an existing account, or contact your administrator for access." })) : (_jsxs("div", { className: "flex gap-1", children: [_jsx(Button, { size: "sm", variant: activeMode === "signIn" ? "secondary" : "ghost", "aria-pressed": activeMode === "signIn", onClick: () => setMode("signIn"), children: "Sign in" }), _jsx(Button, { size: "sm", variant: activeMode === "signUp" ? "secondary" : "ghost", "aria-pressed": activeMode === "signUp", onClick: () => setMode("signUp"), children: "Create account" })] })), error && _jsx(Banner, { tone: "danger", children: error }), activeMode === "signUp" && (_jsxs("div", { className: "flex flex-col gap-1 text-sm", children: [_jsx("label", { htmlFor: "ba-name", className: "text-fg-muted", children: "Name" }), _jsx(Input, { id: "ba-name", type: "text", autoComplete: "name", value: name, onChange: (e) => setName(e.target.value), placeholder: "Your name", required: true })] })), _jsxs("div", { className: "flex flex-col gap-1 text-sm", children: [_jsx("label", { htmlFor: "ba-email", className: "text-fg-muted", children: "Email" }), _jsx(Input, { id: "ba-email", type: "email", autoComplete: "email", value: email, onChange: (e) => setEmail(e.target.value), placeholder: "you@example.com", required: true })] }), _jsxs("div", { className: "flex flex-col gap-1 text-sm", children: [_jsx("label", { htmlFor: "ba-password", className: "text-fg-muted", children: "Password" }), _jsx(PasswordInput, { id: "ba-password", autoComplete: activeMode === "signUp" ? "new-password" : "current-password", value: password, onChange: (e) => setPassword(e.target.value), placeholder: "Your password", required: true })] }), _jsx(Button, { type: "submit", children: activeMode === "signUp" ? "Create account" : "Sign in" })] }), _jsx(AuthFooter, { note: authFooterNote({
80
+ return (_jsxs(_Fragment, { children: [_jsx(FatalErrorOverlay, {}), _jsxs(AuthCard, { children: [_jsx(AuthHero, {}), _jsxs("form", { onSubmit: submit, className: "mt-6 flex flex-col gap-4 rounded-lg border border-line bg-surface p-7 shadow-lg", children: [notice && _jsx(NoticeBanner, { notice: notice }, notice), signInOff ? null : signUpClosed ? (_jsx(Banner, { tone: "info", children: "New signups are currently closed. Sign in with an existing account, or contact your administrator for access." })) : (_jsxs("div", { className: "flex gap-1", children: [_jsx(Button, { size: "sm", variant: activeMode === "signIn" ? "secondary" : "ghost", "aria-pressed": activeMode === "signIn", onClick: () => setMode("signIn"), children: "Sign in" }), _jsx(Button, { size: "sm", variant: activeMode === "signUp" ? "secondary" : "ghost", "aria-pressed": activeMode === "signUp", onClick: () => setMode("signUp"), children: "Create account" })] })), error && _jsx(Banner, { tone: "danger", children: error }), activeMode === "signUp" && (_jsxs("div", { className: "flex flex-col gap-1 text-sm", children: [_jsx("label", { htmlFor: "ba-name", className: "text-fg-muted", children: "Name" }), _jsx(Input, { id: "ba-name", type: "text", autoComplete: "name", value: name, onChange: (e) => setName(e.target.value), placeholder: "Your name", required: true })] })), _jsxs("div", { className: "flex flex-col gap-1 text-sm", children: [_jsx("label", { htmlFor: "ba-email", className: "text-fg-muted", children: "Email" }), _jsx(Input, { id: "ba-email", type: "email", autoComplete: "email", value: email, onChange: (e) => setEmail(e.target.value), placeholder: "you@example.com", required: true, disabled: signInOff })] }), _jsxs("div", { className: "flex flex-col gap-1 text-sm", children: [_jsx("label", { htmlFor: "ba-password", className: "text-fg-muted", children: "Password" }), _jsx(PasswordInput, { id: "ba-password", autoComplete: activeMode === "signUp" ? "new-password" : "current-password", value: password, onChange: (e) => setPassword(e.target.value), placeholder: "Your password", required: true, disabled: signInOff })] }), _jsx(Button, { type: "submit", disabled: signInOff, children: activeMode === "signUp" ? "Create account" : "Sign in" })] }), _jsx(AuthFooter, { note: authFooterNote({
64
81
  betterAuthEnabled: isBetterAuthEnabled(),
65
82
  cognitoConfigured: false,
66
83
  }) })] })] }));
@@ -69,7 +86,7 @@ export const SignInForm = () => {
69
86
  * What the app shows for each state the session lookup can be in, separated
70
87
  * from the hook that feeds it so every state can be driven directly.
71
88
  */
72
- export const SessionGate = ({ session, onRetry, children, }) => {
89
+ export const SessionGate = ({ session, onRetry, notice, children, }) => {
73
90
  const state = classifySessionQuery(session);
74
91
  if (state.kind === "active")
75
92
  return _jsx(_Fragment, { children: children });
@@ -78,11 +95,27 @@ export const SessionGate = ({ session, onRetry, children, }) => {
78
95
  if (state.kind === "rateLimited") {
79
96
  return _jsx(SessionRateLimited, { onRetry: onRetry, onReport: openBugReport });
80
97
  }
81
- return _jsx(SignInForm, {});
98
+ if (state.kind === "refused") {
99
+ return _jsx(SignInForm, { notice: state.refusal }, state.refusal);
100
+ }
101
+ return _jsx(SignInForm, { notice: notice });
82
102
  };
103
+ /**
104
+ * The gate, plus the one page that stands before it: a reset link opens its
105
+ * page signed out, and setting the password leads to the sign-in form.
106
+ */
83
107
  export const BetterAuthShell = ({ children }) => {
84
108
  const { data, isPending, error, refetch } = authClient.useSession();
109
+ const [resetToken, setResetToken] = useState(() => resetPasswordToken(window.location.pathname));
110
+ const [notice, setNotice] = useState(undefined);
111
+ if (resetToken) {
112
+ return (_jsx(ResetPasswordPage, { token: resetToken, onDone: () => {
113
+ window.history.replaceState(null, "", "/");
114
+ setResetToken(undefined);
115
+ setNotice("passwordChanged");
116
+ } }));
117
+ }
85
118
  return (_jsx(SessionGate, { session: { data, isPending, error }, onRetry: () => {
86
119
  void refetch();
87
- }, children: children }));
120
+ }, notice: notice, children: children }));
88
121
  };
@@ -0,0 +1,12 @@
1
+ export declare const resetPasswordToken: (pathname: string) => string | undefined;
2
+ interface ResetPasswordPageProps {
3
+ token: string;
4
+ onDone: () => void;
5
+ }
6
+ /**
7
+ * Where a reset link from the People page lands. Opening it uses nothing; only
8
+ * Set password spends the token, so a mail scanner that follows the link does
9
+ * no harm. It never shows whose account it is.
10
+ */
11
+ export declare function ResetPasswordPage({ token, onDone }: ResetPasswordPageProps): import("react").JSX.Element;
12
+ export {};
@@ -0,0 +1,98 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { AuthCard, AuthFooter, AuthHero, Banner, Button, PasswordInput, } from "@remit/ui";
3
+ import { useEffect, useRef, useState } from "react";
4
+ import { buildBugReportContext, buildGitHubIssueUrl } from "../lib/bug-report";
5
+ import { getErrorStatus } from "../lib/error-classifier";
6
+ import { authFooterNote } from "./account-menu-mode";
7
+ import { authServerMessage, classifyAuthError } from "./auth-error";
8
+ import { authRefusal } from "./auth-refusal";
9
+ import { authClient } from "./better-auth-config";
10
+ const RESET_PATH = /\/reset-password\/([^/]+)\/?$/;
11
+ export const resetPasswordToken = (pathname) => {
12
+ const match = RESET_PATH.exec(pathname);
13
+ return match?.[1] ? decodeURIComponent(match[1]) : undefined;
14
+ };
15
+ const SET_FAILED = "Your password was not set";
16
+ /**
17
+ * A report for a reset the server failed. The address carries the reset token,
18
+ * so the report names the page and never the token.
19
+ */
20
+ const resetReportHref = (message) => buildGitHubIssueUrl({
21
+ ...buildBugReportContext({
22
+ title: `Reset password: ${message}`,
23
+ errorMessage: message,
24
+ }),
25
+ href: `${window.location.origin}/reset-password/<token>`,
26
+ });
27
+ const problemFor = (failure) => {
28
+ if (authRefusal(failure) === "signInOff")
29
+ return { kind: "signInOff" };
30
+ const code = failure && typeof failure === "object" && "code" in failure
31
+ ? failure.code
32
+ : undefined;
33
+ if (code === "INVALID_TOKEN")
34
+ return { kind: "deadLink" };
35
+ if (code === "PASSWORD_TOO_SHORT" || code === "PASSWORD_TOO_LONG") {
36
+ return {
37
+ kind: "password",
38
+ message: authServerMessage(failure) ?? "Use 12 to 128 characters.",
39
+ };
40
+ }
41
+ const kind = classifyAuthError(failure);
42
+ if (kind === "network") {
43
+ return {
44
+ kind: "inline",
45
+ message: "Can't reach the server. You may be offline. Check your connection and try again.",
46
+ };
47
+ }
48
+ if (kind === "rateLimited") {
49
+ return {
50
+ kind: "inline",
51
+ message: "Too many tries from this address. Wait a minute and try again.",
52
+ };
53
+ }
54
+ const status = getErrorStatus(failure);
55
+ const server = authServerMessage(failure);
56
+ return {
57
+ kind: "server",
58
+ message: `${SET_FAILED}. The server answered ${status ?? "nothing"}${server ? `: ${server}` : ""}.`,
59
+ };
60
+ };
61
+ /**
62
+ * Where a reset link from the People page lands. Opening it uses nothing; only
63
+ * Set password spends the token, so a mail scanner that follows the link does
64
+ * no harm. It never shows whose account it is.
65
+ */
66
+ export function ResetPasswordPage({ token, onDone }) {
67
+ const [password, setPassword] = useState("");
68
+ const [problem, setProblem] = useState(null);
69
+ const [submitting, setSubmitting] = useState(false);
70
+ const inputRef = useRef(null);
71
+ useEffect(() => {
72
+ inputRef.current?.focus();
73
+ }, []);
74
+ const submit = async (event) => {
75
+ event.preventDefault();
76
+ if (submitting)
77
+ return;
78
+ setProblem(null);
79
+ setSubmitting(true);
80
+ const failure = await authClient
81
+ .resetPassword({ newPassword: password, token })
82
+ .then((result) => result.error ?? null, (thrown) => thrown);
83
+ setSubmitting(false);
84
+ if (!failure) {
85
+ onDone();
86
+ return;
87
+ }
88
+ setProblem(problemFor(failure));
89
+ };
90
+ return (_jsxs(AuthCard, { children: [_jsx(AuthHero, {}), _jsxs("form", { onSubmit: submit, className: "mt-6 flex flex-col gap-4 rounded-lg border border-line bg-surface p-7 shadow-lg", children: [_jsx("h1", { className: "text-base font-semibold text-fg", children: "Choose a new password" }), problem?.kind === "deadLink" && (_jsx(Banner, { tone: "danger", children: "This link no longer works. Ask for a new one." })), problem?.kind === "signInOff" && (_jsxs(Banner, { tone: "info", children: [_jsx("p", { className: "font-medium", children: "Sign-in is turned off on this server." }), _jsx("p", { className: "mt-1", children: "The link works once the person who runs this server turns sign-in back on." })] })), problem?.kind === "inline" && (_jsx(Banner, { tone: "danger", children: problem.message })), problem?.kind === "server" && (_jsxs(Banner, { tone: "danger", children: [_jsx("p", { children: problem.message }), _jsx("a", { href: resetReportHref(problem.message), target: "_blank", rel: "noreferrer", className: "mt-1 inline-block font-medium text-accent hover:underline", children: "Report an issue" })] })), _jsxs("div", { className: "flex flex-col gap-1 text-sm", children: [_jsx("label", { htmlFor: "reset-new-password", className: "text-fg-muted", children: "New password" }), _jsx(PasswordInput, { ref: inputRef, id: "reset-new-password", autoComplete: "new-password", value: password, onChange: (event) => {
91
+ setPassword(event.target.value);
92
+ if (problem?.kind === "password")
93
+ setProblem(null);
94
+ }, placeholder: "12 to 128 characters", "aria-invalid": problem?.kind === "password", "aria-describedby": "reset-new-password-hint", required: true }), _jsx("p", { id: "reset-new-password-hint", className: "text-xs text-fg-muted", children: problem?.kind === "password" ? (_jsx("span", { className: "text-danger", role: "alert", children: problem.message })) : ("Use 12 to 128 characters. Spaces and any symbols are fine. A long phrase is easy to remember.") })] }), _jsx(Button, { type: "submit", "aria-busy": submitting, children: "Set password" })] }), _jsx(AuthFooter, { note: authFooterNote({
95
+ betterAuthEnabled: true,
96
+ cognitoConfigured: false,
97
+ }) })] }));
98
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The two self-host refusals the sign-in screen states in its own words. The
3
+ * server answers each with a 403 and a code on every auth path, the session
4
+ * lookup included, so the screen shows them before anyone types.
5
+ *
6
+ * - "signInOff": the operator turned sign-in off for the whole server.
7
+ * - "accountDisabled": this account was disabled on the People page.
8
+ */
9
+ export type AuthRefusal = "signInOff" | "accountDisabled";
10
+ export declare const authRefusal: (error: unknown) => AuthRefusal | undefined;
@@ -0,0 +1,14 @@
1
+ import { getErrorStatus } from "../lib/error-classifier";
2
+ const REFUSALS = {
3
+ SIGN_IN_DISABLED: "signInOff",
4
+ ACCOUNT_DISABLED: "accountDisabled",
5
+ };
6
+ export const authRefusal = (error) => {
7
+ if (getErrorStatus(error) !== 403)
8
+ return undefined;
9
+ if (!error || typeof error !== "object" || !("code" in error)) {
10
+ return undefined;
11
+ }
12
+ const { code } = error;
13
+ return typeof code === "string" ? REFUSALS[code] : undefined;
14
+ };
@@ -199,6 +199,10 @@ export const fetchBetterAuthToken = async () => {
199
199
  catch (error) {
200
200
  if (isRevocation(error)) {
201
201
  resetBetterAuthTokenCache();
202
+ // A 403 is the kill switch or a disabled account. The session lookup
203
+ // answers it with a code the sign-in screen states, so re-read it.
204
+ if (error.status === 403)
205
+ authClient.$store.notify("$sessionSignal");
202
206
  throw error;
203
207
  }
204
208
  if (current && isUsable(current) && isTransientMintFailure(error)) {
@@ -8,6 +8,7 @@ import { type FC, type ReactNode } from "react";
8
8
  */
9
9
  export interface AuthAccount {
10
10
  email: string | null;
11
+ securityUrl?: string;
11
12
  signOut: () => void | Promise<void>;
12
13
  }
13
14
  export interface AuthAccountProps {
@@ -1,3 +1,4 @@
1
+ import { type AuthRefusal } from "./auth-refusal";
1
2
  /**
2
3
  * What the session query is actually telling the gate.
3
4
  *
@@ -12,6 +13,9 @@ export type SessionState = {
12
13
  kind: "active";
13
14
  } | {
14
15
  kind: "rateLimited";
16
+ } | {
17
+ kind: "refused";
18
+ refusal: AuthRefusal;
15
19
  } | {
16
20
  kind: "signedOut";
17
21
  };
@@ -22,8 +26,9 @@ export interface SessionQuery {
22
26
  error: unknown;
23
27
  }
24
28
  /**
25
- * A held session outranks everything: better-auth keeps `data` across a failed
26
- * refetch unless the failure was a 401, so a throttled refresh must not evict a
27
- * signed-in user.
29
+ * A held session outranks everything but a refusal: better-auth keeps `data`
30
+ * across a failed refetch unless the failure was a 401, so a throttled refresh
31
+ * must not evict a signed-in user. The kill switch and a disabled account answer
32
+ * 403 with a code, and those end the session the tab still holds.
28
33
  */
29
34
  export declare const classifySessionQuery: ({ data, isPending, error, }: SessionQuery) => SessionState;
@@ -1,11 +1,16 @@
1
1
  import { getErrorStatus } from "../lib/error-classifier";
2
+ import { authRefusal } from "./auth-refusal";
2
3
  const TOO_MANY_REQUESTS = 429;
3
4
  /**
4
- * A held session outranks everything: better-auth keeps `data` across a failed
5
- * refetch unless the failure was a 401, so a throttled refresh must not evict a
6
- * signed-in user.
5
+ * A held session outranks everything but a refusal: better-auth keeps `data`
6
+ * across a failed refetch unless the failure was a 401, so a throttled refresh
7
+ * must not evict a signed-in user. The kill switch and a disabled account answer
8
+ * 403 with a code, and those end the session the tab still holds.
7
9
  */
8
10
  export const classifySessionQuery = ({ data, isPending, error, }) => {
11
+ const refusal = authRefusal(error);
12
+ if (refusal)
13
+ return { kind: "refused", refusal };
9
14
  if (data)
10
15
  return { kind: "active" };
11
16
  if (isPending)
@@ -0,0 +1 @@
1
+ export declare function PeoplePanel(): import("react").JSX.Element | null;
@@ -0,0 +1,72 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Banner, Button, DropdownMenu, DropdownMenuItem, DropdownMenuSeparator, } from "@remit/ui";
3
+ import { MoreHorizontal } from "lucide-react";
4
+ import { useEffect, useRef, useState } from "react";
5
+ import { usePeople } from "../../../hooks/usePeople";
6
+ import { classifyPeopleFailure, formatPersonDate, peopleListFailureReason, peopleReportHref, personActionCopy, } from "../../../lib/people";
7
+ import { PersonActionDialog } from "./PersonActionDialog";
8
+ import { ResetLinkDialog } from "./ResetLinkDialog";
9
+ const LIST_FAILED = "The list of people did not load";
10
+ function ReportLink({ href }) {
11
+ return (_jsx("a", { href: href, target: "_blank", rel: "noreferrer", className: "font-medium text-accent hover:underline", children: "Report an issue" }));
12
+ }
13
+ function ActionFailedBanner({ failure }) {
14
+ const ref = useRef(null);
15
+ useEffect(() => {
16
+ ref.current?.focus();
17
+ }, []);
18
+ return (_jsx("div", { ref: ref, tabIndex: -1, className: "outline-none", children: _jsxs(Banner, { tone: "danger", children: [_jsx("p", { className: "font-medium", children: failure.title }), _jsx("p", { className: "mt-1 text-fg-muted", children: failure.reason }), _jsx("p", { className: "mt-1", children: _jsx(ReportLink, { href: peopleReportHref(failure.title, failure.error) }) })] }) }));
19
+ }
20
+ function PersonMenu({ person, onPick, }) {
21
+ const disabled = person.status === "Disabled";
22
+ return (_jsxs(DropdownMenu, { trigger: _jsxs(_Fragment, { children: [_jsx(MoreHorizontal, { className: "size-4", "aria-hidden": "true" }), _jsxs("span", { className: "sr-only", children: ["Actions for ", person.email] })] }), children: [_jsx(DropdownMenuItem, { onClick: () => onPick("SignOut"), children: "Sign out everywhere" }), _jsx(DropdownMenuItem, { onClick: () => onPick("ResetPassword"), children: "Reset password" }), _jsx(DropdownMenuSeparator, {}), disabled ? (_jsx(DropdownMenuItem, { onClick: () => onPick("Enable"), children: "Enable" })) : (_jsx(DropdownMenuItem, { onClick: () => onPick("Disable"), disabled: person.isCaller, destructive: !person.isCaller, children: _jsxs("span", { className: "flex flex-col", children: [_jsx("span", { children: "Disable" }), person.isCaller && (_jsx("span", { className: "text-xs text-fg-subtle", children: "Not your own account" }))] }) }))] }));
23
+ }
24
+ function PeopleTable({ people, onPick, }) {
25
+ const now = new Date();
26
+ return (_jsx("div", { className: "overflow-x-auto rounded-sm border border-line bg-surface", children: _jsxs("table", { className: "w-full text-left text-sm", children: [_jsx("thead", { className: "border-b border-line text-xs text-fg-muted", children: _jsxs("tr", { children: [_jsx("th", { scope: "col", className: "px-3 py-2 font-medium", children: "Email" }), _jsx("th", { scope: "col", className: "px-3 py-2 font-medium", children: "Created" }), _jsx("th", { scope: "col", className: "px-3 py-2 font-medium", children: "Last sign-in" }), _jsx("th", { scope: "col", className: "px-3 py-2 font-medium", children: "Sessions" }), _jsx("th", { scope: "col", className: "px-3 py-2 font-medium", children: "Status" }), _jsx("th", { scope: "col", className: "w-12 px-1 py-2", children: _jsx("span", { className: "sr-only", children: "Actions" }) })] }) }), _jsx("tbody", { children: people.map((person) => (_jsxs("tr", { className: "border-b border-line last:border-b-0", children: [_jsxs("td", { className: "px-3 py-1 text-fg", children: [person.email, person.isCaller && (_jsx("span", { className: "text-fg-muted", children: " (you)" }))] }), _jsx("td", { className: "px-3 py-1 text-fg-muted", children: formatPersonDate(person.createdAt, now) }), _jsx("td", { className: "px-3 py-1 text-fg-muted", children: formatPersonDate(person.lastSignInAt, now) }), _jsx("td", { className: "px-3 py-1 tabular-nums text-fg-muted", children: person.sessionCount }), _jsx("td", { className: person.status === "Disabled"
27
+ ? "px-3 py-1 text-danger"
28
+ : "px-3 py-1 text-fg-muted", children: person.status }), _jsx("td", { className: "px-1 py-1", children: _jsx(PersonMenu, { person: person, onPick: (action) => onPick(action, person) }) })] }, person.userId))) })] }) }));
29
+ }
30
+ export function PeoplePanel() {
31
+ const people = usePeople();
32
+ const [pending, setPending] = useState(null);
33
+ const [failure, setFailure] = useState(null);
34
+ const [resetLink, setResetLink] = useState(null);
35
+ if (people.isPending) {
36
+ return (
37
+ // biome-ignore lint/a11y/useAriaPropsSupportedByRole: aria-label on a loading skeleton is what assistive tech has to go on
38
+ _jsx("div", { className: "h-24 animate-pulse rounded-sm border border-line bg-surface", "aria-busy": "true", "aria-label": "Loading people" }));
39
+ }
40
+ if (people.unavailable) {
41
+ return (_jsx(Banner, { tone: "info", children: "This server has no People page. It shows on a self-hosted server once self sign-up is turned off." }));
42
+ }
43
+ if (people.isError) {
44
+ if (classifyPeopleFailure(people.error).kind === "signedOut")
45
+ return null;
46
+ return (_jsxs(Banner, { tone: "danger", children: [_jsxs("p", { className: "font-medium", children: [LIST_FAILED, "."] }), _jsx("p", { className: "mt-1 text-fg-muted", children: peopleListFailureReason(people.error) }), _jsxs("p", { className: "mt-2 flex items-center gap-3", children: [_jsx(Button, { variant: "secondary", size: "sm", onClick: () => void people.refetch(), children: "Try again" }), _jsx(ReportLink, { href: peopleReportHref(LIST_FAILED, people.error) })] })] }));
47
+ }
48
+ const pick = (action, person) => {
49
+ setFailure(null);
50
+ setPending({ action, person });
51
+ };
52
+ const done = (result) => {
53
+ if (result.resetUrl && pending) {
54
+ setResetLink({ email: pending.person.email, resetUrl: result.resetUrl });
55
+ }
56
+ setPending(null);
57
+ };
58
+ const failed = (error) => {
59
+ if (!pending)
60
+ return;
61
+ const classified = classifyPeopleFailure(error);
62
+ setFailure({
63
+ title: personActionCopy(pending.action, pending.person.email).failedTitle,
64
+ reason: classified.kind === "failed"
65
+ ? classified.reason
66
+ : "Something went wrong. Nothing changed. Try again.",
67
+ error,
68
+ });
69
+ setPending(null);
70
+ };
71
+ return (_jsxs("div", { className: "space-y-4", children: [failure && _jsx(ActionFailedBanner, { failure: failure }), _jsx(PeopleTable, { people: people.data.people, onPick: pick }), pending && (_jsx(PersonActionDialog, { action: pending.action, person: pending.person, onCancel: () => setPending(null), onDone: done, onFailed: failed })), resetLink && (_jsx(ResetLinkDialog, { email: resetLink.email, resetUrl: resetLink.resetUrl, onDone: () => setResetLink(null) }))] }));
72
+ }
@@ -0,0 +1,11 @@
1
+ import type { RemitImapPerson, RemitImapStepUpAction } from "@remit/api-http-client/types.gen.ts";
2
+ import { type PersonActionResult } from "../../../hooks/usePersonAction";
3
+ interface PersonActionDialogProps {
4
+ action: RemitImapStepUpAction;
5
+ person: RemitImapPerson;
6
+ onCancel: () => void;
7
+ onDone: (result: PersonActionResult) => void;
8
+ onFailed: (error: unknown) => void;
9
+ }
10
+ export declare function PersonActionDialog({ action, person, onCancel, onDone, onFailed, }: PersonActionDialogProps): import("react").JSX.Element;
11
+ export {};
@@ -0,0 +1,52 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button, Dialog, PasswordInput } from "@remit/ui";
3
+ import { X } from "lucide-react";
4
+ import { useState } from "react";
5
+ import { usePersonAction, } from "../../../hooks/usePersonAction";
6
+ import { classifyPeopleFailure, personActionCopy } from "../../../lib/people";
7
+ import { reportSignedOut } from "../../../lib/signed-out";
8
+ const WRONG_PASSWORD = "That is not your password. Try again.";
9
+ const LOCKED = "Five wrong passwords in 15 minutes. Wait 15 minutes, then try again.";
10
+ export function PersonActionDialog({ action, person, onCancel, onDone, onFailed, }) {
11
+ const copy = personActionCopy(action, person.email);
12
+ const [password, setPassword] = useState("");
13
+ const [problem, setProblem] = useState(null);
14
+ const mutation = usePersonAction(password);
15
+ const cancel = () => {
16
+ if (mutation.isPending)
17
+ return;
18
+ onCancel();
19
+ };
20
+ const submit = (event) => {
21
+ event.preventDefault();
22
+ if (mutation.isPending || password === "")
23
+ return;
24
+ setProblem(null);
25
+ mutation.mutate({ action, person }, {
26
+ onSuccess: onDone,
27
+ onError: (error) => {
28
+ const failure = classifyPeopleFailure(error);
29
+ if (failure.kind === "wrongPassword") {
30
+ setPassword("");
31
+ setProblem(WRONG_PASSWORD);
32
+ return;
33
+ }
34
+ if (failure.kind === "locked") {
35
+ setPassword("");
36
+ setProblem(LOCKED);
37
+ return;
38
+ }
39
+ if (failure.kind === "signedOut") {
40
+ onCancel();
41
+ reportSignedOut();
42
+ return;
43
+ }
44
+ onFailed(error);
45
+ },
46
+ });
47
+ };
48
+ return (_jsx(Dialog, { open: true, onClose: cancel, title: copy.title, children: _jsxs("form", { onSubmit: submit, children: [_jsxs("header", { className: "flex items-center gap-2 border-b border-line px-5 py-3", children: [_jsx("span", { className: "flex-1 text-sm font-semibold text-fg", children: copy.title }), _jsx(Button, { variant: "ghost", size: "sm", icon: _jsx(X, { className: "size-3.5" }), onClick: cancel, "aria-label": "Close" })] }), _jsxs("div", { className: "space-y-4 px-5 py-4 text-sm text-fg-muted", children: [_jsx("p", { children: copy.body }), _jsxs("div", { className: "flex flex-col gap-1", children: [_jsx("label", { htmlFor: "people-step-up-password", className: "text-xs font-medium text-fg", children: "Your password" }), _jsx(PasswordInput, { id: "people-step-up-password", autoComplete: "current-password", value: password, onChange: (event) => {
49
+ setPassword(event.target.value);
50
+ setProblem(null);
51
+ }, "aria-invalid": problem !== null, "aria-describedby": "people-step-up-hint", required: true }), _jsx("p", { id: "people-step-up-hint", className: "text-xs", children: problem ? (_jsx("span", { className: "text-danger", role: "alert", children: problem })) : ("Confirm with your own password. It counts for this one action.") })] })] }), _jsxs("footer", { className: "flex items-center justify-end gap-2 border-t border-line px-5 py-3", children: [_jsx(Button, { variant: "secondary", size: "sm", onClick: cancel, children: "Cancel" }), _jsx(Button, { type: "submit", variant: copy.destructive ? "danger" : "primary", size: "sm", disabled: password === "", "aria-busy": mutation.isPending, children: copy.confirmLabel })] })] }) }));
52
+ }
@@ -0,0 +1,11 @@
1
+ interface ResetLinkDialogProps {
2
+ email: string;
3
+ resetUrl: string;
4
+ onDone: () => void;
5
+ }
6
+ /**
7
+ * The reset link, shown once. Only Done closes it: Esc and a click outside do
8
+ * nothing, so the link is not lost by accident. It lives in memory only.
9
+ */
10
+ export declare function ResetLinkDialog({ email, resetUrl, onDone, }: ResetLinkDialogProps): import("react").JSX.Element;
11
+ export {};
@@ -0,0 +1,23 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button, Dialog } from "@remit/ui";
3
+ import { Check, Copy } from "lucide-react";
4
+ import { useState } from "react";
5
+ const ignoreDismiss = () => undefined;
6
+ /**
7
+ * The reset link, shown once. Only Done closes it: Esc and a click outside do
8
+ * nothing, so the link is not lost by accident. It lives in memory only.
9
+ */
10
+ export function ResetLinkDialog({ email, resetUrl, onDone, }) {
11
+ const [copied, setCopied] = useState(false);
12
+ const [copyFailed, setCopyFailed] = useState(false);
13
+ const copy = () => {
14
+ navigator.clipboard
15
+ .writeText(resetUrl)
16
+ .then(() => {
17
+ setCopyFailed(false);
18
+ setCopied(true);
19
+ })
20
+ .catch(() => setCopyFailed(true));
21
+ };
22
+ return (_jsxs(Dialog, { open: true, onClose: ignoreDismiss, title: `Reset link for ${email}`, children: [_jsxs("header", { className: "border-b border-line px-5 py-3 text-sm font-semibold text-fg", children: ["Reset link for ", email] }), _jsxs("div", { className: "space-y-4 px-5 py-4 text-sm text-fg-muted", children: [_jsx("p", { children: "They are signed out everywhere. Give them this link, by message or in person. It works once, for 24 hours." }), _jsxs("div", { className: "flex flex-col gap-2 sm:flex-row sm:items-center", children: [_jsx(Button, { variant: "primary", size: "sm", icon: copied ? (_jsx(Check, { className: "size-3.5" })) : (_jsx(Copy, { className: "size-3.5" })), onClick: copy, children: copied ? "Copied" : "Copy" }), _jsx("input", { readOnly: true, tabIndex: -1, value: resetUrl, "aria-label": `Reset link for ${email}`, onFocus: (event) => event.currentTarget.select(), className: "min-w-0 flex-1 rounded-sm border border-line bg-surface px-2 py-1.5 font-mono text-xs text-fg sm:order-first" })] }), copyFailed && (_jsx("p", { className: "text-xs text-danger", role: "alert", children: "Copying did not work in this browser. Select the link and copy it by hand." })), _jsx("p", { children: "You see this link only now. Close this window and it is gone. Make a new one if it gets lost." })] }), _jsx("footer", { className: "flex justify-end border-t border-line px-5 py-3", children: _jsx(Button, { variant: "secondary", size: "sm", onClick: onDone, children: "Done" }) })] }));
23
+ }