@protobase/cli 0.63.0 → 0.63.2
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/dist/cli/package.js +1 -1
- package/dist/users/register.js +3 -2
- package/package.json +7 -7
- package/skills/protobase/references/features/sign-in-and-accounts.md +1 -1
- package/skills/protobase/references/guides/send-from-gmail.md +1 -1
- package/skills/protobase/references/reference/auth.md +4 -2
- package/skills/protobase/references/reference/cli.md +2 -2
- package/skills/protobase/references/reference/config/sign-in.md +3 -3
- package/skills/protobase/references/reference/email.md +1 -1
package/dist/cli/package.js
CHANGED
package/dist/users/register.js
CHANGED
|
@@ -87,12 +87,13 @@ const registerUsers = (program) => {
|
|
|
87
87
|
});
|
|
88
88
|
};
|
|
89
89
|
const registerToken = (program) => {
|
|
90
|
-
program.command("token").description("Print a bearer token (JWT) for an existing user").argument("<email>").option("--ttl <duration>", "lifetime: 30s, 15m, up to 24h", "15m").action(async (email, opts) => {
|
|
90
|
+
program.command("token").description("Print a bearer token (JWT) for an existing user").argument("<email>").option("--ttl <duration>", "lifetime: 30s, 15m, up to 24h", "15m").option("--organization <slug|id>", "with organizations, the one the token works in (default: where a new session starts)").action(async (email, opts) => {
|
|
91
91
|
const ttlSeconds = parseTtl(opts.ttl);
|
|
92
92
|
const [{ issueToken }, auth] = await Promise.all([import("@protobase/server"), loadAuth()]);
|
|
93
93
|
const { token } = await issueToken(auth, {
|
|
94
94
|
email,
|
|
95
|
-
ttlSeconds
|
|
95
|
+
ttlSeconds,
|
|
96
|
+
...opts.organization !== void 0 && { organization: opts.organization }
|
|
96
97
|
});
|
|
97
98
|
out(`${token}\n`);
|
|
98
99
|
finish(0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.63.
|
|
3
|
+
"version": "0.63.2",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@better-auth/core": "^1.7.12",
|
|
44
44
|
"@hono/node-server": "^2.1.3",
|
|
45
|
-
"@protobase/config": "0.63.
|
|
46
|
-
"@protobase/layout": "0.63.
|
|
47
|
-
"@protobase/query": "0.63.
|
|
48
|
-
"@protobase/schema": "0.63.
|
|
49
|
-
"@protobase/server": "0.63.
|
|
50
|
-
"@protobase/ui": "0.63.
|
|
45
|
+
"@protobase/config": "0.63.2",
|
|
46
|
+
"@protobase/layout": "0.63.2",
|
|
47
|
+
"@protobase/query": "0.63.2",
|
|
48
|
+
"@protobase/schema": "0.63.2",
|
|
49
|
+
"@protobase/server": "0.63.2",
|
|
50
|
+
"@protobase/ui": "0.63.2",
|
|
51
51
|
"@react-email/render": "^2.1.0",
|
|
52
52
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
53
53
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -30,6 +30,6 @@ Sign-in methods, users, roles, organizations and tokens.
|
|
|
30
30
|
- [Immediate revocation](../reference/auth.md#when-a-token-stops-working): A ban, removed role or ended session takes effect on the next request.
|
|
31
31
|
- [Signing key rotation](../reference/auth.md#signing-keys): The keys that sign the tokens are replaced every 30 days on their own, and old ones keep verifying the tokens they signed for a week.
|
|
32
32
|
- [Changing the secret](../reference/auth.md#changing-the-secret): The app's secret can change while the signing keys keep signing, by listing the old secret beside the new one.
|
|
33
|
-
- [Tokens for scripts](../reference/auth.md#tokens-for-scripts-and-curl): A token for an existing user, for scripts and curl.
|
|
33
|
+
- [Tokens for scripts](../reference/auth.md#tokens-for-scripts-and-curl): A token for an existing user, for scripts and curl, in any organization they work in.
|
|
34
34
|
- [Several origins](../reference/auth.md#several-origins): One app works on several domains, such as its own address and a custom domain.
|
|
35
35
|
- [Sign-in rate limits](../reference/auth.md#client-addresses): Sign-in and code requests are limited per client address, also behind a proxy.
|
|
@@ -22,7 +22,7 @@ Keep the client ID and secret for the next step.
|
|
|
22
22
|
|
|
23
23
|
## 2. Turn it on
|
|
24
24
|
|
|
25
|
-
Put the client's ID and secret in the app's environment, and name Gmail in `auth.personalMail`. Gmail links through Google sign-in, so `socialProviders` has `google`; it also offers "Continue with Google" on the sign-in page. `encryptOAuthTokens` stores the tokens encrypted with the app's secret:
|
|
25
|
+
Put the client's ID and secret in the app's environment, and name Gmail in `auth.personalMail`. Gmail links through Google sign-in, so `socialProviders` has `google`; it also offers "Continue with Google" on the sign-in page. `encryptOAuthTokens` stores the tokens encrypted with the app's secret, and personal mail needs it:
|
|
26
26
|
|
|
27
27
|
```sh
|
|
28
28
|
# .env
|
|
@@ -480,7 +480,8 @@ export default defineConfig(({ env }) => ({
|
|
|
480
480
|
- The callback URL to register with GitHub is `<url>/api/auth/callback/github`, and the same path on each of the app's [other origins](#several-origins) it should sign in on. A GitHub OAuth App takes one callback URL, so it covers one origin; a GitHub App takes several. A GitHub App needs the Email addresses (read-only) account permission, or sign-in fails with `email_not_found`.
|
|
481
481
|
- A provider is also a public sign-up: someone without an account gets one with the [default role](#roles). Without a default role the sign-up is refused.
|
|
482
482
|
- `GET /api/auth/status` lists the provider ids as `socialProviders`.
|
|
483
|
-
- `encryptOAuthTokens: true` stores the provider's access
|
|
483
|
+
- `encryptOAuthTokens: true` stores the provider's access and refresh tokens encrypted with the secret. <gap>`encryptOAuthTokens` cannot protect the provider's ID token, which is stored as the provider gave it, because encrypting or dropping it is not implemented.</gap>
|
|
484
|
+
- The provider's tokens stay on the server: Better Auth's `/api/auth/get-access-token` and `/api/auth/refresh-token`, which would answer the browser with them, are turned off.
|
|
484
485
|
- The `onUserCreated` [hook](#hooks) runs after any user is created, a social sign-up included (Better Auth's `databaseHooks.user.create.after`).
|
|
485
486
|
|
|
486
487
|
### Sign-in links and connected accounts
|
|
@@ -726,9 +727,10 @@ import { issueToken } from '@protobase/server'
|
|
|
726
727
|
|
|
727
728
|
const auth = await loadProjectAuth(process.cwd())
|
|
728
729
|
const { token, expiresAt } = await issueToken(auth, { email: 'you@example.com', ttlSeconds: 3600 }) // default 15 minutes, at most 24 hours
|
|
730
|
+
const inGlobex = await issueToken(auth, { email: 'you@example.com', organization: 'globex' }) // with organizations
|
|
729
731
|
```
|
|
730
732
|
|
|
731
|
-
It is signed with the same keys and carries the same claims as a token from `/api/auth/token
|
|
733
|
+
It is signed with the same keys and carries the same claims as a token from `/api/auth/token` for a new session of the user, with the role the user last chose, else their first, so the API treats it as any other. With [organizations](#organizations) it works in the organization a new session would start in, the one the user last worked in, else their oldest membership, and carries its `org`, `org_role` and `app_roles`; `organization`, an id or slug (`protobase token --organization`), names another, and is refused when the user may not work there, and a user in no organization gets a token without one. A ban, a role taken away or the user deleted ends it before it expires. Banned and unknown users get an error. There is no HTTP route for this.
|
|
732
734
|
|
|
733
735
|
## OAuth for MCP clients
|
|
734
736
|
|
|
@@ -608,10 +608,10 @@ Builds the project in the current directory as an iOS or Android app with Capaci
|
|
|
608
608
|
## `token`
|
|
609
609
|
|
|
610
610
|
```sh
|
|
611
|
-
protobase token <email> [--ttl 15m]
|
|
611
|
+
protobase token <email> [--ttl 15m] [--organization <slug|id>]
|
|
612
612
|
```
|
|
613
613
|
|
|
614
|
-
Prints a bearer token (JWT, signed with the project's Better Auth keys, same claims as a browser token) for an existing user. The lifetime is `30s`, `15m`, `24h`, ... up to 24 hours, default 15 minutes. Only the token goes to stdout and errors go to stderr, so it composes in scripts:
|
|
614
|
+
Prints a bearer token (JWT, signed with the project's Better Auth keys, same claims as a browser token) for an existing user. The lifetime is `30s`, `15m`, `24h`, ... up to 24 hours, default 15 minutes. With [organizations](auth.md#organizations), `--organization` names the one the token works in; without it, the token works where a new session of the user would start. Only the token goes to stdout and errors go to stderr, so it composes in scripts:
|
|
615
615
|
|
|
616
616
|
```sh
|
|
617
617
|
curl -H "Authorization: Bearer $(protobase token me@x)" http://localhost:5173/api/v1/orders?page_size=1
|
|
@@ -133,11 +133,11 @@ export default defineConfig(({ env }) => ({
|
|
|
133
133
|
- **Type:** `'gmail'[]`
|
|
134
134
|
- **Default:** none
|
|
135
135
|
|
|
136
|
-
The mail providers people may link their own mailbox with, for the app's functions to send mail from it; each links through its sign-in provider in `socialProviders`, Gmail through `google`. See [From someone's own mailbox](../email.md#from-someones-own-mailbox).
|
|
136
|
+
The mail providers people may link their own mailbox with, for the app's functions to send mail from it; each links through its sign-in provider in `socialProviders`, Gmail through `google`. It needs [`auth.encryptOAuthTokens`](#authencryptoauthtokens): without it, startup stops, since the linked mailboxes' tokens would be stored in plain text. See [From someone's own mailbox](../email.md#from-someones-own-mailbox).
|
|
137
137
|
|
|
138
138
|
```ts
|
|
139
139
|
export default defineConfig(({ env }) => ({
|
|
140
|
-
auth: { socialProviders: { google: { clientId: env.GOOGLE_CLIENT_ID!, clientSecret: env.GOOGLE_CLIENT_SECRET! } }, personalMail: ['gmail'] },
|
|
140
|
+
auth: { socialProviders: { google: { clientId: env.GOOGLE_CLIENT_ID!, clientSecret: env.GOOGLE_CLIENT_SECRET! } }, personalMail: ['gmail'], encryptOAuthTokens: true },
|
|
141
141
|
}))
|
|
142
142
|
```
|
|
143
143
|
|
|
@@ -146,7 +146,7 @@ export default defineConfig(({ env }) => ({
|
|
|
146
146
|
- **Type:** `boolean`
|
|
147
147
|
- **Default:** `false`
|
|
148
148
|
|
|
149
|
-
Encrypts the OAuth access
|
|
149
|
+
Encrypts the OAuth access and refresh tokens kept for social sign-ins, with the app's secret. [`auth.personalMail`](#authpersonalmail) needs it.
|
|
150
150
|
|
|
151
151
|
```ts
|
|
152
152
|
export default defineConfig({ auth: { encryptOAuthTokens: true } })
|
|
@@ -240,7 +240,7 @@ export default defineFunction(async (request, { personalMail }) => {
|
|
|
240
240
|
})
|
|
241
241
|
```
|
|
242
242
|
|
|
243
|
-
- **Tokens:** the link is the sign-in provider's account Better Auth keeps for the person, with its access and refresh tokens
|
|
243
|
+
- **Tokens:** the link is the sign-in provider's account Better Auth keeps for the person, with its access and refresh tokens, encrypted: `auth.personalMail` needs `encryptOAuthTokens: true`, and startup stops without it. The tokens never leave the server. An access token that has expired is refreshed before the message goes out, and the new one is stored.
|
|
244
244
|
- **When it cannot send:** `send` rejects with a `PersonalMailError` and sends nothing. Its `code` is `not_linked` when the person linked no mailbox, or signed in with Google without allowing it to send mail, and `link_expired` when the provider no longer honours the link, as when they revoked it or its refresh token expired: they connect it again. Thrown on, it answers the function's caller as a `409` problem with that `code` (`urn:protobase:problem:personal-mail-not-linked` or `-link-expired`), so the page can offer to link the mailbox:
|
|
245
245
|
|
|
246
246
|
```json
|