@aphexcms/auth 0.1.0 → 0.2.1

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/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # @aphexcms/auth
2
+
3
+ [Better Auth](https://better-auth.com) wiring for [AphexCMS](https://github.com/IcelandicIcecream/aphex), in one call.
4
+
5
+ Aphex is auth-agnostic — `cms-core` defines an `AuthProvider` port and doesn't care what implements it. This package is the batteries-included implementation: sessions, organizations, invitations, API keys, two-factor, and the email flows, already mapped onto Aphex's capability model.
6
+
7
+ 📚 **Documentation: [docs.getaphex.com/authentication](https://docs.getaphex.com/authentication)**
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pnpm add @aphexcms/auth better-auth @better-auth/api-key
13
+ ```
14
+
15
+ ## Quick start
16
+
17
+ ```ts title="src/lib/server/auth/index.ts"
18
+ import { createAphexAuth } from '@aphexcms/auth';
19
+ import { db, drizzleDb, dbDialect } from '$lib/server/db';
20
+ import { email } from '$lib/server/email';
21
+
22
+ export const {
23
+ auth,
24
+ service: authService,
25
+ provider: authProvider
26
+ } = createAphexAuth({
27
+ database: db,
28
+ drizzleDb,
29
+ dialect: dbDialect,
30
+ secret: env.AUTH_SECRET,
31
+ baseURL: env.AUTH_URL,
32
+ trustedOrigins: [env.AUTH_URL],
33
+ emailAdapter: email,
34
+ appName: 'My CMS'
35
+ });
36
+ ```
37
+
38
+ `provider` is what `createCMSConfig()` wants:
39
+
40
+ ```ts title="aphex.config.ts"
41
+ export default createCMSConfig({
42
+ schemaTypes,
43
+ database: db,
44
+ auth: { provider: authProvider, loginUrl: '/login' }
45
+ });
46
+ ```
47
+
48
+ ## Environment
49
+
50
+ ```bash
51
+ AUTH_SECRET= # node -e "console.log(require('crypto').randomBytes(32).toString('base64url'))"
52
+ AUTH_URL=http://localhost:5173
53
+ AUTH_TRUSTED_ORIGINS=http://localhost:5173
54
+ ```
55
+
56
+ `BETTER_AUTH_SECRET` / `BETTER_AUTH_URL` still work as aliases, but prefer the `AUTH_*` spellings.
57
+
58
+ Rotating `AUTH_SECRET` signs everyone out and invalidates every API key, so generate one per environment and keep it.
59
+
60
+ `AUTH_TRUSTED_ORIGINS` is not optional in production: Better Auth uses it for CSRF and origin checks, and without it cookie-authenticated mutations are reachable from any site a signed-in admin visits.
61
+
62
+ ## Schema
63
+
64
+ Auth tables are dialect-specific and exported separately, because Drizzle needs the real table objects:
65
+
66
+ ```ts
67
+ import * as authSchema from '@aphexcms/auth/schema/pg'; // or /schema/sqlite
68
+ ```
69
+
70
+ ## Email verification is off by default
71
+
72
+ The first user to sign up becomes super admin and can sign in immediately, with no SMTP server — which is what makes a fresh project runnable in one command. Turn verification on with `AUTH_REQUIRE_EMAIL_VERIFICATION=true` once you have an email adapter configured. In production you want it on: without it, anyone can sign up with an address they don't own.
73
+
74
+ ## License
75
+
76
+ MIT
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@aphexcms/auth",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
- "access": "public"
6
+ "access": "public",
7
+ "provenance": true
7
8
  },
8
9
  "repository": {
9
10
  "type": "git",
@@ -33,21 +34,18 @@
33
34
  "files": [
34
35
  "dist"
35
36
  ],
36
- "dependencies": {
37
- "@aphexcms/cms-core": "^9.8.1"
38
- },
39
37
  "peerDependencies": {
38
+ "@aphexcms/cms-core": ">=11.0.0",
40
39
  "@better-auth/api-key": "^1.6.25",
41
40
  "better-auth": "^1.6.25",
42
- "drizzle-orm": "^0.45.2",
43
- "@aphexcms/cms-core": "^9.8.1"
41
+ "drizzle-orm": "^0.45.2"
44
42
  },
45
43
  "devDependencies": {
46
44
  "@better-auth/api-key": "^1.6.25",
47
45
  "better-auth": "^1.6.25",
48
46
  "drizzle-orm": "^0.45.2",
49
47
  "typescript": "^5.9.3",
50
- "@aphexcms/cms-core": "^9.8.1"
48
+ "@aphexcms/cms-core": "^11.0.0"
51
49
  },
52
50
  "scripts": {
53
51
  "build": "tsc",
@@ -1,105 +0,0 @@
1
- import { type DatabaseAdapter } from '@aphexcms/cms-core/server';
2
- /** Instance-level role a bootstrap policy may grant. */
3
- export type InstanceRole = 'super_admin' | 'admin' | 'editor' | 'viewer';
4
- export interface BootstrapContext {
5
- user: {
6
- id: string;
7
- email: string;
8
- emailVerified: boolean;
9
- };
10
- /**
11
- * True only when the system is *provably* empty.
12
- *
13
- * Never inferred from a missing capability: an adapter that can't answer the
14
- * question yields `false`, so an unanswerable check can't be mistaken for
15
- * "nobody is here yet, promote this person".
16
- */
17
- isFirstUser: boolean;
18
- /** The request that triggered profile creation, when there is one. */
19
- request?: Request;
20
- db: DatabaseAdapter;
21
- }
22
- /**
23
- * Decides what instance role a brand-new user profile gets.
24
- *
25
- * Bootstrapping is a policy decision, not a library one — how you claim a fresh
26
- * instance depends on how you deploy it. Return `null` for "no promotion"; the
27
- * caller falls back to the ordinary `editor` role.
28
- */
29
- export interface BootstrapPolicy {
30
- (ctx: BootstrapContext): Promise<InstanceRole | null>;
31
- /**
32
- * Optional one-off startup step, run before any request is served.
33
- *
34
- * Lets a recipe own its own setup instead of making the app wire it: only
35
- * `claimCode()` needs one (to generate and log its code), and an app that
36
- * swaps recipes shouldn't have to remember to delete a hook. Callers invoke
37
- * it as `policy.prepare?.(db)` — recipes without setup simply omit it.
38
- */
39
- prepare?: (db: DatabaseAdapter) => Promise<void>;
40
- }
41
- /**
42
- * Ensure an unclaimed instance has a pending claim code, and log it.
43
- *
44
- * Only the **hash** is persisted: a leaked database dump or backup shouldn't be
45
- * enough to claim the instance. Called at startup by `claimCode()` consumers.
46
- */
47
- export declare function ensureClaimCode(db: DatabaseAdapter): Promise<void>;
48
- /**
49
- * True when nobody has claimed this instance yet and a code is waiting to be
50
- * used. Drives the sign-up form's claim-code field: without this the code has
51
- * nowhere to go but a hand-set cookie, which is not a flow anyone can follow.
52
- *
53
- * Deliberately narrow. It reveals only that an instance is unclaimed — never the
54
- * code or its hash — so it is safe to hand to an unauthenticated page. That fact
55
- * is already obvious to anyone who can reach a CMS with no users in it.
56
- */
57
- export declare function isInstanceUnclaimed(db: DatabaseAdapter): Promise<boolean>;
58
- /**
59
- * The default. Keeps the familiar first-run wizard, but promotion requires a
60
- * code printed to the server log at startup — so arriving first isn't enough,
61
- * you also have to control the deployment. Same shape as Jupyter's `?token=`
62
- * and GitLab's generated root password.
63
- *
64
- * The code is single-use, but not mutually exclusive: it's cleared as its own
65
- * write rather than atomically with the profile insert. Two concurrent claims
66
- * can therefore both read the hash before either clears it, and a claim can be
67
- * spent by a request whose profile insert then fails.
68
- *
69
- * That's a deliberate trade. Wrapping both in one transaction holds SQLite's
70
- * single write lock across the auth provider's own concurrent user/session
71
- * inserts, which fails the whole sign-up with SQLITE_BUSY. Closing the race
72
- * properly needs a uniqueness constraint on "one super admin" at the database
73
- * level, not a longer lock. In practice every racer must already hold the code,
74
- * so the exposure is a duplicate admin, never an unauthorised one.
75
- */
76
- export declare function claimCode(options?: {
77
- readCode?: (request?: Request) => string | undefined;
78
- }): BootstrapPolicy;
79
- /**
80
- * First user whose address is on the allowlist becomes super admin — Discourse's
81
- * `DISCOURSE_DEVELOPER_EMAILS`. Good when you know the owner's address at deploy
82
- * time and would rather not read logs.
83
- *
84
- * This recipe is only as strong as the address is trustworthy, so pair it with
85
- * `requireEmailVerification`. That's enforced at the auth layer — better-auth
86
- * refuses to complete sign-in for an unconfirmed address, so an unverified user
87
- * never reaches profile creation at all. Re-checking it here would be dead code
88
- * when verification is on, and would brick a fresh install when it's off.
89
- */
90
- export declare function allowlistEmail(emails: string | readonly string[] | undefined): BootstrapPolicy;
91
- /**
92
- * Whoever signs up first becomes super admin, with nothing else required.
93
- *
94
- * This is what WordPress, Ghost, Strapi and Payload do, and it's fine when you
95
- * install immediately after deploying. It is **not** fine for an instance that
96
- * sits reachable before anyone signs in: the first stranger to find the URL owns
97
- * it. Opt in deliberately.
98
- */
99
- export declare function openFirstUser(): BootstrapPolicy;
100
- /**
101
- * Never promote anyone. Provision the first administrator out of band — a seed
102
- * script, a migration, or a direct row — the way Directus and Keycloak do.
103
- */
104
- export declare function never(): BootstrapPolicy;
105
- //# sourceMappingURL=bootstrap.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAElF,wDAAwD;AACxD,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAKzE,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,OAAO,CAAA;KAAE,CAAC;IAC5D;;;;;;OAMG;IACH,WAAW,EAAE,OAAO,CAAC;IACrB,sEAAsE;IACtE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,EAAE,EAAE,eAAe,CAAC;CACpB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC/B,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IACtD;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACjD;AAcD;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,EAAE,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBxE;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CAAC,EAAE,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAK/E;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CACxB,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,CAAA;CAAO,GACpE,eAAe,CAmDjB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,eAAe,CAsB9F;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,IAAI,eAAe,CAE/C;AAED;;;GAGG;AACH,wBAAgB,KAAK,IAAI,eAAe,CAEvC"}
package/dist/bootstrap.js DELETED
@@ -1,164 +0,0 @@
1
- import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
2
- import { cmsLogger } from '@aphexcms/cms-core';
3
- import { isInstanceEmpty } from '@aphexcms/cms-core/server';
4
- /** Where the claim-code hash lives inside the instance-settings blob. */
5
- const CLAIM_CODE_KEY = 'bootstrapClaimCodeHash';
6
- function hashCode(code) {
7
- return createHash('sha256').update(code).digest('hex');
8
- }
9
- /** Constant-time compare of two hex digests of equal length. */
10
- function digestsMatch(a, b) {
11
- const left = Buffer.from(a, 'hex');
12
- const right = Buffer.from(b, 'hex');
13
- if (left.length !== right.length || left.length === 0)
14
- return false;
15
- return timingSafeEqual(left, right);
16
- }
17
- /**
18
- * Ensure an unclaimed instance has a pending claim code, and log it.
19
- *
20
- * Only the **hash** is persisted: a leaked database dump or backup shouldn't be
21
- * enough to claim the instance. Called at startup by `claimCode()` consumers.
22
- */
23
- export async function ensureClaimCode(db) {
24
- if (!(await isInstanceEmpty(db)))
25
- return;
26
- const settings = await db.getInstanceSettings();
27
- if (typeof settings[CLAIM_CODE_KEY] === 'string')
28
- return;
29
- const code = randomBytes(24).toString('base64url');
30
- await db.updateInstanceSettings({ [CLAIM_CODE_KEY]: hashCode(code) });
31
- cmsLogger.info('[Bootstrap]', `\n\n This instance has no administrator yet.\n` +
32
- ` Sign up at /admin and enter this claim code to become the super admin:\n\n` +
33
- ` ${code}\n\n` +
34
- ` It is single-use and is not stored in recoverable form. If you lose it,\n` +
35
- ` clear "${CLAIM_CODE_KEY}" from instance settings and restart to get a new one.\n`);
36
- }
37
- /**
38
- * True when nobody has claimed this instance yet and a code is waiting to be
39
- * used. Drives the sign-up form's claim-code field: without this the code has
40
- * nowhere to go but a hand-set cookie, which is not a flow anyone can follow.
41
- *
42
- * Deliberately narrow. It reveals only that an instance is unclaimed — never the
43
- * code or its hash — so it is safe to hand to an unauthenticated page. That fact
44
- * is already obvious to anyone who can reach a CMS with no users in it.
45
- */
46
- export async function isInstanceUnclaimed(db) {
47
- if (!(await isInstanceEmpty(db)))
48
- return false;
49
- const settings = await db.getInstanceSettings();
50
- return typeof settings[CLAIM_CODE_KEY] === 'string';
51
- }
52
- /**
53
- * The default. Keeps the familiar first-run wizard, but promotion requires a
54
- * code printed to the server log at startup — so arriving first isn't enough,
55
- * you also have to control the deployment. Same shape as Jupyter's `?token=`
56
- * and GitLab's generated root password.
57
- *
58
- * The code is single-use, but not mutually exclusive: it's cleared as its own
59
- * write rather than atomically with the profile insert. Two concurrent claims
60
- * can therefore both read the hash before either clears it, and a claim can be
61
- * spent by a request whose profile insert then fails.
62
- *
63
- * That's a deliberate trade. Wrapping both in one transaction holds SQLite's
64
- * single write lock across the auth provider's own concurrent user/session
65
- * inserts, which fails the whole sign-up with SQLITE_BUSY. Closing the race
66
- * properly needs a uniqueness constraint on "one super admin" at the database
67
- * level, not a longer lock. In practice every racer must already hold the code,
68
- * so the exposure is a duplicate admin, never an unauthorised one.
69
- */
70
- export function claimCode(options = {}) {
71
- /**
72
- * Header, `?claim=` query param, or an `aphex_bootstrap_code` cookie — in that
73
- * order. The profile is created on the first authenticated request after
74
- * sign-up, which may be a redirect the signup form doesn't control, so a
75
- * header alone would be unreachable from a plain HTML flow. Override
76
- * `readCode` if you want to accept it somewhere else.
77
- */
78
- const readCode = options.readCode ??
79
- ((request) => {
80
- if (!request)
81
- return undefined;
82
- const header = request.headers.get('x-aphex-bootstrap-code');
83
- if (header)
84
- return header;
85
- const fromQuery = new URL(request.url).searchParams.get('claim');
86
- if (fromQuery)
87
- return fromQuery;
88
- const cookie = request.headers.get('cookie');
89
- const raw = cookie?.match(/(?:^|;\s*)aphex_bootstrap_code=([^;]+)/)?.[1];
90
- // The sign-up form percent-encodes the value. A generated base64url code
91
- // has nothing to decode, but a custom one may.
92
- return raw === undefined ? undefined : decodeURIComponent(raw);
93
- });
94
- const policy = async ({ isFirstUser, request, db }) => {
95
- if (!isFirstUser)
96
- return null;
97
- const supplied = readCode(request)?.trim();
98
- if (!supplied)
99
- return null;
100
- const settings = await db.getInstanceSettings();
101
- const expected = settings[CLAIM_CODE_KEY];
102
- if (typeof expected !== 'string')
103
- return null;
104
- if (!digestsMatch(hashCode(supplied), expected)) {
105
- cmsLogger.warn('[Bootstrap]', 'Rejected claim attempt — code did not match');
106
- return null;
107
- }
108
- // Single-use: clearing the hash is what makes a second claimant lose.
109
- await db.updateInstanceSettings({ [CLAIM_CODE_KEY]: null });
110
- cmsLogger.info('[Bootstrap]', 'Instance claimed — super admin created');
111
- return 'super_admin';
112
- };
113
- // The code only exists because this recipe was chosen, so this recipe is what
114
- // generates it. Swapping to another recipe takes the startup step with it.
115
- policy.prepare = ensureClaimCode;
116
- return policy;
117
- }
118
- /**
119
- * First user whose address is on the allowlist becomes super admin — Discourse's
120
- * `DISCOURSE_DEVELOPER_EMAILS`. Good when you know the owner's address at deploy
121
- * time and would rather not read logs.
122
- *
123
- * This recipe is only as strong as the address is trustworthy, so pair it with
124
- * `requireEmailVerification`. That's enforced at the auth layer — better-auth
125
- * refuses to complete sign-in for an unconfirmed address, so an unverified user
126
- * never reaches profile creation at all. Re-checking it here would be dead code
127
- * when verification is on, and would brick a fresh install when it's off.
128
- */
129
- export function allowlistEmail(emails) {
130
- const allowed = new Set((typeof emails === 'string' ? emails.split(',') : (emails ?? []))
131
- .map((email) => email.trim().toLowerCase())
132
- .filter(Boolean));
133
- return async ({ isFirstUser, user }) => {
134
- if (!isFirstUser || allowed.size === 0)
135
- return null;
136
- if (!allowed.has(user.email.trim().toLowerCase()))
137
- return null;
138
- if (!user.emailVerified) {
139
- // Advice, not enforcement — the decision belongs to the auth layer.
140
- cmsLogger.warn('[Bootstrap]', `Promoting ${user.email} on an unverified address. Set ` +
141
- `AUTH_REQUIRE_EMAIL_VERIFICATION=true so the address has to be proven.`);
142
- }
143
- return 'super_admin';
144
- };
145
- }
146
- /**
147
- * Whoever signs up first becomes super admin, with nothing else required.
148
- *
149
- * This is what WordPress, Ghost, Strapi and Payload do, and it's fine when you
150
- * install immediately after deploying. It is **not** fine for an instance that
151
- * sits reachable before anyone signs in: the first stranger to find the URL owns
152
- * it. Opt in deliberately.
153
- */
154
- export function openFirstUser() {
155
- return async ({ isFirstUser }) => (isFirstUser ? 'super_admin' : null);
156
- }
157
- /**
158
- * Never promote anyone. Provision the first administrator out of band — a seed
159
- * script, a migration, or a direct row — the way Directus and Keycloak do.
160
- */
161
- export function never() {
162
- return async () => null;
163
- }
164
- //# sourceMappingURL=bootstrap.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAwB,MAAM,2BAA2B,CAAC;AAKlF,yEAAyE;AACzE,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAqChD,SAAS,QAAQ,CAAC,IAAY;IAC7B,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACxD,CAAC;AAED,gEAAgE;AAChE,SAAS,YAAY,CAAC,CAAS,EAAE,CAAS;IACzC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACnC,MAAM,KAAK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