Files
native/src/lib/account-utils.ts
T
Linus Rath 26bb947940 fix: keep the account limit from leaving the app signed in as the wrong account
Signing in connects the shared client to the new account and stores its
credentials before the account registry takes it. With ten accounts the
registry refused, but nothing undid the connect: every request then went
out as the new account while the app still showed the old one. A
sign-in link made this easy to reach, since it opened "Add account"
without the limit check the menus have.

- A failed registration now restores the previous connection and drops
  credentials the registry never took.
- Adding an account to a full registry is refused before a sign-in code
  is spent or a browser sign-in starts, with "Remove an account in
  Settings to add another one."
2026-09-27 05:10:50 +02:00

25 lines
795 B
TypeScript

// Registry cap. Raised from 5: the per-account cost is one stored credential
// set and one cached snapshot; the SSE socket budget is bounded separately
// (MAX_SSE_STREAMS), so nothing scales with this number at runtime.
export const MAX_ACCOUNTS = 10;
/** A new account would take the registry past MAX_ACCOUNTS. */
export class AccountLimitError extends Error {
readonly limit = MAX_ACCOUNTS;
constructor() {
super(`Maximum of ${MAX_ACCOUNTS} accounts reached`);
this.name = 'AccountLimitError';
}
}
export function generateAccountId(username: string, serverUrl: string): string {
let host = serverUrl;
try {
host = new URL(serverUrl).hostname;
} catch {
host = serverUrl.replace(/^https?:\/\//, '').replace(/\/.*$/, '');
}
return `${username}@${host}`;
}