@jgb-solutions/kit 0.6.0 → 0.8.0
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.
- package/CHANGELOG.md +38 -0
- package/README.md +73 -7
- package/dist/account/AccountPage.d.ts +130 -0
- package/dist/account/SignIn.d.ts +54 -0
- package/dist/account/index.d.ts +12 -0
- package/dist/account/native/index.d.ts +173 -0
- package/dist/account/native.d.ts +2 -0
- package/dist/account/native.js +1012 -0
- package/dist/account/result.d.ts +13 -0
- package/dist/account/styles.css +557 -0
- package/dist/account/text.d.ts +108 -0
- package/dist/account/theme.d.ts +47 -0
- package/dist/account/ui.d.ts +73 -0
- package/dist/account.d.ts +2 -0
- package/dist/account.js +1396 -0
- package/dist/auth/browser.d.ts +4 -1
- package/dist/auth/bun.d.ts +3 -2
- package/dist/auth/bun.js +4 -2
- package/dist/auth/expo.d.ts +39 -4
- package/dist/auth/expo.js +24 -3
- package/dist/auth/orpc.d.ts +6 -0
- package/dist/auth/orpc.js +11 -3
- package/dist/auth/server.d.ts +43 -7
- package/dist/auth/server.js +178 -16
- package/dist/auth/versions.d.ts +17 -0
- package/dist/auth/versions.js +19 -0
- package/dist/auth.d.ts +111 -3
- package/dist/auth.js +110 -4
- package/dist/i18n.js +2 -2
- package/package.json +32 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,44 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `@jgb-solutions/kit`. Versions follow semver.
|
|
4
4
|
|
|
5
|
+
## 0.8.0
|
|
6
|
+
|
|
7
|
+
- `kit/account` (new): the sign-in, sign-up and account pages every app shares, one layout chosen by the owner (2026-12-04), on CSS variables so each app changes only colours, fonts and radius. `SignInPanel`, `SignUpPanel`, `SignedInPanel`, `AccountPage` and its sections, `AccountRoot` and `accountTheme`, and the words in a typed `AccountText` (English: `accountTextEn`). Stylesheet: `@jgb-solutions/kit/account/styles.css`, scoped to `.jac-root`. Actions answer `kit/auth/server`'s `AuthResult`; deleting a Google-only account uses its `REAUTH_REQUIRED` window.
|
|
8
|
+
- `kit/account/native` (new): the same screen for Expo apps (`SignInOrUp`, `AccountProfile` and their pieces). `react-native` and `react-native-svg` are new optional peer dependencies, needed only by this module.
|
|
9
|
+
- Nothing else changes: no breaking changes from 0.7.0.
|
|
10
|
+
|
|
11
|
+
## 0.7.0
|
|
12
|
+
|
|
13
|
+
Security fixes from the 2026-12-04 audit. Breaking changes are marked; see "Upgrading" at the end of this section.
|
|
14
|
+
|
|
15
|
+
- **Breaking:** `authServer` takes a required `rateLimit: { storage }`, or `'off'` for E2E (it throws on a production server unless E2E=1). Better Auth limits only requests to its own routes, so direct `auth.api` calls from server functions were unthrottled. Each sign-in, sign-up, password change, first password, Google start or link and account deletion now counts per address under Better Auth's own keys (`<ip>|<path>`). Over the limit: `TOO_MANY_REQUESTS`.
|
|
16
|
+
- Password sign-in also counts per login, through /api/auth and direct calls alike: `accountSignInLimit(storage)`, a Better Auth hook that `standardAuthOptions` adds when rate limits are on (`ACCOUNT_SIGN_IN_RULE`, 30 in 15 minutes, keyed by a hash), so a new address per attempt doesn't reset it.
|
|
17
|
+
- **Breaking:** `AuthResult`'s failure has an optional `retryAfter`; code that rebuilds the type or matches it exactly must allow it.
|
|
18
|
+
- **Breaking:** `AuthInstance` (and so `authServer`'s `auth`) needs `options` as well as `api` (the Better Auth instance has both; a hand-made stub needs `options: {}`), and `AuthApi.getSession` must answer `session.createdAt`.
|
|
19
|
+
- **Breaking:** `deleteOwnAccount` for an account without a password no longer takes `confirmUsername` (a public username proved nothing). It needs a sign-in from the last `REAUTH_MINUTES` (5), else `REAUTH_REQUIRED`. `AUTH_SERVER_CODES.confirmUsername` becomes `reauthRequired`.
|
|
20
|
+
- **Breaking:** `MobileSession` has a new `{ status: 'unverified' }`. When the server can't be reached at launch, `restore()` sets it instead of `out` with the token still sent. New `handleUnauthorized(error)` forgets the token on any UNAUTHORIZED answer.
|
|
21
|
+
- **Breaking (trust):** the client's address comes from `ipAddressHeaders` (`cf-connecting-ip` by default), which only Cloudflare sets reliably. A server reachable without Cloudflare must list its own proxy's header, or every per-address limit can be dodged.
|
|
22
|
+
- `googleIdTokenNonce({ mode })` (new Better Auth plugin, added by `standardAuthOptions` when Google is on; `googleNonce: 'optional'` by default). POST /google/nonce issues a single-use nonce (5 minutes, never cached; expired ones are swept), and a Google ID-token sign-in or link spends it, so a stolen token can't be replayed. **Plan:** `'required'` becomes the default in 0.9.0 (planned for January 2027), once every app's mobile build sends a nonce; until then a token sent without one still skips the check. Apps can set `googleNonce: 'required'` sooner.
|
|
23
|
+
- Expo: `auth.googleNonce()` answers `{ ok: true, nonce }` or `{ ok: false, code }` (NONCE_UNAVAILABLE, NETWORK, TOO_MANY_REQUESTS…) for the app's error tracker. **Breaking:** `googleIdToken(module, webClientId, nonce)` passes the nonce to the native module's `signIn(serverClientId, nonce)`, so the module must accept and use it (Credential Manager's `setNonce`).
|
|
24
|
+
- `kit/auth/versions` (new, no imports): `AUTH_VERSIONS`, the better-auth, passkey and jose versions this release is tested with, and `authVersionProblems(dependencies)` for an app's CI check, so the auth set moves in every app together.
|
|
25
|
+
- `counterRateLimit` counts in memory while its store is down, instead of letting every attempt through. New `memoryRateLimit()`.
|
|
26
|
+
- `kit/auth/orpc`: `authMiddleware({ freshViewer })` makes `requireAdmin` re-read the session fresh, so a ban or a lost role counts at once. `withUser` marks any answer for a signed-in person `private, no-store`.
|
|
27
|
+
- `concurrencyLimit(limit, maxQueue)` refuses new tasks past `maxQueue` waiting; `argon2idHasher({ concurrency })` caps its queue at 100 per running hash.
|
|
28
|
+
- `createTranslator` reads own properties only, so `{constructor}` in a message or key never prints a built-in.
|
|
29
|
+
|
|
30
|
+
### Upgrading
|
|
31
|
+
|
|
32
|
+
From 0.4.x:
|
|
33
|
+
|
|
34
|
+
1. Pin `better-auth` and `@better-auth/passkey` to `AUTH_VERSIONS` (1.7.29).
|
|
35
|
+
2. Pass `rateLimit: { storage }` to `authServer`, the same store as `standardAuthOptions`' `rateLimitStorage` (`counterRateLimit(…)`, or `memoryRateLimit()` on one server); `'off'` only on the E2E server.
|
|
36
|
+
3. Check `ipAddressHeaders` names a header your proxy sets.
|
|
37
|
+
4. Deleting an account without a password: drop the username field; offer "sign in with Google again" on `REAUTH_REQUIRED`, then delete.
|
|
38
|
+
5. Mobile: handle `unverified` wherever the session status is switched on, call `handleUnauthorized` from the RPC client's error interceptor, fetch `googleNonce()` before Google's sheet, and update the native module's `signIn` to take the nonce.
|
|
39
|
+
6. Word the new codes: `TOO_MANY_REQUESTS`, `REAUTH_REQUIRED`, `INVALID_NONCE`, `NONCE_REQUIRED`.
|
|
40
|
+
|
|
41
|
+
From 0.3.x, also take 0.4.x's and 0.5.0's changes: move the app's own account code onto `kit/auth/server` (0.5.0) and `kit/auth/browser` (0.6.0), and its caching headers onto `kit/auth/cache`, then follow the steps above.
|
|
42
|
+
|
|
5
43
|
## 0.6.0
|
|
6
44
|
|
|
7
45
|
- `kit/auth/browser` (new, no dependencies):
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @jgb-solutions/kit
|
|
2
2
|
|
|
3
|
-
One package for JGB Solutions apps, in tree-shakable namespaces: the generic plumbing web apps need (Cloudflare Access, Better Auth) and the admin panel kit (`kit/admin`). An app bundles only the subpaths it imports: one using `kit/access` never ships admin or React code (`bun run check:install` proves it). ESM with TypeScript types, one subpath per module, MIT licensed. The modules run anywhere with Web Crypto and `fetch`: Bun, Node and Cloudflare Workers (`kit/auth/bun` on Bun only, `kit/auth/expo` in React Native, `kit/admin` in React 19 apps).
|
|
3
|
+
One package for JGB Solutions apps, in tree-shakable namespaces: the generic plumbing web apps need (Cloudflare Access, Better Auth) and the admin panel kit (`kit/admin`) and the shared sign-in and account pages (`kit/account`). An app bundles only the subpaths it imports: one using `kit/access` never ships admin or React code (`bun run check:install` proves it). ESM with TypeScript types, one subpath per module, MIT licensed. The modules run anywhere with Web Crypto and `fetch`: Bun, Node and Cloudflare Workers (`kit/auth/bun` on Bun only, `kit/auth/expo` in React Native, `kit/admin` and `kit/account` in React 19 apps, `kit/account/native` in Expo).
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
bun add @jgb-solutions/kit
|
|
@@ -83,7 +83,7 @@ What the preset sets:
|
|
|
83
83
|
- **Google**, when `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` are set. `GOOGLE_MOBILE_CLIENT_IDS` adds the apps' clients, for ID-token sign-in. A new Google address makes a new account with a confirmed address. Joining existing accounts is "merge only confirmed" (see below).
|
|
84
84
|
- **Roles:** Better Auth's admin plugin, with the app's access control. A new account whose address is in `ADMIN_EMAILS` starts as admin when it's created with Google (a confirmed address); a sign-up with that address by email and password starts as an ordinary user, so nobody can claim an admin's address first. Other first admins are promoted from the server (the app's admin script).
|
|
85
85
|
- **The mobile app:** the bearer plugin.
|
|
86
|
-
- **Limits:** 60 requests a minute, tighter on sign-in, sign-up, passkeys and password changes (`RATE_LIMIT_RULES`). Counts go in the database, or in a counter store with `rateLimitStorage: counterRateLimit(() => redis)`, which
|
|
86
|
+
- **Limits:** 60 requests a minute, tighter on sign-in, sign-up, passkeys and password changes (`RATE_LIMIT_RULES`). Counts go in the database, or in a counter store with `rateLimitStorage: counterRateLimit(() => redis)`, which counts in the server's memory while the store is down (`memoryRateLimit()` on its own suits a single server).
|
|
87
87
|
- **Sessions:** 30 days, renewed daily, with a 5-minute cookie cache. The base URL is the request's host only for the site or a local host; anything else falls back to the site.
|
|
88
88
|
|
|
89
89
|
#### Google and existing accounts: merge only confirmed
|
|
@@ -123,7 +123,13 @@ Sign-in, sign-up, passwords, passkeys, Google, deleting one's own account and th
|
|
|
123
123
|
```ts
|
|
124
124
|
import { authServer } from '@jgb-solutions/kit/auth/server'
|
|
125
125
|
|
|
126
|
-
const accounts = authServer({
|
|
126
|
+
const accounts = authServer({
|
|
127
|
+
auth: getAuth,
|
|
128
|
+
headers: getRequestHeaders,
|
|
129
|
+
roleOf,
|
|
130
|
+
canOpenAdmin,
|
|
131
|
+
rateLimit: { storage: rateLimitStorage }, // required: the store given to standardAuthOptions; 'off' only for E2E
|
|
132
|
+
})
|
|
127
133
|
|
|
128
134
|
await accounts.viewer() // the signed-in person, or null (also when suspended); { fresh: true } skips the cookie cache
|
|
129
135
|
await accounts.signIn({ login, password }) // username or email; a placeholder address never signs in
|
|
@@ -131,11 +137,13 @@ await accounts.signUp({ username, password, email }) // no email: a placeholder
|
|
|
131
137
|
await accounts.changePassword({ currentPassword, newPassword }) // signs out the other devices
|
|
132
138
|
await accounts.passkeys() // newest first
|
|
133
139
|
await accounts.googleStartUrl({ redirect, home: '/account', signInPath: '/sign-in' }) // redirect checked with safeRedirect
|
|
134
|
-
await accounts.deleteOwnAccount({ password }) //
|
|
140
|
+
await accounts.deleteOwnAccount({ password }) // without a password (Google): a sign-in from the last 5 minutes, else REAUTH_REQUIRED
|
|
135
141
|
await accounts.admin.listUsers({ page, pageSize: 25, search })
|
|
136
142
|
await accounts.admin.ban({ userId }) // also setRole, unban, resetPassword: never on the admin's own account
|
|
137
143
|
```
|
|
138
144
|
|
|
145
|
+
**Rate limits.** The client's address comes from `ipAddressHeaders` (`cf-connecting-ip` by default): that header is trustworthy only when every request comes through Cloudflare. A server reachable directly must list the header its own proxy sets, or anyone can pick a new address per request. Better Auth limits only requests to its own routes (/api/auth/…), never a direct `auth.api` call, so a server function calling it is unthrottled. `authServer` counts each attempt itself, in the same store and under Better Auth's own keys (`<ip>|<path>`, the address read the way the instance reads it), so the two add up. Password sign-in also counts per login, through either door: `standardAuthOptions` adds `accountSignInLimit` (`ACCOUNT_SIGN_IN_RULE`, 30 in 15 minutes per login, its username and its address each, keyed by a hash), a Better Auth hook that runs for /api/auth requests and direct calls alike, so a new address per attempt doesn't reset it. It uses `rateLimitStorage` (in memory with the database store). `rateLimit: 'off'` throws on a production server unless E2E=1. Over the limit: `TOO_MANY_REQUESTS` with `retryAfter` in seconds.
|
|
146
|
+
|
|
139
147
|
Admin calls read the session fresh and go through `toAuthUser`, so a suspended admin is out at once. `authResult(fn)` turns any other Better Auth call into the same `{ ok, code }`.
|
|
140
148
|
|
|
141
149
|
#### `kit/auth/cache`: per-person pages stay out of shared caches
|
|
@@ -183,13 +191,16 @@ export const auth = createMobileAuth({
|
|
|
183
191
|
|
|
184
192
|
const session = useSyncExternalStore(auth.subscribe, auth.getSession)
|
|
185
193
|
await auth.signIn('maria', password) // or an email address
|
|
186
|
-
await auth.
|
|
194
|
+
const nonce = await auth.googleNonce() // { ok: true, nonce } (single use) or { ok: false, code }: report the code
|
|
195
|
+
await auth.signInWithGoogle(idToken, nonce.ok ? { nonce: nonce.nonce } : {}) // from the app's Google Sign-In SDK, asked with the nonce
|
|
187
196
|
await auth.linkGoogle(idToken) // signed in: connect Google from the account screen
|
|
188
197
|
await auth.signInWithPasskey(Passkeys)
|
|
189
|
-
new RPCLink({ url, headers: auth.authHeaders }) // Bearer on every RPC call
|
|
198
|
+
new RPCLink({ url, headers: auth.authHeaders }) // Bearer on every RPC call; in its error interceptor: auth.handleUnauthorized(error)
|
|
190
199
|
```
|
|
191
200
|
|
|
192
|
-
|
|
201
|
+
`restore()` at launch checks the saved token with the server. Offline, the session is `unverified`: never signed in (show signed-out or cached screens) and `restore()` again when back online. Any UNAUTHORIZED answer passed to `handleUnauthorized` forgets the token.
|
|
202
|
+
|
|
203
|
+
On Android, `googleIdToken(nativeModule, webClientId, nonce)` gets the ID token from the phone's Google account sheet (the app's own Credential Manager module: `signIn(serverClientId)` answering `{ idToken }`, rejecting with `ERR_CANCELLED` or `ERR_NO_ACCOUNT`). It answers `{ ok: true, idToken }`, or `CANCELLED`, `NO_GOOGLE_ACCOUNT`, `GOOGLE_UNAVAILABLE` (no module or client ID), or `GOOGLE_FAILED` with a `detail` for the error tracker.
|
|
193
204
|
|
|
194
205
|
Failures come back as codes (`INVALID_USERNAME_OR_PASSWORD`, `ACCOUNT_NOT_LINKED`, `GOOGLE_ALREADY_LINKED`, `TOO_MANY_REQUESTS`, `NETWORK`, `CANCELLED`…), and the app words them. The module has no dependencies: the app passes in its secure storage and passkey modules.
|
|
195
206
|
|
|
@@ -353,6 +364,61 @@ Every text pair meets WCAG AA; `src/contrast.test.ts` checks them, and the E2E t
|
|
|
353
364
|
|
|
354
365
|
Type: Bricolage Grotesque (700/800) for titles and numbers (`tabular-nums`), Figtree (400/500/600) for the rest. Sentence case everywhere. Shape: tiles 24 px (20 on phones), controls 12 px, pills. Motion only in answer to an action, and none with `prefers-reduced-motion`.
|
|
355
366
|
|
|
367
|
+
### `@jgb-solutions/kit/account`: the sign-in and account pages (React 19, and Expo)
|
|
368
|
+
|
|
369
|
+
One sign-in, sign-up and account layout for every app, chosen by the owner (2026-12-04): the same field order, buttons, links and wording rules everywhere, on the web and in Expo. Each app changes only the look (colours, fonts, radius) and the words.
|
|
370
|
+
|
|
371
|
+
- **In:** the sign-in, sign-up and "signed in" cards, and the account page (Profile, the app's own cards, Passkeys, Google, Password, Delete account), in a fixed order.
|
|
372
|
+
- **Not in:** sign-in itself. Every button calls the app's action, which answers `{ ok: true } | { ok: false, code }` (`kit/auth/server`'s `AuthResult`). The kit words the code with the app's `AccountText` (`errorText`), and never shows a raw error. On success the app goes where it wants; the panel stays busy until it does.
|
|
373
|
+
|
|
374
|
+
```tsx
|
|
375
|
+
import '@jgb-solutions/kit/account/styles.css'
|
|
376
|
+
import { AccountRoot, SignInPanel, accountTextEn } from '@jgb-solutions/kit/account'
|
|
377
|
+
|
|
378
|
+
export function SignInPage() {
|
|
379
|
+
return (
|
|
380
|
+
<AccountRoot scheme="dark" theme={{ brand: '#d42320', radiusButton: '12px' }}>
|
|
381
|
+
<SignInPanel
|
|
382
|
+
text={accountTextEn}
|
|
383
|
+
reason={reasonText} // "Sign in to save it to your favorites", or undefined
|
|
384
|
+
initialError={search.error} // Google's ?error= code
|
|
385
|
+
google={() => startGoogleSignIn({ data: { redirect } })} // leave out when Google is off
|
|
386
|
+
passkey={signInWithPasskey}
|
|
387
|
+
onSignIn={(input) => signIn({ data: input })}
|
|
388
|
+
signUpHref="/sign-up"
|
|
389
|
+
renderLink={({ href, className, children }) => (
|
|
390
|
+
<Link to={href} className={className}>
|
|
391
|
+
{children}
|
|
392
|
+
</Link>
|
|
393
|
+
)}
|
|
394
|
+
/>
|
|
395
|
+
</AccountRoot>
|
|
396
|
+
)
|
|
397
|
+
}
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
`SignUpPanel` and `SignedInPanel` work the same way. `AccountPage` takes the person, the passkeys, and one action per change; `afterProfile` holds the app's own cards (notifications, a callout). Deleting an account asks for the password, or, for an account made with Google, a Google sign-in from the last 5 minutes (`confirm: { mode: 'reauth', fresh, onReauth }`, matching `authServer`'s `REAUTH_REQUIRED`). The sections (`ProfileSection`, `PasskeysSection`, `GoogleSection`, `PasswordSection`, `DangerSection`) are exported for a page that needs them apart.
|
|
401
|
+
|
|
402
|
+
**Words:** `AccountText` holds every string; words with a number or a name are functions. Pass a translation, or `{ ...accountTextEn, … }` with a few lines changed. Dates print in UTC, so the server and the browser print the same.
|
|
403
|
+
|
|
404
|
+
**Look:** `AccountRoot`'s `theme` sets these tokens (CSS variables on `.jac-root`; every class is prefixed `jac-`, so nothing outside changes). Light by default, dark with `scheme="dark"` or the system's dark mode (dark by default is a near-black grey). `brandInk` is picked for contrast when the brand is a hex colour.
|
|
405
|
+
|
|
406
|
+
| Theme key | Token | Light default | Dark default |
|
|
407
|
+
| ----------------------------------------------- | -------------------------------------------- | --------------------------------- | --------------------------------- |
|
|
408
|
+
| `brand` / `brandInk` / `brandText` | `--jac-brand` / `-brand-ink` / `-brand-text` | `#2f54c8` / white / `#2a4bb3` | same / same / brand mixed light |
|
|
409
|
+
| `page` / `surface` / `raised` | `--jac-page` / `-surface` / `-raised` | `#f4f4f6` / `#ffffff` / `#ececf0` | `#0b0b0e` / `#15151a` / `#212127` |
|
|
410
|
+
| `line` / `fieldLine` | `--jac-line` / `-field-line` | `#dcdce3` / `#a9a9b4` | `#2d2d34` / `#55555e` |
|
|
411
|
+
| `ink` / `muted` | `--jac-ink` / `-muted` | `#17171c` / `#5b5b66` | `#eeeef1` / `#aaaab2` |
|
|
412
|
+
| `good` / `warn` / `bad` / `info` | `--jac-good` / `-warn` / `-bad` / `-info` | AA on cards | AA on cards |
|
|
413
|
+
| `radiusCard` / `radiusControl` / `radiusButton` | `--jac-radius-card` / `-control` / `-button` | 16px / 12px / 12px | same |
|
|
414
|
+
| `fontDisplay` / `fontBody` | `--jac-font-display` / `-body` | the system's sans | same |
|
|
415
|
+
|
|
416
|
+
Google's button keeps Google's own white style and mark in every theme (its branding rules).
|
|
417
|
+
|
|
418
|
+
#### `kit/account/native`: the same screen in Expo
|
|
419
|
+
|
|
420
|
+
`SignInOrUp` (sign-in and sign-up on one screen, with the mode link), `AccountProfile` (the profile, passkeys, Google, the app's `links`, Sign out, and Delete account behind a second step) and the pieces (`NativeField`, `NativeButton`, `NativeGoogleButton`, `NativeNotice`, `NativeError`, `NativeAvatar`). Same `AccountText`, same actions; the theme is a plain object (`accountNativeDark` or `accountNativeLight`, with your colours, radius and fonts). Needs `react-native` and `react-native-svg` (Google's mark), both optional peer dependencies.
|
|
421
|
+
|
|
356
422
|
## What goes in, and what never goes in
|
|
357
423
|
|
|
358
424
|
**In:** generic plumbing that several apps need in the same shape, written once and tested: checking a signed token, parsing a header, a retry or rate-limit helper, a typed client for a public protocol. Every module:
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type AccountText } from './text';
|
|
3
|
+
import { type AccountLink, type AccountResult } from './ui';
|
|
4
|
+
/** A card of the account page, named by its h2. */
|
|
5
|
+
export declare function AccountSection({ title, tone, children, sectionRef, }: {
|
|
6
|
+
title: string;
|
|
7
|
+
tone?: 'danger';
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
sectionRef?: React.Ref<HTMLElement>;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
11
|
+
/** The page title and Sign out. */
|
|
12
|
+
export declare function AccountHeader({ text, onSignOut }: {
|
|
13
|
+
text: AccountText;
|
|
14
|
+
onSignOut: () => void | Promise<void>;
|
|
15
|
+
}): import("react").JSX.Element;
|
|
16
|
+
export type AccountUser = {
|
|
17
|
+
name: string;
|
|
18
|
+
username: string;
|
|
19
|
+
email: string | null;
|
|
20
|
+
image?: string | null | undefined;
|
|
21
|
+
};
|
|
22
|
+
/** A username change refused because the last one was recent: `until` is when the next can happen (ISO). */
|
|
23
|
+
export type SaveResult = AccountResult | {
|
|
24
|
+
ok: false;
|
|
25
|
+
code: 'USERNAME_CHANGED_RECENTLY';
|
|
26
|
+
until?: string | undefined;
|
|
27
|
+
};
|
|
28
|
+
export type ProfileSectionProps = {
|
|
29
|
+
text: AccountText;
|
|
30
|
+
user: AccountUser;
|
|
31
|
+
onSaveName: (name: string) => Promise<SaveResult>;
|
|
32
|
+
onSaveUsername: (username: string) => Promise<SaveResult>;
|
|
33
|
+
usernameLockedUntil?: string | null | undefined;
|
|
34
|
+
/** How often a username may change (the app's rule; 30 is common). */
|
|
35
|
+
usernameChangeDays?: number | undefined;
|
|
36
|
+
nameMax?: number | undefined;
|
|
37
|
+
/** A link to the admin panel, for people allowed in. */
|
|
38
|
+
adminHref?: string | undefined;
|
|
39
|
+
renderLink?: AccountLink | undefined;
|
|
40
|
+
};
|
|
41
|
+
/** Profile: the person, then name, username and email rows, and the admin link. */
|
|
42
|
+
export declare function ProfileSection({ text, user, onSaveName, onSaveUsername, usernameLockedUntil, usernameChangeDays, nameMax, adminHref, renderLink, }: ProfileSectionProps): import("react").JSX.Element;
|
|
43
|
+
export type Passkey = {
|
|
44
|
+
id: string;
|
|
45
|
+
name: string | null;
|
|
46
|
+
createdAt: string | null;
|
|
47
|
+
};
|
|
48
|
+
export type PasskeysSectionProps = {
|
|
49
|
+
text: AccountText;
|
|
50
|
+
passkeys: readonly Passkey[];
|
|
51
|
+
/** The account has no password (made with Google): different words, Google is the way back in. */
|
|
52
|
+
googleOnly: boolean;
|
|
53
|
+
/** Adds one, named `name` ("Passkey 2"); the app reloads the list before answering. */
|
|
54
|
+
onAdd: (name: string) => Promise<AccountResult>;
|
|
55
|
+
onRemove: (id: string) => Promise<AccountResult>;
|
|
56
|
+
};
|
|
57
|
+
/** Passkeys: why they matter, a warning when there are none, the list, and Add. */
|
|
58
|
+
export declare function PasskeysSection({ text, passkeys, googleOnly, onAdd, onRemove }: PasskeysSectionProps): import("react").JSX.Element;
|
|
59
|
+
export type GoogleSectionProps = {
|
|
60
|
+
text: AccountText;
|
|
61
|
+
connected: boolean;
|
|
62
|
+
/** Back from Google after connecting (`?connected=google`): says so, and scrolls into view. */
|
|
63
|
+
justConnected?: boolean | undefined;
|
|
64
|
+
/** Google's `?error=` code after a failed connection. */
|
|
65
|
+
initialError?: string | undefined;
|
|
66
|
+
/** Starts connecting Google (usually a redirect). */
|
|
67
|
+
onConnect: () => Promise<AccountResult>;
|
|
68
|
+
};
|
|
69
|
+
/** Google as a second way in: connected, or Connect Google. */
|
|
70
|
+
export declare function GoogleSection({ text, connected, justConnected, initialError, onConnect }: GoogleSectionProps): import("react").JSX.Element;
|
|
71
|
+
export type PasswordSectionProps = {
|
|
72
|
+
text: AccountText;
|
|
73
|
+
/** False for an account made with Google: the section offers a first password instead. */
|
|
74
|
+
hasPassword: boolean;
|
|
75
|
+
onChange: (input: {
|
|
76
|
+
currentPassword: string;
|
|
77
|
+
newPassword: string;
|
|
78
|
+
}) => Promise<AccountResult>;
|
|
79
|
+
/** Sets a first password; the app reloads (hasPassword becomes true) before answering. */
|
|
80
|
+
onSet: (input: {
|
|
81
|
+
newPassword: string;
|
|
82
|
+
}) => Promise<AccountResult>;
|
|
83
|
+
passwordMin?: number | undefined;
|
|
84
|
+
passwordMax?: number | undefined;
|
|
85
|
+
};
|
|
86
|
+
/** Change password, or Set a password for an account made with Google. */
|
|
87
|
+
export declare function PasswordSection({ text, hasPassword, onChange, onSet, passwordMin, passwordMax, }: PasswordSectionProps): import("react").JSX.Element;
|
|
88
|
+
/**
|
|
89
|
+
* How deleting is confirmed: the password, or, for an account without one (made with Google), a
|
|
90
|
+
* Google sign-in from the last `minutes` (kit/auth/server's REAUTH_MINUTES and REAUTH_REQUIRED).
|
|
91
|
+
*/
|
|
92
|
+
export type DeleteConfirm = {
|
|
93
|
+
mode: 'password';
|
|
94
|
+
} | {
|
|
95
|
+
mode: 'reauth';
|
|
96
|
+
fresh: boolean;
|
|
97
|
+
minutes?: number | undefined;
|
|
98
|
+
onReauth: () => Promise<AccountResult>;
|
|
99
|
+
};
|
|
100
|
+
export type DangerSectionProps = {
|
|
101
|
+
text: AccountText;
|
|
102
|
+
confirm: DeleteConfirm;
|
|
103
|
+
/** Deletes the account; on success the app takes the person away (the panel stays busy). */
|
|
104
|
+
onDelete: (input: {
|
|
105
|
+
password?: string;
|
|
106
|
+
}) => Promise<AccountResult>;
|
|
107
|
+
};
|
|
108
|
+
/** Delete account: a red card, confirmed by the password or by a fresh Google sign-in. */
|
|
109
|
+
export declare function DangerSection({ text, confirm, onDelete }: DangerSectionProps): import("react").JSX.Element;
|
|
110
|
+
export type AccountPageProps = {
|
|
111
|
+
text: AccountText;
|
|
112
|
+
user: AccountUser;
|
|
113
|
+
onSignOut: () => void | Promise<void>;
|
|
114
|
+
/** Just signed up (`?welcome=1`): with no passkey yet, the page asks for one first. */
|
|
115
|
+
welcome?: boolean | undefined;
|
|
116
|
+
profile: Omit<ProfileSectionProps, 'text' | 'user' | 'renderLink'>;
|
|
117
|
+
passkeys: Omit<PasskeysSectionProps, 'text' | 'googleOnly'>;
|
|
118
|
+
/** Leave out when Google sign-in isn't set up. */
|
|
119
|
+
google?: Omit<GoogleSectionProps, 'text'> | undefined;
|
|
120
|
+
password: Omit<PasswordSectionProps, 'text'>;
|
|
121
|
+
danger: Omit<DangerSectionProps, 'text'>;
|
|
122
|
+
/** The app's own cards, after Profile (notifications, then an app callout). */
|
|
123
|
+
afterProfile?: ReactNode;
|
|
124
|
+
renderLink?: AccountLink | undefined;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* The account page, in a fixed order: title and Sign out, the welcome note, Profile, the app's own
|
|
128
|
+
* cards, Passkeys, Google, Password, Delete account.
|
|
129
|
+
*/
|
|
130
|
+
export declare function AccountPage({ text, user, onSignOut, welcome, profile, passkeys, google, password, danger, afterProfile, renderLink, }: AccountPageProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type AccountText } from './text';
|
|
2
|
+
import { type AccountLink, type AccountResult } from './ui';
|
|
3
|
+
type Action<Input = void> = (input: Input) => Promise<AccountResult>;
|
|
4
|
+
type Shared = {
|
|
5
|
+
text: AccountText;
|
|
6
|
+
/** Why the visitor was sent here, in the app's words ("Sign in to save it to your favorites"). */
|
|
7
|
+
reason?: string | undefined;
|
|
8
|
+
/** An error code to show at once, such as Google's `?error=` after a failed sign-in. */
|
|
9
|
+
initialError?: string | undefined;
|
|
10
|
+
/** Starts Google's sign-in (usually a redirect). Leave out when Google isn't set up. */
|
|
11
|
+
google?: Action | undefined;
|
|
12
|
+
renderLink?: AccountLink | undefined;
|
|
13
|
+
};
|
|
14
|
+
export type SignInPanelProps = Shared & {
|
|
15
|
+
signUpHref: string;
|
|
16
|
+
onSignIn: Action<{
|
|
17
|
+
login: string;
|
|
18
|
+
password: string;
|
|
19
|
+
}>;
|
|
20
|
+
/** Signs in with a passkey. Leave out where passkeys can't work. */
|
|
21
|
+
passkey?: Action | undefined;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Sign in: the reason, an error, Google, a passkey, "or", then username or email and
|
|
25
|
+
* password. The footer links to sign-up.
|
|
26
|
+
*/
|
|
27
|
+
export declare function SignInPanel({ text, reason, initialError, google, passkey, onSignIn, signUpHref, renderLink, }: SignInPanelProps): import("react").JSX.Element;
|
|
28
|
+
export type SignUpRules = {
|
|
29
|
+
usernameMin: number;
|
|
30
|
+
usernameMax: number;
|
|
31
|
+
passwordMin: number;
|
|
32
|
+
passwordMax: number;
|
|
33
|
+
};
|
|
34
|
+
/** kit/auth/rules' limits, the ones authServer checks. */
|
|
35
|
+
export declare const DEFAULT_SIGN_UP_RULES: SignUpRules;
|
|
36
|
+
export type SignUpPanelProps = Shared & {
|
|
37
|
+
signInHref: string;
|
|
38
|
+
onSignUp: Action<{
|
|
39
|
+
username: string;
|
|
40
|
+
email: string;
|
|
41
|
+
password: string;
|
|
42
|
+
}>;
|
|
43
|
+
rules?: SignUpRules | undefined;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Create an account: the reason, an error, Google and "or", then username, email
|
|
47
|
+
* (optional) and password, the no-email warning, and the button. The footer links to sign-in.
|
|
48
|
+
*/
|
|
49
|
+
export declare function SignUpPanel({ text, reason, initialError, google, onSignUp, signInHref, rules, renderLink, }: SignUpPanelProps): import("react").JSX.Element;
|
|
50
|
+
/** After Google sends the person back: "Signed in. Taking you back…" while the app finishes. */
|
|
51
|
+
export declare function SignedInPanel({ text }: {
|
|
52
|
+
text: AccountText;
|
|
53
|
+
}): import("react").JSX.Element;
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* kit/account: the sign-in, sign-up and account pages every app shares (the owner's rule: one
|
|
3
|
+
* layout, the same everywhere). Import the stylesheet once ('@jgb-solutions/kit/account/styles.css'),
|
|
4
|
+
* wrap the pages in <AccountRoot theme={…}>, and give each panel its words (AccountText) and actions.
|
|
5
|
+
* Actions answer `{ ok: true } | { ok: false, code }` (kit/auth/server's AuthResult); the kit words the
|
|
6
|
+
* code with the app's text, and never shows a raw error.
|
|
7
|
+
*/
|
|
8
|
+
export { AccountRoot, accountTheme, type AccountRootProps, type AccountScheme, type AccountTheme } from './theme';
|
|
9
|
+
export { accountTextEn, errorText, type AccountText } from './text';
|
|
10
|
+
export { AccountAvatar, AccountButton, AuthCard, AuthField, FormMessage, GoogleButton, GoogleMark, Notice, OrDivider, plainAccountLink, type AccountButtonProps, type AccountLink, type AccountResult, type AuthFieldProps, type MessageKind, } from './ui';
|
|
11
|
+
export { DEFAULT_SIGN_UP_RULES, SignedInPanel, SignInPanel, SignUpPanel, type SignInPanelProps, type SignUpPanelProps, type SignUpRules, } from './SignIn';
|
|
12
|
+
export { AccountHeader, AccountPage, AccountSection, DangerSection, GoogleSection, PasskeysSection, PasswordSection, ProfileSection, type AccountPageProps, type AccountUser, type DangerSectionProps, type DeleteConfirm, type GoogleSectionProps, type Passkey, type PasskeysSectionProps, type PasswordSectionProps, type ProfileSectionProps, type SaveResult, } from './AccountPage';
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type AccountResult } from '../result';
|
|
3
|
+
import { type AccountText } from '../text';
|
|
4
|
+
/**
|
|
5
|
+
* kit/account/native: the same account screen for Expo apps: one column, sign in or
|
|
6
|
+
* create an account when signed out, the profile when signed in. Same words (AccountText) and the
|
|
7
|
+
* same actions as the web pages; the app changes only the theme.
|
|
8
|
+
*/
|
|
9
|
+
export type AccountNativeTheme = {
|
|
10
|
+
colors: {
|
|
11
|
+
page: string;
|
|
12
|
+
surface: string;
|
|
13
|
+
raised: string;
|
|
14
|
+
/** Field and card borders. */
|
|
15
|
+
border: string;
|
|
16
|
+
text: string;
|
|
17
|
+
muted: string;
|
|
18
|
+
/** Buttons and fills; `brandInk` must read on it. */
|
|
19
|
+
brand: string;
|
|
20
|
+
brandInk: string;
|
|
21
|
+
/** Brand-coloured text and links on the page. */
|
|
22
|
+
accent: string;
|
|
23
|
+
/** Errors, and the danger button's colour. */
|
|
24
|
+
bad: string;
|
|
25
|
+
badInk: string;
|
|
26
|
+
};
|
|
27
|
+
radius: {
|
|
28
|
+
control: number;
|
|
29
|
+
button: number;
|
|
30
|
+
};
|
|
31
|
+
fonts?: {
|
|
32
|
+
display?: string | undefined;
|
|
33
|
+
body?: string | undefined;
|
|
34
|
+
} | undefined;
|
|
35
|
+
};
|
|
36
|
+
/** Dark: near-black greys, with the kit's brand. */
|
|
37
|
+
export declare const accountNativeDark: AccountNativeTheme;
|
|
38
|
+
export declare const accountNativeLight: AccountNativeTheme;
|
|
39
|
+
type Action<Input = void> = (input: Input) => Promise<AccountResult>;
|
|
40
|
+
type Themed = {
|
|
41
|
+
theme: AccountNativeTheme;
|
|
42
|
+
};
|
|
43
|
+
export type NativeFieldProps = Themed & {
|
|
44
|
+
label: string;
|
|
45
|
+
hint?: string | undefined;
|
|
46
|
+
value: string;
|
|
47
|
+
onChangeText: (value: string) => void;
|
|
48
|
+
secure?: boolean | undefined;
|
|
49
|
+
autoComplete?: 'username' | 'email' | 'current-password' | 'new-password' | 'name' | 'off' | undefined;
|
|
50
|
+
keyboardType?: 'default' | 'email-address' | undefined;
|
|
51
|
+
/** Names start with capitals; usernames, emails and passwords never. */
|
|
52
|
+
capitalize?: 'none' | 'words' | undefined;
|
|
53
|
+
maxLength?: number | undefined;
|
|
54
|
+
};
|
|
55
|
+
/** A labelled input, 48 points tall; its hint under it. */
|
|
56
|
+
export declare function NativeField({ theme, label, hint, value, onChangeText, secure, autoComplete, keyboardType, capitalize, maxLength, }: NativeFieldProps): import("react").JSX.Element;
|
|
57
|
+
export type NativeButtonProps = Themed & {
|
|
58
|
+
label: string;
|
|
59
|
+
onPress: () => void;
|
|
60
|
+
variant?: 'primary' | 'quiet' | 'danger' | undefined;
|
|
61
|
+
/** Shows a spinner and ignores presses. */
|
|
62
|
+
busy?: boolean | undefined;
|
|
63
|
+
disabled?: boolean | undefined;
|
|
64
|
+
accessibilityLabel?: string | undefined;
|
|
65
|
+
};
|
|
66
|
+
/** A pill button, at least 44 points tall (Apple's and Google's touch size). */
|
|
67
|
+
export declare function NativeButton({ theme, label, onPress, variant, busy, disabled, accessibilityLabel, }: NativeButtonProps): import("react").JSX.Element;
|
|
68
|
+
/** "Continue with Google": Google's own white button with its mark (Google's branding rules), whatever the app's colours. */
|
|
69
|
+
export declare function NativeGoogleButton({ label, onPress, busy }: {
|
|
70
|
+
label: string;
|
|
71
|
+
onPress: () => void;
|
|
72
|
+
busy?: boolean | undefined;
|
|
73
|
+
}): import("react").JSX.Element;
|
|
74
|
+
/** An error, read out at once. */
|
|
75
|
+
export declare function NativeError({ theme, message }: Themed & {
|
|
76
|
+
message: string | null;
|
|
77
|
+
}): import("react").JSX.Element | null;
|
|
78
|
+
/** A calm note in a box: why the person is here, or a confirmation. */
|
|
79
|
+
export declare function NativeNotice({ theme, children }: Themed & {
|
|
80
|
+
children: ReactNode;
|
|
81
|
+
}): import("react").JSX.Element;
|
|
82
|
+
export type SignInOrUpProps = Themed & {
|
|
83
|
+
text: AccountText;
|
|
84
|
+
/** The intro under "Sign in" (the app's own words: what an account gives). */
|
|
85
|
+
signInIntro: string;
|
|
86
|
+
/** Why the person was sent here ("Sign in to follow Daily News"). */
|
|
87
|
+
reason?: string | undefined;
|
|
88
|
+
google?: Action | undefined;
|
|
89
|
+
/** Leave out where passkeys can't work on this device. */
|
|
90
|
+
passkey?: Action | undefined;
|
|
91
|
+
onSignIn: Action<{
|
|
92
|
+
login: string;
|
|
93
|
+
password: string;
|
|
94
|
+
}>;
|
|
95
|
+
onSignUp: Action<{
|
|
96
|
+
username: string;
|
|
97
|
+
email: string;
|
|
98
|
+
password: string;
|
|
99
|
+
}>;
|
|
100
|
+
rules?: {
|
|
101
|
+
usernameMin: number;
|
|
102
|
+
usernameMax: number;
|
|
103
|
+
passwordMin: number;
|
|
104
|
+
passwordMax: number;
|
|
105
|
+
} | undefined;
|
|
106
|
+
/** Start in sign-up mode. */
|
|
107
|
+
initialMode?: 'in' | 'up' | undefined;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Signed out: title and intro, the reason, Google, a passkey and "or" (sign-in), the
|
|
111
|
+
* fields, the no-email note (sign-up), the error, the button, and the link to the other mode.
|
|
112
|
+
*/
|
|
113
|
+
export declare function SignInOrUp({ theme, text, signInIntro, reason, google, passkey, onSignIn, onSignUp, rules, initialMode, }: SignInOrUpProps): import("react").JSX.Element;
|
|
114
|
+
/** A person's picture (https only) or initials. Decorative: the name is written next to it. */
|
|
115
|
+
export declare function NativeAvatar({ theme, user, size, }: Themed & {
|
|
116
|
+
user: {
|
|
117
|
+
name: string;
|
|
118
|
+
username: string;
|
|
119
|
+
image?: string | null | undefined;
|
|
120
|
+
};
|
|
121
|
+
size?: number;
|
|
122
|
+
}): import("react").JSX.Element;
|
|
123
|
+
type SaveResult = AccountResult | {
|
|
124
|
+
ok: false;
|
|
125
|
+
code: 'USERNAME_CHANGED_RECENTLY';
|
|
126
|
+
until?: string | undefined;
|
|
127
|
+
};
|
|
128
|
+
export type NativeDeleteConfirm = {
|
|
129
|
+
mode: 'password';
|
|
130
|
+
} | {
|
|
131
|
+
mode: 'reauth';
|
|
132
|
+
fresh: boolean;
|
|
133
|
+
minutes?: number | undefined;
|
|
134
|
+
onReauth: Action;
|
|
135
|
+
};
|
|
136
|
+
export type AccountProfileProps = Themed & {
|
|
137
|
+
text: AccountText;
|
|
138
|
+
user: {
|
|
139
|
+
name: string;
|
|
140
|
+
username: string;
|
|
141
|
+
email: string | null;
|
|
142
|
+
image?: string | null | undefined;
|
|
143
|
+
};
|
|
144
|
+
onSaveName: (name: string) => Promise<SaveResult>;
|
|
145
|
+
onSaveUsername: (username: string) => Promise<SaveResult>;
|
|
146
|
+
usernameLockedUntil?: string | null | undefined;
|
|
147
|
+
usernameChangeDays?: number | undefined;
|
|
148
|
+
nameMax?: number | undefined;
|
|
149
|
+
/** Adds a passkey. Leave out where passkeys can't work on this device. */
|
|
150
|
+
onAddPasskey?: Action | undefined;
|
|
151
|
+
/** The account has no password (made with Google). */
|
|
152
|
+
googleOnly: boolean;
|
|
153
|
+
/** Leave out when Google sign-in isn't set up. */
|
|
154
|
+
google?: {
|
|
155
|
+
connected: boolean;
|
|
156
|
+
onConnect: Action;
|
|
157
|
+
} | undefined;
|
|
158
|
+
/** The app's own buttons (My home, Manage on the website), above Sign out. */
|
|
159
|
+
links?: ReactNode;
|
|
160
|
+
onSignOut: () => void | Promise<void>;
|
|
161
|
+
deleteConfirm: NativeDeleteConfirm;
|
|
162
|
+
/** Deletes the account; on success the app signs out and leaves this screen. */
|
|
163
|
+
onDelete: Action<{
|
|
164
|
+
password?: string;
|
|
165
|
+
}>;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Signed in: the avatar and Profile, name and username with Change, the email,
|
|
169
|
+
* passkeys, Google, the app's links, Sign out, and Delete account behind a second step.
|
|
170
|
+
*/
|
|
171
|
+
export declare function AccountProfile({ theme, text, user, onSaveName, onSaveUsername, usernameLockedUntil, usernameChangeDays, nameMax, onAddPasskey, googleOnly, google, links, onSignOut, deleteConfirm, onDelete, }: AccountProfileProps): import("react").JSX.Element;
|
|
172
|
+
export { accountTextEn, errorText, type AccountText } from '../text';
|
|
173
|
+
export type { AccountResult } from '../result';
|