@dbsc-toolkit/better-auth 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 +202 -0
- package/README.md +168 -0
- package/dist/adapter.d.ts +71 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +213 -0
- package/dist/adapter.js.map +1 -0
- package/dist/client.d.ts +43 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +53 -0
- package/dist/client.js.map +1 -0
- package/dist/express.d.ts +65 -0
- package/dist/express.d.ts.map +1 -0
- package/dist/express.js +124 -0
- package/dist/express.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +138 -0
- package/dist/index.js.map +1 -0
- package/dist/init-script.d.ts +18 -0
- package/dist/init-script.d.ts.map +1 -0
- package/dist/init-script.js +35 -0
- package/dist/init-script.js.map +1 -0
- package/dist/internal.d.ts +8 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +7 -0
- package/dist/internal.js.map +1 -0
- package/dist/schema.d.ts +69 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +67 -0
- package/dist/schema.js.map +1 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Suliman Abdulrazzaq
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# @dbsc-toolkit/better-auth
|
|
2
|
+
|
|
3
|
+
Device Bound Session Credentials (DBSC) for [Better Auth](https://better-auth.com), powered by [dbsc-toolkit](https://github.com/SulimanAbdulrazzaq/dbsc-toolkit).
|
|
4
|
+
|
|
5
|
+
On Chromium 145+ (Chrome, Edge, Brave, Opera, Arc), sessions are bound to a hardware key in the TPM or Secure Enclave. Stolen cookies cannot be replayed — the refresh requires a signature from the device's private key. On Firefox, Safari, and older Chromium, the same protection is provided via a non-extractable Web Crypto key stored in IndexedDB.
|
|
6
|
+
|
|
7
|
+
**Live demo:** [dbsc-better-auth-demo.onrender.com](https://dbsc-better-auth-demo.onrender.com)
|
|
8
|
+
|
|
9
|
+
## Setup (Express)
|
|
10
|
+
|
|
11
|
+
### 1. Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @dbsc-toolkit/better-auth dbsc-toolkit
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`better-auth` and `express` are peer deps — already in your project.
|
|
18
|
+
|
|
19
|
+
### 2. Add the plugin to Better Auth
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
// auth.ts
|
|
23
|
+
import { betterAuth } from "better-auth"
|
|
24
|
+
import { dbsc } from "@dbsc-toolkit/better-auth"
|
|
25
|
+
|
|
26
|
+
export const auth = betterAuth({
|
|
27
|
+
database: db,
|
|
28
|
+
emailAndPassword: { enabled: true },
|
|
29
|
+
plugins: [dbsc()], // ← add this
|
|
30
|
+
})
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Run migrations to create the `dbscSession` + `dbscBoundKey` tables:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
npx @better-auth/cli migrate
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 3. Wire the Express adapter
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
// server.ts
|
|
43
|
+
import express from "express"
|
|
44
|
+
import { toNodeHandler } from "better-auth/node"
|
|
45
|
+
import { dbscExpress } from "@dbsc-toolkit/better-auth/express"
|
|
46
|
+
import { auth } from "./auth.js"
|
|
47
|
+
|
|
48
|
+
const app = express()
|
|
49
|
+
|
|
50
|
+
// DBSC routes BEFORE Better Auth's catch-all (toNodeHandler swallows /api/auth/*).
|
|
51
|
+
const dbsc = dbscExpress(auth)
|
|
52
|
+
dbsc.install(app)
|
|
53
|
+
|
|
54
|
+
app.all("/api/auth/*splat", toNodeHandler(auth))
|
|
55
|
+
app.use(express.json())
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
That's the whole server setup. `dbsc.install(app)` mounts:
|
|
59
|
+
|
|
60
|
+
- `POST /api/auth/dbsc/registration` + `POST /api/auth/dbsc/refresh` — native TPM flow
|
|
61
|
+
- `GET /api/auth/dbsc-bound/*` — polyfill flow for Firefox / Safari / older Chromium
|
|
62
|
+
- `GET /dbsc-client/*` — the browser SDK and the auto-init shim
|
|
63
|
+
|
|
64
|
+
### 4. Guard routes that need per-request proof
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
app.get("/profile", dbsc.requireProof(), async (req, res) => {
|
|
68
|
+
const session = await auth.api.getSession({ headers: new Headers(req.headers) })
|
|
69
|
+
if (!session) return res.status(401).end()
|
|
70
|
+
res.json({ email: session.user.email })
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 5. One line on the frontend
|
|
75
|
+
|
|
76
|
+
```html
|
|
77
|
+
<script src="/dbsc-client/init.js" type="module"></script>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The shim auto-points the polyfill SDK at the right paths and exposes:
|
|
81
|
+
|
|
82
|
+
- `window.boundFetch` — `fetch` that signs the request with the polyfill key
|
|
83
|
+
- `window.initDbsc()` — re-runs the SDK so it observes a newly issued session
|
|
84
|
+
- `window.clearBoundKey()` — wipes the IndexedDB polyfill key on sign-out
|
|
85
|
+
|
|
86
|
+
Use `boundFetch` on calls to any guarded route:
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
const r = await boundFetch("/profile", { credentials: "include" })
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**One catch**: the shim probes `/dbsc-bound/state` once on page load. A
|
|
93
|
+
logged-out visitor resolves to `unbound` and the SDK returns without storing a
|
|
94
|
+
polyfill key. Call `window.initDbsc()` after a fresh sign-in / sign-up so the
|
|
95
|
+
SDK observes the session Better Auth just issued:
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
const r = await fetch("/api/auth/sign-in/email", { … })
|
|
99
|
+
if (r.ok) await window.initDbsc()
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Skipping this leaves `boundFetch` short-circuiting to plain `fetch` without the
|
|
103
|
+
proof header — guarded routes return 403.
|
|
104
|
+
|
|
105
|
+
Total user changes: **2 imports, 3 lines of server code, 1 script tag, 1
|
|
106
|
+
`initDbsc()` call after sign-in.**
|
|
107
|
+
|
|
108
|
+
## How the flow runs
|
|
109
|
+
|
|
110
|
+
1. User signs in → the `dbsc()` plugin's after-hook fires `Secure-Session-Registration` + three cookies
|
|
111
|
+
2. Chromium 145+ signs the challenge with its TPM key and POSTs to `/api/auth/dbsc/registration`
|
|
112
|
+
3. The Express adapter verifies, stores the public JWK, flips `tier` to `"dbsc"`
|
|
113
|
+
4. The init shim's `initBoundDbsc()` polls `/api/auth/dbsc-bound/state` and co-registers a Web Crypto key (so per-request proofs work everywhere)
|
|
114
|
+
5. `boundFetch` signs every guarded request; `requireProof()` rejects unsigned or replayed requests
|
|
115
|
+
|
|
116
|
+
The private key never leaves the device. A stolen `__Host-dbsc-session` cookie is useless without it.
|
|
117
|
+
|
|
118
|
+
## Options
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
// In auth.ts
|
|
122
|
+
dbsc({
|
|
123
|
+
basePath: "/api/auth", // must match the basePath you give Better Auth
|
|
124
|
+
cookieScope: "host", // "host" (__Host-) or "site" (__Secure- + Domain)
|
|
125
|
+
cookieDomain: "example.com", // required when cookieScope is "site"
|
|
126
|
+
sessionTtl: 600_000, // bound cookie TTL in ms (default 10 min)
|
|
127
|
+
onEvent: (e) => log(e), // telemetry for registration / refresh / failures
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
// In server.ts
|
|
131
|
+
dbscExpress(auth, {
|
|
132
|
+
basePath: "/api/auth", // match dbsc({ basePath })
|
|
133
|
+
secure: true, // set false on bare-http localhost
|
|
134
|
+
clientPath: "/dbsc-client", // SDK mount; false to skip
|
|
135
|
+
replayCache: new RedisReplayCache(redis), // optional, for requireProof()
|
|
136
|
+
})
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Database tables
|
|
140
|
+
|
|
141
|
+
The plugin adds two tables via Better Auth's `schema` field:
|
|
142
|
+
|
|
143
|
+
| Table | Purpose |
|
|
144
|
+
|---|---|
|
|
145
|
+
| `dbscSession` | Tracks binding state (`tier`, `lastRefreshAt`) per session |
|
|
146
|
+
| `dbscBoundKey` | Stores the public JWK for native (TPM) and polyfill (IndexedDB) keys |
|
|
147
|
+
|
|
148
|
+
Challenges live in Better Auth's existing `verification` table — `consumeVerificationValue` is its atomic primitive, which is what the storage adapter uses for replay-safe consume.
|
|
149
|
+
|
|
150
|
+
## Tier model
|
|
151
|
+
|
|
152
|
+
| Tier | Meaning |
|
|
153
|
+
|---|---|
|
|
154
|
+
| `"dbsc"` | TPM/Secure Enclave bound — Chromium 145+ |
|
|
155
|
+
| `"bound"` | Web Crypto polyfill — Firefox, Safari, older Chromium |
|
|
156
|
+
| `"none"` | Session created but registration not complete (transient) |
|
|
157
|
+
|
|
158
|
+
## Subpath exports
|
|
159
|
+
|
|
160
|
+
| Import | When you need it |
|
|
161
|
+
|---|---|
|
|
162
|
+
| `@dbsc-toolkit/better-auth` | The `dbsc()` plugin for `betterAuth({ plugins })` |
|
|
163
|
+
| `@dbsc-toolkit/better-auth/express` | The `dbscExpress(auth)` kit for Express apps |
|
|
164
|
+
| `@dbsc-toolkit/better-auth/internal` | `createBetterAuthStorageAdapter` for advanced framework wiring |
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
Apache-2.0 — same as dbsc-toolkit.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridges Better Auth's adapters to dbsc-toolkit's StorageAdapter interface.
|
|
3
|
+
*
|
|
4
|
+
* Uses Better Auth's own DB (SQLite/Postgres/MySQL) — no second connection required.
|
|
5
|
+
* - DB CRUD (sessions, bound keys) goes through the low-level `adapter`
|
|
6
|
+
* - Challenges go through `internalAdapter.createVerificationValue` /
|
|
7
|
+
* `consumeVerificationValue` for atomic single-use consume.
|
|
8
|
+
*/
|
|
9
|
+
import type { StorageAdapter } from "dbsc-toolkit";
|
|
10
|
+
export interface BetterAuthDbAdapter {
|
|
11
|
+
create<T extends Record<string, unknown>>(data: {
|
|
12
|
+
model: string;
|
|
13
|
+
data: T;
|
|
14
|
+
}): Promise<T>;
|
|
15
|
+
findOne<T extends Record<string, unknown>>(data: {
|
|
16
|
+
model: string;
|
|
17
|
+
where: Array<{
|
|
18
|
+
field: string;
|
|
19
|
+
value: unknown;
|
|
20
|
+
operator?: string;
|
|
21
|
+
}>;
|
|
22
|
+
}): Promise<T | null>;
|
|
23
|
+
findMany<T extends Record<string, unknown>>(data: {
|
|
24
|
+
model: string;
|
|
25
|
+
where?: Array<{
|
|
26
|
+
field: string;
|
|
27
|
+
value: unknown;
|
|
28
|
+
operator?: string;
|
|
29
|
+
}>;
|
|
30
|
+
}): Promise<T[]>;
|
|
31
|
+
update<T extends Record<string, unknown>>(data: {
|
|
32
|
+
model: string;
|
|
33
|
+
where: Array<{
|
|
34
|
+
field: string;
|
|
35
|
+
value: unknown;
|
|
36
|
+
}>;
|
|
37
|
+
update: Partial<T>;
|
|
38
|
+
}): Promise<T | null>;
|
|
39
|
+
delete(data: {
|
|
40
|
+
model: string;
|
|
41
|
+
where: Array<{
|
|
42
|
+
field: string;
|
|
43
|
+
value: unknown;
|
|
44
|
+
}>;
|
|
45
|
+
}): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
export interface BetterAuthInternalAdapter {
|
|
48
|
+
createVerificationValue(data: {
|
|
49
|
+
value: string;
|
|
50
|
+
identifier: string;
|
|
51
|
+
expiresAt: Date;
|
|
52
|
+
}): Promise<{
|
|
53
|
+
id: string;
|
|
54
|
+
value: string;
|
|
55
|
+
identifier: string;
|
|
56
|
+
expiresAt: Date;
|
|
57
|
+
}>;
|
|
58
|
+
consumeVerificationValue?(identifier: string): Promise<{
|
|
59
|
+
id: string;
|
|
60
|
+
value: string;
|
|
61
|
+
} | null>;
|
|
62
|
+
findVerificationValue(identifier: string): Promise<{
|
|
63
|
+
id: string;
|
|
64
|
+
value: string;
|
|
65
|
+
identifier: string;
|
|
66
|
+
expiresAt: Date;
|
|
67
|
+
} | null>;
|
|
68
|
+
deleteVerificationValue?(id: string): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
export declare function createBetterAuthStorageAdapter(db: BetterAuthDbAdapter, internalAdapter: BetterAuthInternalAdapter): StorageAdapter;
|
|
71
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,cAAc,EAA8C,MAAM,cAAc,CAAC;AAE/F,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACxF,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE;QAC/C,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,KAAK,CAAC;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,OAAO,CAAC;YAAC,QAAQ,CAAC,EAAE,MAAM,C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C,CAAC;IAChF,wBAAwB,CAAC,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;IAC7F,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;QACjD,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,IAAI,CAAC;KACjB,GAAG,IAAI,CAAC,CAAC;IACV,uBAAuB,CAAC,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrD;AAQD,wBAAgB,8BAA8B,CAC5C,EAAE,EAAE,mBAAmB,EACvB,eAAe,EAAE,yBAAyB,GACzC,cAAc,CAoKhB"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
const CHALLENGE_PREFIX = "dbsc-challenge:";
|
|
2
|
+
function challengeIdentifier(jti) {
|
|
3
|
+
return `${CHALLENGE_PREFIX}${jti}`;
|
|
4
|
+
}
|
|
5
|
+
export function createBetterAuthStorageAdapter(db, internalAdapter) {
|
|
6
|
+
return {
|
|
7
|
+
async getSession(id) {
|
|
8
|
+
const row = await db.findOne({
|
|
9
|
+
model: "dbscSession",
|
|
10
|
+
where: [{ field: "id", value: id }],
|
|
11
|
+
});
|
|
12
|
+
return row ? rowToSession(row) : null;
|
|
13
|
+
},
|
|
14
|
+
async setSession(session) {
|
|
15
|
+
const existing = await db.findOne({
|
|
16
|
+
model: "dbscSession",
|
|
17
|
+
where: [{ field: "id", value: session.id }],
|
|
18
|
+
});
|
|
19
|
+
if (existing) {
|
|
20
|
+
await db.update({
|
|
21
|
+
model: "dbscSession",
|
|
22
|
+
where: [{ field: "id", value: session.id }],
|
|
23
|
+
update: sessionToRow(session),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// Pass id with forceAllowId — Kysely adapter warns otherwise.
|
|
28
|
+
// dbscSession.id is the Better Auth session id (canonical key).
|
|
29
|
+
await db.create({
|
|
30
|
+
model: "dbscSession",
|
|
31
|
+
data: { id: session.id, ...sessionToRow(session) },
|
|
32
|
+
forceAllowId: true,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
async deleteSession(id) {
|
|
37
|
+
await db.delete({
|
|
38
|
+
model: "dbscSession",
|
|
39
|
+
where: [{ field: "id", value: id }],
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
async getBoundKey(sessionId, kind) {
|
|
43
|
+
if (kind) {
|
|
44
|
+
const row = await db.findOne({
|
|
45
|
+
model: "dbscBoundKey",
|
|
46
|
+
where: [
|
|
47
|
+
{ field: "sessionId", value: sessionId },
|
|
48
|
+
{ field: "kind", value: kind },
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
return row ? rowToBoundKey(row) : null;
|
|
52
|
+
}
|
|
53
|
+
const nativeRow = await db.findOne({
|
|
54
|
+
model: "dbscBoundKey",
|
|
55
|
+
where: [
|
|
56
|
+
{ field: "sessionId", value: sessionId },
|
|
57
|
+
{ field: "kind", value: "native" },
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
if (nativeRow)
|
|
61
|
+
return rowToBoundKey(nativeRow);
|
|
62
|
+
const boundRow = await db.findOne({
|
|
63
|
+
model: "dbscBoundKey",
|
|
64
|
+
where: [
|
|
65
|
+
{ field: "sessionId", value: sessionId },
|
|
66
|
+
{ field: "kind", value: "bound" },
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
return boundRow ? rowToBoundKey(boundRow) : null;
|
|
70
|
+
},
|
|
71
|
+
async setBoundKey(key) {
|
|
72
|
+
const existing = await db.findOne({
|
|
73
|
+
model: "dbscBoundKey",
|
|
74
|
+
where: [
|
|
75
|
+
{ field: "sessionId", value: key.sessionId },
|
|
76
|
+
{ field: "kind", value: key.kind },
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
const data = boundKeyToRow(key);
|
|
80
|
+
if (existing) {
|
|
81
|
+
await db.update({
|
|
82
|
+
model: "dbscBoundKey",
|
|
83
|
+
where: [
|
|
84
|
+
{ field: "sessionId", value: key.sessionId },
|
|
85
|
+
{ field: "kind", value: key.kind },
|
|
86
|
+
],
|
|
87
|
+
update: data,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
await db.create({ model: "dbscBoundKey", data });
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
async deleteBoundKey(sessionId, kind) {
|
|
95
|
+
if (kind) {
|
|
96
|
+
await db.delete({
|
|
97
|
+
model: "dbscBoundKey",
|
|
98
|
+
where: [
|
|
99
|
+
{ field: "sessionId", value: sessionId },
|
|
100
|
+
{ field: "kind", value: kind },
|
|
101
|
+
],
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
await db.delete({
|
|
106
|
+
model: "dbscBoundKey",
|
|
107
|
+
where: [{ field: "sessionId", value: sessionId }],
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
async getChallenge(jti) {
|
|
112
|
+
const row = await internalAdapter.findVerificationValue(challengeIdentifier(jti));
|
|
113
|
+
if (!row)
|
|
114
|
+
return null;
|
|
115
|
+
return verificationRowToChallenge(jti, row);
|
|
116
|
+
},
|
|
117
|
+
async setChallenge(challenge) {
|
|
118
|
+
await internalAdapter.createVerificationValue({
|
|
119
|
+
identifier: challengeIdentifier(challenge.jti),
|
|
120
|
+
value: JSON.stringify({ sessionId: challenge.sessionId, consumed: challenge.consumed }),
|
|
121
|
+
expiresAt: new Date(challenge.expiresAt),
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
async consumeChallenge(jti) {
|
|
125
|
+
if (internalAdapter.consumeVerificationValue) {
|
|
126
|
+
const result = await internalAdapter.consumeVerificationValue(challengeIdentifier(jti));
|
|
127
|
+
return result !== null;
|
|
128
|
+
}
|
|
129
|
+
// Fallback: find + delete (less safe under concurrent requests, but functional)
|
|
130
|
+
const row = await internalAdapter.findVerificationValue(challengeIdentifier(jti));
|
|
131
|
+
if (!row)
|
|
132
|
+
return false;
|
|
133
|
+
if (internalAdapter.deleteVerificationValue) {
|
|
134
|
+
await internalAdapter.deleteVerificationValue(row.id);
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
137
|
+
},
|
|
138
|
+
async revokeSession(sessionId) {
|
|
139
|
+
await db.delete({
|
|
140
|
+
model: "dbscBoundKey",
|
|
141
|
+
where: [{ field: "sessionId", value: sessionId }],
|
|
142
|
+
});
|
|
143
|
+
await db.delete({
|
|
144
|
+
model: "dbscSession",
|
|
145
|
+
where: [{ field: "id", value: sessionId }],
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
async revokeAllForUser(userId) {
|
|
149
|
+
const sessions = await db.findMany({
|
|
150
|
+
model: "dbscSession",
|
|
151
|
+
where: [{ field: "userId", value: userId }],
|
|
152
|
+
});
|
|
153
|
+
for (const sess of sessions) {
|
|
154
|
+
await db.delete({
|
|
155
|
+
model: "dbscBoundKey",
|
|
156
|
+
where: [{ field: "sessionId", value: sess["id"] }],
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
await db.delete({
|
|
160
|
+
model: "dbscSession",
|
|
161
|
+
where: [{ field: "userId", value: userId }],
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function rowToSession(row) {
|
|
167
|
+
return {
|
|
168
|
+
id: String(row["id"]),
|
|
169
|
+
userId: String(row["userId"]),
|
|
170
|
+
tier: String(row["tier"]),
|
|
171
|
+
createdAt: Number(row["createdAt"]),
|
|
172
|
+
expiresAt: Number(row["expiresAt"]),
|
|
173
|
+
lastRefreshAt: Number(row["lastRefreshAt"]),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function sessionToRow(s) {
|
|
177
|
+
return {
|
|
178
|
+
userId: s.userId,
|
|
179
|
+
tier: s.tier,
|
|
180
|
+
createdAt: s.createdAt,
|
|
181
|
+
expiresAt: s.expiresAt,
|
|
182
|
+
lastRefreshAt: s.lastRefreshAt,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function rowToBoundKey(row) {
|
|
186
|
+
return {
|
|
187
|
+
sessionId: String(row["sessionId"]),
|
|
188
|
+
kind: String(row["kind"]),
|
|
189
|
+
jwk: JSON.parse(String(row["jwk"])),
|
|
190
|
+
createdAt: Number(row["createdAt"]),
|
|
191
|
+
algorithm: String(row["algorithm"]),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function boundKeyToRow(k) {
|
|
195
|
+
return {
|
|
196
|
+
sessionId: k.sessionId,
|
|
197
|
+
kind: k.kind,
|
|
198
|
+
jwk: JSON.stringify(k.jwk),
|
|
199
|
+
createdAt: k.createdAt,
|
|
200
|
+
algorithm: k.algorithm,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function verificationRowToChallenge(jti, row) {
|
|
204
|
+
const parsed = JSON.parse(row.value);
|
|
205
|
+
return {
|
|
206
|
+
jti,
|
|
207
|
+
sessionId: parsed.sessionId,
|
|
208
|
+
consumed: parsed.consumed,
|
|
209
|
+
createdAt: 0,
|
|
210
|
+
expiresAt: row.expiresAt.getTime(),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AA+CA,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAE3C,SAAS,mBAAmB,CAAC,GAAW;IACtC,OAAO,GAAG,gBAAgB,GAAG,GAAG,EAAE,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,8BAA8B,CAC5C,EAAuB,EACvB,eAA0C;IAE1C,OAAO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