@cubicecho/server-kit 0.1.0 → 0.2.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/LICENSE +0 -0
- package/README.md +0 -0
- package/_agents/docs/01-database.md +0 -0
- package/_agents/docs/02-columns.md +0 -0
- package/_agents/docs/03-testing.md +0 -0
- package/_agents/docs/04-auth.md +41 -0
- package/_agents/docs/common-mistakes.md +0 -0
- package/dist/auth/defaults.d.ts +20 -0
- package/dist/auth/defaults.js +12 -0
- package/dist/auth/index.d.ts +3 -0
- package/dist/auth/index.js +3 -0
- package/dist/auth/plugins.d.ts +1270 -0
- package/dist/auth/plugins.js +39 -0
- package/dist/auth/preset.d.ts +53 -0
- package/dist/auth/preset.js +21 -0
- package/dist/columns/index.d.ts +0 -0
- package/dist/columns/index.js +0 -0
- package/dist/consts.d.ts +0 -0
- package/dist/consts.js +0 -0
- package/dist/db/connection.d.ts +0 -0
- package/dist/db/connection.js +0 -0
- package/dist/db/create.d.ts +0 -0
- package/dist/db/create.js +0 -0
- package/dist/db/defaults.d.ts +0 -0
- package/dist/db/defaults.js +0 -0
- package/dist/db/errors.d.ts +0 -0
- package/dist/db/errors.js +0 -0
- package/dist/db/index.d.ts +0 -0
- package/dist/db/index.js +0 -0
- package/dist/db/prepare.d.ts +0 -0
- package/dist/db/prepare.js +0 -0
- package/dist/db/ssl.d.ts +0 -0
- package/dist/db/ssl.js +0 -0
- package/dist/db/version.d.ts +0 -0
- package/dist/db/version.js +0 -0
- package/dist/db/wait.d.ts +0 -0
- package/dist/db/wait.js +0 -0
- package/dist/testing/index.d.ts +0 -0
- package/dist/testing/index.js +0 -0
- package/dist/testing/postgres-problems.d.ts +0 -0
- package/dist/testing/postgres-problems.js +0 -0
- package/dist/testing/schema-problems.d.ts +0 -0
- package/dist/testing/schema-problems.js +0 -0
- package/llms.txt +16 -1
- package/package.json +13 -1
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Auth preset
|
|
2
|
+
|
|
3
|
+
`@cubicecho/server-kit/auth` has the better-auth options and sign-in plugins every server shares: sessions in Postgres, bearer tokens, emailed links, and OIDC with pairing. The app still calls `betterAuth`, so it adds its own plugins and hooks and keeps exact types.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { apiKey } from '@better-auth/api-key';
|
|
7
|
+
import { authPreset, signInPlugins } from '@cubicecho/server-kit/auth';
|
|
8
|
+
import { betterAuth } from 'better-auth';
|
|
9
|
+
|
|
10
|
+
const auth = betterAuth({
|
|
11
|
+
...authPreset({
|
|
12
|
+
db,
|
|
13
|
+
tables: {
|
|
14
|
+
user: users,
|
|
15
|
+
session: sessions,
|
|
16
|
+
account: accounts,
|
|
17
|
+
verification: verifications,
|
|
18
|
+
apikey: apikeys,
|
|
19
|
+
ssoProvider: ssoProviders,
|
|
20
|
+
},
|
|
21
|
+
secret,
|
|
22
|
+
serverUrl,
|
|
23
|
+
appUrl,
|
|
24
|
+
}),
|
|
25
|
+
databaseHooks: { user: { create: { after: (user) => claimFirstAdmin(db, user.id) } } },
|
|
26
|
+
plugins: [
|
|
27
|
+
apiKey({ defaultPrefix: 'todo_', requireName: true, rateLimit: { enabled: false } }),
|
|
28
|
+
...signInPlugins({
|
|
29
|
+
appUrl,
|
|
30
|
+
deliver: sendMagicLinkEmail,
|
|
31
|
+
oidc: { clientName: 'Todo', canPair: ({ userId }) => mayPair(userId) },
|
|
32
|
+
}),
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- Set every `id` column with `id()`: the preset leaves ids to the database.
|
|
38
|
+
- `deliver: undefined` is an instance that cannot email. `sendsMagicLinks(auth)` says which it is.
|
|
39
|
+
- `paths` moves the app's `login`, `verify` and `signedIn` pages.
|
|
40
|
+
- An option after the spread replaces the preset's whole value, so `session: { … }` has to repeat `expiresIn`.
|
|
41
|
+
- `@better-auth/sso` and `better-auth` are peers: install both in the server.
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Session and link lifetimes. */
|
|
2
|
+
export interface AuthSettings {
|
|
3
|
+
/** How long a session lasts after it was last used. Long: there is no password to fall back on. */
|
|
4
|
+
sessionTtlDays: number;
|
|
5
|
+
/** How long an emailed sign-in link works. Short: it travels by mail. */
|
|
6
|
+
magicLinkTtlMinutes: number;
|
|
7
|
+
}
|
|
8
|
+
/** What `authPreset` and `signInPlugins` use when the app overrides nothing. */
|
|
9
|
+
export declare const AUTH_DEFAULTS: Readonly<AuthSettings>;
|
|
10
|
+
/** The app's pages a sign-in passes through, as paths under `appUrl`. */
|
|
11
|
+
export interface AuthPaths {
|
|
12
|
+
/** The sign-in page, where a failed sign-in goes. */
|
|
13
|
+
login: string;
|
|
14
|
+
/** Spends an emailed link's token. */
|
|
15
|
+
verify: string;
|
|
16
|
+
/** Spends the one-time token an OIDC sign-in ends in. */
|
|
17
|
+
signedIn: string;
|
|
18
|
+
}
|
|
19
|
+
/** Where those pages are when the app overrides nothing. */
|
|
20
|
+
export declare const AUTH_PATHS: Readonly<AuthPaths>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Every value someone might tune, as plain data. Nothing here computes, reads the environment or imports.
|
|
2
|
+
/** What `authPreset` and `signInPlugins` use when the app overrides nothing. */
|
|
3
|
+
export const AUTH_DEFAULTS = Object.freeze({
|
|
4
|
+
sessionTtlDays: 30,
|
|
5
|
+
magicLinkTtlMinutes: 15,
|
|
6
|
+
});
|
|
7
|
+
/** Where those pages are when the app overrides nothing. */
|
|
8
|
+
export const AUTH_PATHS = Object.freeze({
|
|
9
|
+
login: '/login',
|
|
10
|
+
verify: '/auth/verify',
|
|
11
|
+
signedIn: '/auth/sso',
|
|
12
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { AUTH_DEFAULTS, AUTH_PATHS, type AuthPaths, type AuthSettings } from './defaults.ts';
|
|
2
|
+
export { type MagicLink, type SignInOptions, sendsMagicLinks, signInPlugins } from './plugins.ts';
|
|
3
|
+
export { type AuthPresetOptions, type AuthTables, authPreset } from './preset.ts';
|