@aphexcms/auth 0.2.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 +76 -0
- package/package.json +4 -7
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aphexcms/auth",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -34,21 +34,18 @@
|
|
|
34
34
|
"files": [
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"@aphexcms/cms-core": "^9.9.0"
|
|
39
|
-
},
|
|
40
37
|
"peerDependencies": {
|
|
38
|
+
"@aphexcms/cms-core": ">=11.0.0",
|
|
41
39
|
"@better-auth/api-key": "^1.6.25",
|
|
42
40
|
"better-auth": "^1.6.25",
|
|
43
|
-
"drizzle-orm": "^0.45.2"
|
|
44
|
-
"@aphexcms/cms-core": "^9.9.0"
|
|
41
|
+
"drizzle-orm": "^0.45.2"
|
|
45
42
|
},
|
|
46
43
|
"devDependencies": {
|
|
47
44
|
"@better-auth/api-key": "^1.6.25",
|
|
48
45
|
"better-auth": "^1.6.25",
|
|
49
46
|
"drizzle-orm": "^0.45.2",
|
|
50
47
|
"typescript": "^5.9.3",
|
|
51
|
-
"@aphexcms/cms-core": "^
|
|
48
|
+
"@aphexcms/cms-core": "^11.0.0"
|
|
52
49
|
},
|
|
53
50
|
"scripts": {
|
|
54
51
|
"build": "tsc",
|