@auth/d1-adapter 0.8.0 → 1.0.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/README.md +1 -1
- package/index.d.ts +1 -55
- package/index.d.ts.map +1 -1
- package/index.js +1 -55
- package/migrations.d.ts +0 -1
- package/migrations.d.ts.map +1 -1
- package/migrations.js +0 -1
- package/package.json +2 -2
- package/src/index.ts +1 -55
- package/src/migrations.ts +0 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<br/>
|
|
3
3
|
<a href="https://authjs.dev" target="_blank">
|
|
4
|
-
<img height="64px" src="https://authjs.dev/img/logo
|
|
4
|
+
<img height="64px" src="https://authjs.dev/img/logo-sm.png" />
|
|
5
5
|
</a>
|
|
6
6
|
<a href="https://developers.cloudflare.com/d1/" target="_blank">
|
|
7
7
|
<img height="64px" src="https://authjs.dev/img/adapters/d1.svg"/>
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding:
|
|
2
|
+
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: "16px"}}>
|
|
3
3
|
* <p style={{fontWeight: "normal"}}>An official <a href="https://developers.cloudflare.com/d1/">Cloudflare D1</a> adapter for Auth.js / NextAuth.js.</p>
|
|
4
4
|
* <a href="https://developers.cloudflare.com/d1/">
|
|
5
5
|
* <img style={{display: "block"}} src="/img/adapters/d1.svg" width="48" />
|
|
@@ -49,59 +49,5 @@ export declare function createRecord<RecordType>(db: D1Database, CREATE_SQL: str
|
|
|
49
49
|
export declare function getRecord<RecordType>(db: D1Database, SQL: string, bindings: any[]): Promise<RecordType | null>;
|
|
50
50
|
export declare function updateRecord(db: D1Database, SQL: string, bindings: any[]): Promise<import("@miniflare/d1").D1Result<unknown> | import("@cloudflare/workers-types").D1Result<unknown>>;
|
|
51
51
|
export declare function deleteRecord(db: D1Database, SQL: string, bindings: any[]): Promise<void>;
|
|
52
|
-
/**
|
|
53
|
-
*
|
|
54
|
-
* ## Setup
|
|
55
|
-
*
|
|
56
|
-
* This is the D1 Adapter for [`next-auth`](https://authjs.dev). This package can only be used in conjunction with the primary `next-auth` package. It is not a standalone package.
|
|
57
|
-
*
|
|
58
|
-
* ### Configure Auth.js
|
|
59
|
-
*
|
|
60
|
-
* ```javascript title="pages/api/auth/[...nextauth].js"
|
|
61
|
-
* import NextAuth from "next-auth"
|
|
62
|
-
* import { D1Adapter, up } from "@auth/d1-adapter"
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* // For more information on each option (and a full list of options) go to
|
|
66
|
-
* // https://authjs.dev/reference/configuration/auth-options
|
|
67
|
-
* export default NextAuth({
|
|
68
|
-
* // https://authjs.dev/reference/providers/
|
|
69
|
-
* providers: [],
|
|
70
|
-
* adapter: D1Adapter(env.db)
|
|
71
|
-
* ...
|
|
72
|
-
* })
|
|
73
|
-
* ```
|
|
74
|
-
*
|
|
75
|
-
* ### Migrations
|
|
76
|
-
*
|
|
77
|
-
* Somewhere in the initialization of your application you need to run the `up(env.db)` function to create the tables in D1.
|
|
78
|
-
* It will create 4 tables if they don't already exist:
|
|
79
|
-
* `accounts`, `sessions`, `users`, `verification_tokens`.
|
|
80
|
-
*
|
|
81
|
-
* The table prefix "" is not configurable at this time.
|
|
82
|
-
*
|
|
83
|
-
* You can use something like the following to attempt the migration once each time your worker starts up. Running migrations more than once will not erase your existing tables.
|
|
84
|
-
* ```javascript
|
|
85
|
-
* import { up } from "@auth/d1-adapter"
|
|
86
|
-
*
|
|
87
|
-
* let migrated = false;
|
|
88
|
-
* async function migrationHandle({event, resolve}) {
|
|
89
|
-
* if(!migrated) {
|
|
90
|
-
* try {
|
|
91
|
-
* await up(event.platform.env.db)
|
|
92
|
-
* migrated = true
|
|
93
|
-
* } catch(e) {
|
|
94
|
-
* console.log(e.cause.message, e.message)
|
|
95
|
-
* }
|
|
96
|
-
* }
|
|
97
|
-
* return resolve(event)
|
|
98
|
-
* }
|
|
99
|
-
* ```
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* You can also initialize your tables manually. Look in [migrations.ts](https://github.com/nextauthjs/next-auth/blob/main/packages/adapter-d1/src/migrations.ts) for the relevant sql.
|
|
103
|
-
* Paste and execute the SQL from within your D1 database's console in the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers/d1).
|
|
104
|
-
*
|
|
105
|
-
**/
|
|
106
52
|
export declare function D1Adapter(db: D1Database): Adapter;
|
|
107
53
|
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC7E,OAAO,KAAK,EAAE,UAAU,IAAI,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACtE,OAAO,KAAK,EACV,OAAO,EAKR,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAA;AAEpC;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,mBAAmB,CAAA;AAI7D,eAAO,MAAM,eAAe,qFAAqF,CAAA;AACjH,eAAO,MAAM,kBAAkB,qCAAqC,CAAA;AACpE,eAAO,MAAM,qBAAqB,wCAAwC,CAAA;AAC1E,eAAO,MAAM,wBAAwB,0HAGc,CAAA;AACnD,eAAO,MAAM,qBAAqB,gGAGlB,CAAA;AAChB,eAAO,MAAM,eAAe,mCAAmC,CAAA;AAG/D,eAAO,MAAM,kBAAkB,8EAC8C,CAAA;AAC7E,eAAO,MAAM,wBAAwB,4FAGZ,CAAA;AACzB,eAAO,MAAM,mCAAmC,2DAA2D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CAAC,UAAU,GAAG,IAAI,CAAC,CAgB5B;AAED,wBAAsB,YAAY,CAChC,EAAE,EAAE,UAAU,EACd,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,GAAG,EAAE,8GAYhB;AAED,wBAAsB,YAAY,CAChC,EAAE,EAAE,UAAU,EACd,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,GAAG,EAAE,iBAahB;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,UAAU,GAAG,OAAO,CA0LjD"}
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding:
|
|
2
|
+
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: "16px"}}>
|
|
3
3
|
* <p style={{fontWeight: "normal"}}>An official <a href="https://developers.cloudflare.com/d1/">Cloudflare D1</a> adapter for Auth.js / NextAuth.js.</p>
|
|
4
4
|
* <a href="https://developers.cloudflare.com/d1/">
|
|
5
5
|
* <img style={{display: "block"}} src="/img/adapters/d1.svg" width="48" />
|
|
@@ -142,60 +142,6 @@ export async function deleteRecord(db, SQL, bindings) {
|
|
|
142
142
|
throw e;
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
|
-
/**
|
|
146
|
-
*
|
|
147
|
-
* ## Setup
|
|
148
|
-
*
|
|
149
|
-
* This is the D1 Adapter for [`next-auth`](https://authjs.dev). This package can only be used in conjunction with the primary `next-auth` package. It is not a standalone package.
|
|
150
|
-
*
|
|
151
|
-
* ### Configure Auth.js
|
|
152
|
-
*
|
|
153
|
-
* ```javascript title="pages/api/auth/[...nextauth].js"
|
|
154
|
-
* import NextAuth from "next-auth"
|
|
155
|
-
* import { D1Adapter, up } from "@auth/d1-adapter"
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* // For more information on each option (and a full list of options) go to
|
|
159
|
-
* // https://authjs.dev/reference/configuration/auth-options
|
|
160
|
-
* export default NextAuth({
|
|
161
|
-
* // https://authjs.dev/reference/providers/
|
|
162
|
-
* providers: [],
|
|
163
|
-
* adapter: D1Adapter(env.db)
|
|
164
|
-
* ...
|
|
165
|
-
* })
|
|
166
|
-
* ```
|
|
167
|
-
*
|
|
168
|
-
* ### Migrations
|
|
169
|
-
*
|
|
170
|
-
* Somewhere in the initialization of your application you need to run the `up(env.db)` function to create the tables in D1.
|
|
171
|
-
* It will create 4 tables if they don't already exist:
|
|
172
|
-
* `accounts`, `sessions`, `users`, `verification_tokens`.
|
|
173
|
-
*
|
|
174
|
-
* The table prefix "" is not configurable at this time.
|
|
175
|
-
*
|
|
176
|
-
* You can use something like the following to attempt the migration once each time your worker starts up. Running migrations more than once will not erase your existing tables.
|
|
177
|
-
* ```javascript
|
|
178
|
-
* import { up } from "@auth/d1-adapter"
|
|
179
|
-
*
|
|
180
|
-
* let migrated = false;
|
|
181
|
-
* async function migrationHandle({event, resolve}) {
|
|
182
|
-
* if(!migrated) {
|
|
183
|
-
* try {
|
|
184
|
-
* await up(event.platform.env.db)
|
|
185
|
-
* migrated = true
|
|
186
|
-
* } catch(e) {
|
|
187
|
-
* console.log(e.cause.message, e.message)
|
|
188
|
-
* }
|
|
189
|
-
* }
|
|
190
|
-
* return resolve(event)
|
|
191
|
-
* }
|
|
192
|
-
* ```
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* You can also initialize your tables manually. Look in [migrations.ts](https://github.com/nextauthjs/next-auth/blob/main/packages/adapter-d1/src/migrations.ts) for the relevant sql.
|
|
196
|
-
* Paste and execute the SQL from within your D1 database's console in the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers/d1).
|
|
197
|
-
*
|
|
198
|
-
**/
|
|
199
145
|
export function D1Adapter(db) {
|
|
200
146
|
// we need to run migrations if we dont have the right tables
|
|
201
147
|
return {
|
package/migrations.d.ts
CHANGED
package/migrations.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["src/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,GAAG,CAAA;AAEnC,eAAO,MAAM,eAAe,UAuC3B,CAAA;AAED,eAAO,MAAM,IAAI,UAKhB,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["src/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,GAAG,CAAA;AAEnC,eAAO,MAAM,eAAe,UAuC3B,CAAA;AAED,eAAO,MAAM,IAAI,UAKhB,CAAA;AAED;;GAEG;AACH,iBAAe,EAAE,CAAC,EAAE,EAAE,UAAU,iBAS/B;AAED,OAAO,EAAE,EAAE,EAAE,CAAA"}
|
package/migrations.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auth/d1-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "A Cloudflare D1 adapter for Auth.js",
|
|
5
5
|
"homepage": "https://authjs.dev",
|
|
6
6
|
"repository": "https://github.com/nextauthjs/next-auth",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@auth/core": "0.
|
|
41
|
+
"@auth/core": "0.30.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@cloudflare/workers-types": "^4.20230321.0",
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding:
|
|
2
|
+
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: "16px"}}>
|
|
3
3
|
* <p style={{fontWeight: "normal"}}>An official <a href="https://developers.cloudflare.com/d1/">Cloudflare D1</a> adapter for Auth.js / NextAuth.js.</p>
|
|
4
4
|
* <a href="https://developers.cloudflare.com/d1/">
|
|
5
5
|
* <img style={{display: "block"}} src="/img/adapters/d1.svg" width="48" />
|
|
@@ -189,60 +189,6 @@ export async function deleteRecord(
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
/**
|
|
193
|
-
*
|
|
194
|
-
* ## Setup
|
|
195
|
-
*
|
|
196
|
-
* This is the D1 Adapter for [`next-auth`](https://authjs.dev). This package can only be used in conjunction with the primary `next-auth` package. It is not a standalone package.
|
|
197
|
-
*
|
|
198
|
-
* ### Configure Auth.js
|
|
199
|
-
*
|
|
200
|
-
* ```javascript title="pages/api/auth/[...nextauth].js"
|
|
201
|
-
* import NextAuth from "next-auth"
|
|
202
|
-
* import { D1Adapter, up } from "@auth/d1-adapter"
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* // For more information on each option (and a full list of options) go to
|
|
206
|
-
* // https://authjs.dev/reference/configuration/auth-options
|
|
207
|
-
* export default NextAuth({
|
|
208
|
-
* // https://authjs.dev/reference/providers/
|
|
209
|
-
* providers: [],
|
|
210
|
-
* adapter: D1Adapter(env.db)
|
|
211
|
-
* ...
|
|
212
|
-
* })
|
|
213
|
-
* ```
|
|
214
|
-
*
|
|
215
|
-
* ### Migrations
|
|
216
|
-
*
|
|
217
|
-
* Somewhere in the initialization of your application you need to run the `up(env.db)` function to create the tables in D1.
|
|
218
|
-
* It will create 4 tables if they don't already exist:
|
|
219
|
-
* `accounts`, `sessions`, `users`, `verification_tokens`.
|
|
220
|
-
*
|
|
221
|
-
* The table prefix "" is not configurable at this time.
|
|
222
|
-
*
|
|
223
|
-
* You can use something like the following to attempt the migration once each time your worker starts up. Running migrations more than once will not erase your existing tables.
|
|
224
|
-
* ```javascript
|
|
225
|
-
* import { up } from "@auth/d1-adapter"
|
|
226
|
-
*
|
|
227
|
-
* let migrated = false;
|
|
228
|
-
* async function migrationHandle({event, resolve}) {
|
|
229
|
-
* if(!migrated) {
|
|
230
|
-
* try {
|
|
231
|
-
* await up(event.platform.env.db)
|
|
232
|
-
* migrated = true
|
|
233
|
-
* } catch(e) {
|
|
234
|
-
* console.log(e.cause.message, e.message)
|
|
235
|
-
* }
|
|
236
|
-
* }
|
|
237
|
-
* return resolve(event)
|
|
238
|
-
* }
|
|
239
|
-
* ```
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
* You can also initialize your tables manually. Look in [migrations.ts](https://github.com/nextauthjs/next-auth/blob/main/packages/adapter-d1/src/migrations.ts) for the relevant sql.
|
|
243
|
-
* Paste and execute the SQL from within your D1 database's console in the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers/d1).
|
|
244
|
-
*
|
|
245
|
-
**/
|
|
246
192
|
export function D1Adapter(db: D1Database): Adapter {
|
|
247
193
|
// we need to run migrations if we dont have the right tables
|
|
248
194
|
|