@protobase/cli 0.28.3 → 0.28.4

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.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.28.3";
2
+ var version = "0.28.4";
3
3
  //#endregion
4
4
  export { version };
@@ -8,7 +8,7 @@ const createUserCommand = async (api, options, deps, out) => {
8
8
  const role = !await api.hasUsers() ? "admin" : options.role;
9
9
  const user = await api.createUser({
10
10
  email: options.email,
11
- password,
11
+ ...password !== void 0 && { password },
12
12
  ...role && { role },
13
13
  ...options.name && { name: options.name },
14
14
  ...options.githubId && { accounts: [{
@@ -1,7 +1,7 @@
1
1
  import { randomBytes } from "node:crypto";
2
2
  //#region src/users/password.ts
3
3
  const rejectPasswordArgument = (value) => {
4
- if (value === void 0) return;
4
+ if (value === void 0 || value === false) return;
5
5
  throw new Error("Passwords are never accepted as arguments (they end up in shell history); type it at the prompt, or use --password-stdin or --generate-password");
6
6
  };
7
7
  const generatePassword = () => randomBytes(18).toString("base64url");
@@ -44,7 +44,12 @@ const readHidden = (question) => new Promise((resolve, reject) => {
44
44
  stdin.on("data", onData);
45
45
  });
46
46
  const resolvePassword = async (options, deps) => {
47
- if (options.passwordStdin && options.generatePassword) throw new Error("Use either --password-stdin or --generate-password, not both");
47
+ if ([
48
+ options.passwordStdin,
49
+ options.generatePassword,
50
+ options.noPassword
51
+ ].filter(Boolean).length > 1) throw new Error("Use only one of --password-stdin, --generate-password and --no-password");
52
+ if (options.noPassword) return { generated: false };
48
53
  if (options.generatePassword) return {
49
54
  password: generatePassword(),
50
55
  generated: true
@@ -36,7 +36,7 @@ const ask = async (question) => {
36
36
  const finish = (code) => process.exit(code);
37
37
  const registerUsers = (program) => {
38
38
  const users = program.command("users").description("Manage the admin users of the project in the current directory");
39
- users.command("create").description("Create a user; the first user is always an admin").argument("<email>").option("--name <name>", "display name").option("--role <role>", "role for users after the first (default: the project's default role; see `users roles`)").option("--password-stdin", "read the password from stdin", false).option("--generate-password", "generate a strong password and print it once", false).option("--github-id <id>", "link the user to this GitHub user id, so signing in with GitHub finds them whatever their address").option("--organization <organization>", "with organizations: add the user to this one (its slug or id)").option("--org-role <role>", "with --organization: owner, admin or member (default member)").option("--app-roles <roles>", "with --organization: app roles there, comma separated").addOption(new Option("--password <value>").hideHelp()).action(async (email, opts) => {
39
+ users.command("create").description("Create a user; the first user is always an admin").argument("<email>").option("--name <name>", "display name").option("--role <role>", "role for users after the first (default: the project's default role; see `users roles`)").option("--password-stdin", "read the password from stdin", false).option("--generate-password", "generate a strong password and print it once", false).option("--no-password", "no password: the user signs in by emailed code, passkey or a sign-in provider").option("--github-id <id>", "link the user to this GitHub user id, so signing in with GitHub finds them whatever their address").option("--organization <organization>", "with organizations: add the user to this one (its slug or id)").option("--org-role <role>", "with --organization: owner, admin or member (default member)").option("--app-roles <roles>", "with --organization: app roles there, comma separated").addOption(new Option("--password <value>").hideHelp()).action(async (email, opts) => {
40
40
  rejectPasswordArgument(opts.password);
41
41
  const auth = await loadProjectAuth(process.cwd());
42
42
  await createUserCommand(usersApi(auth), {
@@ -45,6 +45,7 @@ const registerUsers = (program) => {
45
45
  role: opts.role,
46
46
  passwordStdin: opts.passwordStdin,
47
47
  generatePassword: opts.generatePassword,
48
+ noPassword: opts.password === false,
48
49
  githubId: opts.githubId
49
50
  }, {
50
51
  stdin: process.stdin,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.28.3",
3
+ "version": "0.28.4",
4
4
  "description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -35,11 +35,11 @@
35
35
  "dependencies": {
36
36
  "@hono/node-server": "^2.1.3",
37
37
  "@hono/vite-dev-server": "^0.26.1",
38
- "@protobase/layout": "0.28.3",
39
- "@protobase/query": "0.28.3",
40
- "@protobase/schema": "0.28.3",
41
- "@protobase/server": "0.28.3",
42
- "@protobase/ui": "0.28.3",
38
+ "@protobase/layout": "0.28.4",
39
+ "@protobase/query": "0.28.4",
40
+ "@protobase/schema": "0.28.4",
41
+ "@protobase/server": "0.28.4",
42
+ "@protobase/ui": "0.28.4",
43
43
  "@react-email/render": "^2.1.0",
44
44
  "@scalar/hono-api-reference": "^0.12.10",
45
45
  "@tailwindcss/vite": "^4.3.3",
@@ -88,12 +88,12 @@ The columns Better Auth needs that the table lacks, filled from what the other s
88
88
 
89
89
  ## First run
90
90
 
91
- Accounts are never created over the web while the store is empty: there is no setup route, and [open sign-up](#open-sign-up), when an app turns it on, waits for the first admin, so a freshly deployed URL cannot be claimed by whoever reaches it first. The first admin is created on the host, with the CLI (`protobase users create you@example.com --generate-password`) or from code:
91
+ Accounts are never created over the web while the store is empty: there is no setup route, and [open sign-up](#open-sign-up), when an app turns it on, waits for the first admin, so a freshly deployed URL cannot be claimed by whoever reaches it first. The first admin is created on the host, with the CLI (`protobase users create you@example.com --generate-password`, or `--no-password` for an account that signs in by emailed code, passkey or a sign-in provider only) or from code:
92
92
 
93
93
  ```ts
94
94
  import { createUser, hasUsers, listUsers } from '@protobase/server'
95
95
 
96
- await createUser(auth, { email, password, name?, role? }) // the first user is always an admin; later ones default to `user`
96
+ await createUser(auth, { email, password?, name?, role? }) // the first user is always an admin; later ones default to `user`
97
97
  await hasUsers(auth) // boolean
98
98
  await listUsers(auth) // [{ id, email, role, banned, createdAt }], never passwords
99
99
  await setUserRole(auth, { email, role }) // 'admin' | 'user'
@@ -219,7 +219,15 @@ Admins set how people sign in on the app's **Sign-in policy** page (the profile
219
219
  | Staff sign-in as a person | On, Email the person, Off | On |
220
220
  | Sign in with ... through the platform | On, Off | On |
221
221
 
222
- The server stores the policy in the `sign_in_policy` table, one row per save (the newest applies, the others are its history, with who saved each and when), and applies it to Better Auth's endpoints; the pages only show what it allows.
222
+ The Default column is the policy of an app that sets none. An app sets its own in code, the policy that applies until an admin saves one, such as emailed codes and passkeys only, with the methods it changes:
223
+
224
+ ```ts
225
+ createAuth({ ..., signInPolicy: { password: 'forbidden' } })
226
+ ```
227
+
228
+ It is checked at startup as an admin's save is, so a default that would lock people out stops the app; without mail it applies as a saved policy does (password sign-in is then on). The page shows it, as never changed, until an admin saves a policy. Pair it with `protobase users create --no-password`, so the first admin has no password to fall back on.
229
+
230
+ The server stores the policy in the `sign_in_policy` table, one row per save (the newest applies, the others are its history, with who saved each and when; a newest row that no longer reads, with a rule the method does not take, counts as none, so the app's default applies), and applies it to Better Auth's endpoints; the pages only show what it allows.
223
231
 
224
232
  - **Off:** the server refuses the method with `403` (`SIGN_IN_METHOD_FORBIDDEN`) and the sign-in page leaves it out. Passkeys off also stops adding them; two-factor off stops turning it on, while those who have it keep being asked until they turn it off.
225
233
  - **Required:** someone who signs in without it is sent to set it up first. The server holds back API tokens until then (`GET /api/auth/token` answers `403`, `SIGN_IN_SETUP_REQUIRED`), and refuses to turn two-factor authentication off or to remove the last passkey.
@@ -410,7 +410,7 @@ Runs the [scheduled file deletes](files.md#deleting-files)) that are due: replac
410
410
  ## `users`
411
411
 
412
412
  ```sh
413
- protobase users create <email> [--name <name>] [--role <role>] [--password-stdin | --generate-password] [--github-id <id>]
413
+ protobase users create <email> [--name <name>] [--role <role>] [--password-stdin | --generate-password | --no-password] [--github-id <id>]
414
414
  [--organization <slug> [--org-role <role>] [--app-roles <a,b>]]
415
415
  protobase users list
416
416
  protobase users roles
@@ -421,7 +421,7 @@ protobase users delete <email> [--yes]
421
421
 
422
422
  Run inside a project whose `protobase.config.ts` exports `auth` (Better Auth). There is no web setup page, and [open sign-up](auth.md#open-sign-up)), when a project turns it on, waits for the first admin: the first admin is created here. The first user is always an admin, whatever `--role` says; later users get `--role`, or the project's default role (`createAuth({ roles, defaultRole })`). `protobase users roles` lists the roles of the project; anything else is refused with that list. `set-role` also takes comma separated roles (`sales,accountant`). `--github-id` links the new user to a GitHub user id (the number, not the login), so signing in with GitHub, the app's own provider or the [platform's](auth.md#platform-sign-in-provider)), finds them whatever address GitHub reports; an id that signs in another user already is refused. `createUser(auth, { ..., accounts: [{ providerId, accountId }] })` does the same from code.
423
423
 
424
- The password is typed at a hidden prompt with confirmation, read from stdin with `--password-stdin` (for scripts, e.g. `pass show erp | protobase users create me@example.com --password-stdin`), or generated with `--generate-password` and printed once. A password is never accepted as an argument, since it would end up in shell history. `users list` prints email, role and creation date (and `disabled` for banned users), never credentials.
424
+ The password is typed at a hidden prompt with confirmation, read from stdin with `--password-stdin` (for scripts, e.g. `pass show erp | protobase users create me@example.com --password-stdin`), or generated with `--generate-password` and printed once. `--no-password` makes an account without one, which signs in by [emailed code](auth.md#emailed-sign-in-codes)), passkey or a sign-in provider, as with an app whose [sign-in policy](auth.md#sign-in-policy)) turns passwords off. A password is never accepted as an argument, since it would end up in shell history. `users list` prints email, role and creation date (and `disabled` for banned users), never credentials.
425
425
 
426
426
  `delete` asks you to type the email back (or pass `--yes`), and needs a terminal otherwise. `delete`, `set-role` and `disable` refuse to touch the last admin, so the project cannot lock itself out. `disable` bans the user and revokes their sessions; tokens already issued stop working within their lifetime (15 minutes by default), and `protobase token` refuses disabled users. `enable` lifts the ban. `protobase dev` prints "No users yet. Create the first admin with: protobase users create you@example.com" at startup while the user table is empty.
427
427