Three operator gaps, all found the same way — a person could not sign up and the
app showed nobody anything.
- DELETE /api/admin/invites/{id} with a delete control on both the pending
requests and the previously-decided list. Deny keeps the row so the person
cannot immediately re-ask; delete forgets the address. Refused with 409 while
a User row exists for it, because is_allowed reads that row and removing it
would revoke a live user's access with no other sign — the list ships
has_account so the UI withholds the button instead of offering one that fails.
- Email is fail-soft by design, which had come to mean invisible. _send() now
records an email_undelivered notification for every admin when a message is
skipped or rejected, naming the message that was lost, throttled to one an
hour. /api/me carries email_configured, driving a standing warning on
Configuration → Email / SMTP and above the access-request list.
- The sign-in card's Create account / Forgot password / Didn't get the email
views are history entries (useHistorySubview), so Back returns to the previous
view instead of only moving the address bar.
Also: the per-test rate-limiter reset sweeps every loaded app.* module rather
than a hand-kept list of three — this change added a limiter outside it.
61 lines
2.4 KiB
TypeScript
61 lines
2.4 KiB
TypeScript
// The signed-in account & session: the bootstrap `me` probe, multi-account switch/list, sign-out,
|
|
// app version, and preference save. Only touches core's req.
|
|
import { req } from "./core";
|
|
|
|
export interface Me {
|
|
id: number;
|
|
email: string;
|
|
display_name: string | null;
|
|
avatar_url: string | null;
|
|
role: string;
|
|
is_demo: boolean;
|
|
has_google: boolean;
|
|
has_password: boolean;
|
|
google_enabled: boolean;
|
|
plex_enabled: boolean;
|
|
can_read: boolean;
|
|
can_write: boolean;
|
|
pending_invites: number;
|
|
/** Admin-only: false when SMTP is incomplete, so every outbound message is silently skipped. */
|
|
email_configured: boolean;
|
|
preferences: Record<string, unknown>;
|
|
}
|
|
|
|
export interface Account {
|
|
id: number;
|
|
email: string;
|
|
display_name: string | null;
|
|
avatar_url: string | null;
|
|
active: boolean;
|
|
}
|
|
|
|
export interface VersionInfo {
|
|
app_version: string;
|
|
git_sha: string;
|
|
build_date: string | null;
|
|
db_revision: string | null;
|
|
}
|
|
|
|
export const accountApi = {
|
|
// Bootstrap probe: 200 always. Returns the user when signed in, or null when logged out
|
|
// (the endpoint answers `{authenticated:false}` rather than 401, so the public landing never
|
|
// logs a failed request to the console). React Query treats the null as data, not an error.
|
|
me: async (): Promise<Me | null> => {
|
|
// Always 200: `{ authenticated: false }` when logged out, else the full Me + `authenticated`.
|
|
const r = await req<{ authenticated: boolean } & Partial<Me>>("/api/me");
|
|
return r.authenticated ? (r as Me) : null;
|
|
},
|
|
accounts: (): Promise<Account[]> => req("/api/me/accounts"),
|
|
deleteAccount: (): Promise<{ deleted: boolean }> => req("/api/me/account", { method: "DELETE" }),
|
|
switchAccount: (userId: number): Promise<{ ok: boolean; user_id: number }> =>
|
|
req("/api/me/switch", { method: "POST", body: JSON.stringify({ user_id: userId }) }),
|
|
// Signs the current tab's active account out of the browser wallet (per-tab aware via the
|
|
// X-Siftlode-Account header that req() attaches).
|
|
logout: (): Promise<{ ok: boolean; switched: boolean }> =>
|
|
req("/auth/logout", { method: "POST" }),
|
|
version: (): Promise<VersionInfo> => req("/api/version"),
|
|
// Overwriting preferences is idempotent, so let it retry on a transient gateway blip.
|
|
savePrefs: (p: Record<string, unknown>) =>
|
|
req("/api/me/preferences", { method: "PUT", body: JSON.stringify(p) }, { idempotent: true }),
|
|
};
|