@dads-framework/identity-better-auth 0.0.0-stage → 0.1.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.md +21 -0
- package/README.md +82 -2
- package/dist/identity-better-auth.tsbuildinfo +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/account-invitations.d.ts +7 -0
- package/dist/lib/account-invitations.d.ts.map +1 -0
- package/dist/lib/account-invitations.js +46 -0
- package/dist/lib/account-invitations.js.map +1 -0
- package/dist/lib/configure-better-auth.d.ts +288 -0
- package/dist/lib/configure-better-auth.d.ts.map +1 -0
- package/dist/lib/configure-better-auth.js +67 -0
- package/dist/lib/configure-better-auth.js.map +1 -0
- package/dist/lib/create-better-auth-identity.d.ts +5 -0
- package/dist/lib/create-better-auth-identity.d.ts.map +1 -0
- package/dist/lib/create-better-auth-identity.js +31 -0
- package/dist/lib/create-better-auth-identity.js.map +1 -0
- package/dist/lib/identity-email.d.ts +4 -0
- package/dist/lib/identity-email.d.ts.map +1 -0
- package/dist/lib/identity-email.js +15 -0
- package/dist/lib/identity-email.js.map +1 -0
- package/dist/lib/identity-handler.d.ts +8 -0
- package/dist/lib/identity-handler.d.ts.map +1 -0
- package/dist/lib/identity-handler.js +82 -0
- package/dist/lib/identity-handler.js.map +1 -0
- package/dist/lib/identity-options.d.ts +15 -0
- package/dist/lib/identity-options.d.ts.map +1 -0
- package/dist/lib/identity-options.js +17 -0
- package/dist/lib/identity-options.js.map +1 -0
- package/dist/lib/migrations/20261120070500_identity.migration.d.ts +5 -0
- package/dist/lib/migrations/20261120070500_identity.migration.d.ts.map +1 -0
- package/dist/lib/migrations/20261120070500_identity.migration.js +81 -0
- package/dist/lib/migrations/20261120070500_identity.migration.js.map +1 -0
- package/package.json +43 -4
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bryton Cooper
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,83 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dads-framework/identity-better-auth
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Binds the Dads identity contract to Better Auth and PostgreSQL for email and password sign-in.
|
|
4
|
+
|
|
5
|
+
## Try it
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { createBetterAuthIdentity } from "@dads-framework/identity-better-auth";
|
|
9
|
+
|
|
10
|
+
const identity = createBetterAuthIdentity({
|
|
11
|
+
database: postgres,
|
|
12
|
+
baseUrl: environment.appOrigin,
|
|
13
|
+
secret: environment.identitySecret,
|
|
14
|
+
enqueueEmail: mailQueue.enqueueIdentityEmail,
|
|
15
|
+
canInvite: accountPolicy.canInvite,
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Use it
|
|
20
|
+
|
|
21
|
+
Apply the migration with the Dads migration runner. It discovers
|
|
22
|
+
`20261120070500_identity.migration.ts` for this repository. An adopter can
|
|
23
|
+
call `installIdentitySchemaV1` from its own migration via the package's
|
|
24
|
+
public export. Mount `identity.handle` under `IDENTITY_PATH` (`/api/auth`)
|
|
25
|
+
and pass through the original browser request and response headers,
|
|
26
|
+
including each `Set-Cookie` header. Replace client-supplied forwarding
|
|
27
|
+
headers at the trusted ingress before invoking the handler. Better Auth
|
|
28
|
+
uses the resulting client address for request limits. An application
|
|
29
|
+
with multiple instances can also enforce shared limits at its ingress.
|
|
30
|
+
|
|
31
|
+
Use `identity.readSession(request.headers)` to authenticate with the session
|
|
32
|
+
cookie. Cookies are host-only, HTTP-only, and secure on HTTPS. The database
|
|
33
|
+
is checked on each lookup. Sessions expire seven days after sign-in and
|
|
34
|
+
sign-out revokes the current session.
|
|
35
|
+
|
|
36
|
+
From the same origin, use the following paths relative to `/api/auth`.
|
|
37
|
+
|
|
38
|
+
| Method | Path | Input and effect |
|
|
39
|
+
| ------ | ------------------------- | -------------------------------------------------------------------------------------- |
|
|
40
|
+
| POST | `/sign-up/email` | `name`, `email`, `password`. Requests email verification with a uniform success body. |
|
|
41
|
+
| GET | `/verify-email` | The verification URL delivered to the account owner. |
|
|
42
|
+
| POST | `/sign-in/email` | `email`, `password`. Sets a session cookie for a verified account. |
|
|
43
|
+
| POST | `/sign-out` | Revokes the cookie's session. |
|
|
44
|
+
| GET | `/get-session` | Returns the safe account and its expiration, or `null`. |
|
|
45
|
+
| POST | `/request-password-reset` | `email`, same-origin `redirectTo`. Returns a generic acknowledgement. |
|
|
46
|
+
| POST | `/reset-password` | `token`, `newPassword`. Consumes the token and revokes existing sessions. |
|
|
47
|
+
| POST | `/invite` | `email`. Requires a verified session and an application policy permitting invitations. |
|
|
48
|
+
| POST | `/accept-invitation` | `token` from the link's fragment. Requires a verified session with the same email. |
|
|
49
|
+
| GET | `/token` | A five-minute JWT for an active cookie session. |
|
|
50
|
+
| GET | `/jwks` | Public verification keys. |
|
|
51
|
+
|
|
52
|
+
An invited recipient signs up and verifies their address first. The
|
|
53
|
+
application's `/accept-invitation` page reads the token fragment and submits
|
|
54
|
+
it to the identity endpoint. An account invitation grants no tenant role.
|
|
55
|
+
Tenant onboarding can instead use its own tenant invitation and map a
|
|
56
|
+
verified identity session to a tenant account.
|
|
57
|
+
|
|
58
|
+
Password reset links expire after 15 minutes, verification links after an
|
|
59
|
+
hour, and account invitations after 24 hours. A password reset is
|
|
60
|
+
single-use. Invite tokens are stored by digest, accepted atomically, and
|
|
61
|
+
cannot be redeemed with another account's email.
|
|
62
|
+
|
|
63
|
+
## What it refuses to do
|
|
64
|
+
|
|
65
|
+
The handler omits SSO, SCIM, administrative impersonation and provider
|
|
66
|
+
token endpoints. Reads return account identity without password or raw
|
|
67
|
+
session records. JWTs carry only the subject, session ID, and standard
|
|
68
|
+
issuer, audience, time and expiry claims. An offline verifier must check
|
|
69
|
+
signature, issuer, audience and expiry. A revoked cookie session cannot
|
|
70
|
+
mint new JWTs, and existing offline JWTs expire within five minutes.
|
|
71
|
+
|
|
72
|
+
## Contract
|
|
73
|
+
|
|
74
|
+
Use a bare HTTPS origin or a loopback HTTP origin and a secret of at least
|
|
75
|
+
32 characters from application configuration. The application owns the
|
|
76
|
+
database pool and its shutdown. Use a confidential mail queue. Mail is
|
|
77
|
+
enqueued without delaying reset or registration responses, and enqueue
|
|
78
|
+
failures can call `onEmailError` without exposing any address, secret, or
|
|
79
|
+
link. Keep request bodies and authentication query strings out of logs.
|
|
80
|
+
|
|
81
|
+
Denied invitation issuance returns `401` without a session and `403` for a
|
|
82
|
+
refused origin or account policy. A wrong, expired, or spent invitation
|
|
83
|
+
returns the same `400` response.
|