@auth/edgedb-adapter 0.8.0 → 1.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/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/logo-sm.png" />
4
+ <img height="64px" src="https://authjs.dev/img/logo-sm.png" />
5
5
  </a>
6
6
  <a href="https://www.edgedb.com/" target="_blank">
7
7
  <img height="64px" src="https://authjs.dev/img/adapters/edgedb.svg"/>
@@ -18,7 +18,7 @@
18
18
  <img src="https://img.shields.io/npm/dm/@auth/edgedb-adapter?label=%20downloads&style=flat-square" alt="Downloads" />
19
19
  </a>
20
20
  <a href="https://github.com/nextauthjs/next-auth/stargazers">
21
- <img src="https://img.shields.io/github/stars/nextauthjs/next-auth?style=flat-square" alt="Github Stars" />
21
+ <img src="https://img.shields.io/github/stars/nextauthjs/next-auth?style=flat-square" alt="GitHub Stars" />
22
22
  </a>
23
23
  </p>
24
24
  </p>
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: 16}}>
3
- * <p style={{fontWeight: "normal"}}>Official <a href="https://www.edgedb.com/">Edge DB</a> adapter for Auth.js / NextAuth.js.</p>
2
+ * <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: "16px"}}>
3
+ * <p>Official <a href="https://www.edgedb.com/">Edge DB</a> adapter for Auth.js / NextAuth.js.</p>
4
4
  * <a href="https://www.edgedb.com/">
5
5
  * <img style={{display: "block"}} src="/img/adapters/edgedb.svg" width="38" />
6
6
  * </a>
@@ -17,270 +17,5 @@
17
17
  */
18
18
  import type { Adapter } from "@auth/core/adapters";
19
19
  import type { Client } from "edgedb";
20
- /**
21
- *
22
- * To use this Adapter, you need to install `edgedb`, `@edgedb/generate`, and the separate `@auth/edgedb-adapter` package:
23
- *
24
- * ```bash npm2yarn
25
- * npm install edgedb @auth/edgedb-adapter
26
- * npm install @edgedb/generate --save-dev
27
- * ```
28
- *
29
- * ## Installation
30
- *
31
- * First, ensure you have the EdgeDB CLI installed.
32
- *
33
- * Follow the instructions below, or read the [EdgeDB quickstart](https://www.edgedb.com/docs/intro/quickstart) to install the EdgeDB CLI and initialize a project
34
- *
35
- * ### Linux or macOS
36
- * ```bash
37
- * curl --proto '=https' --tlsv1.2 -sSf https://sh.edgedb.com | sh
38
- * ```
39
- *
40
- * ### Windows
41
- * ```powershell
42
- * iwr https://ps1.edgedb.com -useb | iex
43
- * ```
44
- *
45
- * Check that the CLI is available with the `edgedb --version` command. If you get a `Command not found` error, you may need to open a new terminal window before the `edgedb` command is available.
46
- *
47
- * Once the CLI is installed, initialize a project from the application’s root directory. You’ll be presented with a series of prompts.
48
- *
49
- * ```bash
50
- * edgedb project init
51
- * ```
52
- *
53
- * This process will spin up an EdgeDB instance and [“link”](https://www.edgedb.com/docs/cli/edgedb_instance/edgedb_instance_link#edgedb-instance-link) it with your current directory. As long as you’re inside that directory, CLI commands and client libraries will be able to connect to the linked instance automatically, without additional configuration.
54
- *
55
- * ## Setup
56
- *
57
- * ### NextAuth.js configuration
58
- *
59
- * Configure your NextAuth.js to use the EdgeDB Adapter:
60
- *
61
- * ```javascript title="pages/api/auth/[...nextauth].js"
62
- * import NextAuth from "next-auth"
63
- * import GoogleProvider from "next-auth/providers/google"
64
- * import { EdgeDBAdapter } from "@auth/edgedb-adapter"
65
- * import { createClient } from "edgedb"
66
- *
67
- * const client = createClient()
68
- *
69
- * export default NextAuth({
70
- * adapter: EdgeDBAdapter(client),
71
- * providers: [
72
- * GoogleProvider({
73
- * clientId: process.env.GOOGLE_CLIENT_ID,
74
- * clientSecret: process.env.GOOGLE_CLIENT_SECRET,
75
- * }),
76
- * ],
77
- * })
78
- * ```
79
- *
80
- * ### Create the EdgeDB schema
81
- *
82
- * Replace the contents of the auto-generated file in `dbschema/default.esdl` with the following:
83
- *
84
- * > This schema is adapted for use in EdgeDB and based upon our main [schema](https://authjs.dev/getting-started/adapters#models)
85
- *
86
- * ```json title="default.esdl"
87
- * module default {
88
- * type User {
89
- * property name -> str;
90
- * required property email -> str {
91
- * constraint exclusive;
92
- * }
93
- * property emailVerified -> datetime;
94
- * property image -> str;
95
- * multi link accounts := .<user[is Account];
96
- * multi link sessions := .<user[is Session];
97
- * property createdAt -> datetime {
98
- * default := datetime_current();
99
- * };
100
- * }
101
- *
102
- * type Account {
103
- * required property userId := .user.id;
104
- * required property type -> str;
105
- * required property provider -> str;
106
- * required property providerAccountId -> str {
107
- * constraint exclusive;
108
- * };
109
- * property refresh_token -> str;
110
- * property access_token -> str;
111
- * property expires_at -> int64;
112
- * property token_type -> str;
113
- * property scope -> str;
114
- * property id_token -> str;
115
- * property session_state -> str;
116
- * required link user -> User {
117
- * on target delete delete source;
118
- * };
119
- * property createdAt -> datetime {
120
- * default := datetime_current();
121
- * };
122
- *
123
- * constraint exclusive on ((.provider, .providerAccountId))
124
- * }
125
- *
126
- * type Session {
127
- * required property sessionToken -> str {
128
- * constraint exclusive;
129
- * }
130
- * required property userId := .user.id;
131
- * required property expires -> datetime;
132
- * required link user -> User {
133
- * on target delete delete source;
134
- * };
135
- * property createdAt -> datetime {
136
- * default := datetime_current();
137
- * };
138
- * }
139
- *
140
- * type VerificationToken {
141
- * required property identifier -> str;
142
- * required property token -> str {
143
- * constraint exclusive;
144
- * }
145
- * required property expires -> datetime;
146
- * property createdAt -> datetime {
147
- * default := datetime_current();
148
- * };
149
- *
150
- * constraint exclusive on ((.identifier, .token))
151
- * }
152
- * }
153
- *
154
- * # Disable the application of access policies within access policies
155
- * # themselves. This behavior will become the default in EdgeDB 3.0.
156
- * # See: https://www.edgedb.com/docs/reference/ddl/access_policies#nonrecursive
157
- * using future nonrecursive_access_policies;
158
- * ```
159
- *
160
- * ### Migrate the database schema
161
- *
162
- * Create a migration
163
- *
164
- * ```
165
- * edgedb migration create
166
- * ```
167
- *
168
- * Apply the migration
169
- *
170
- * ```
171
- * edgedb migrate
172
- * ```
173
- *
174
- * To learn more about [EdgeDB migrations](https://www.edgedb.com/docs/intro/migrations#generate-a-migration), check out the [Migrations docs](https://www.edgedb.com/docs/intro/migrations).
175
- *
176
- * ### Generate the query builder
177
- *
178
- * ```npm2yarn
179
- * npx @edgedb/generate edgeql-js
180
- * ```
181
- *
182
- * This will generate the [query builder](https://www.edgedb.com/docs/clients/js/querybuilder) so that you can write fully typed EdgeQL queries with TypeScript in a code-first way.
183
- *
184
- * For example
185
- *
186
- * ```ts
187
- * const query = e.select(e.User, () => ({
188
- * id: true,
189
- * email: true,
190
- * emailVerified: true,
191
- * name: true,
192
- * image: true,
193
- * filter_single: { email: 'johndoe@example.com' },
194
- * }));
195
- *
196
- * return await query.run(client);
197
- *
198
- * // Return type:
199
- * // {
200
- * // id: string;
201
- * // email: string;
202
- * // emailVerified: Date | null;
203
- * // image: string | null;
204
- * // name: string | null;
205
- * // } | null
206
- *
207
- * ```
208
- *
209
- *
210
- * ## Deploying
211
- *
212
- * ### Deploy EdgeDB
213
- *
214
- * First deploy an EdgeDB instance on your preferred cloud provider:
215
- *
216
- * [AWS](https://www.edgedb.com/docs/guides/deployment/aws_aurora_ecs)
217
- *
218
- * [Google Cloud](https://www.edgedb.com/docs/guides/deployment/gcp)
219
- *
220
- * [Azure](https://www.edgedb.com/docs/guides/deployment/azure_flexibleserver)
221
- *
222
- * [DigitalOcean](https://www.edgedb.com/docs/guides/deployment/digitalocean)
223
- *
224
- * [Fly.io](https://www.edgedb.com/docs/guides/deployment/fly_io)
225
- *
226
- * [Docker](https://www.edgedb.com/docs/guides/deployment/docker) (cloud-agnostic)
227
- *
228
- * ### Find your instance’s DSN
229
- *
230
- * The DSN is also known as a connection string. It will have the format `edgedb://username:password@hostname:port`. The exact instructions for this depend on which cloud you are deploying to.
231
- *
232
- * ### Set an environment variable
233
- *
234
- * ```env title=".env"
235
- * EDGEDB_DSN=edgedb://johndoe:supersecure@myhost.com:420
236
- * ```
237
- *
238
- * ### Update the client
239
- *
240
- * ```diff title="pages/api/auth/[...nextauth].js"
241
- * import NextAuth from "next-auth"
242
- * import GoogleProvider from "next-auth/providers/google"
243
- * import { EdgeDBAdapter } from "@auth/edgedb-adapter"
244
- * import { createClient } from "edgedb"
245
- *
246
- * - const client = createClient()
247
- * + const client = createClient({ dsn: process.env.EDGEDB_DSN })
248
- *
249
- * export default NextAuth({
250
- * adapter: EdgeDBAdapter(client),
251
- * providers: [
252
- * GoogleProvider({
253
- * clientId: process.env.GOOGLE_CLIENT_ID,
254
- * clientSecret: process.env.GOOGLE_CLIENT_SECRET,
255
- * }),
256
- * ],
257
- * })
258
- * ```
259
- *
260
- *
261
- *
262
- * ### Apply migrations
263
- *
264
- * Use the DSN to apply migrations against your remote instance.
265
- *
266
- * ```bash
267
- * edgedb migrate --dsn <your-instance-dsn>
268
- * ```
269
- *
270
- * ### Set up a `prebuild` script
271
- *
272
- * Add the following `prebuild` script to your `package.json`. When your hosting provider initializes the build, it will trigger this script which will generate the query builder. The `npx @edgedb/generate edgeql-js` command will read the value of the `EDGEDB_DSN` environment variable, connect to the database, and generate the query builder before your hosting provider starts building the project.
273
- *
274
- * ```diff title="package.json"
275
- * "scripts": {
276
- * "dev": "next dev",
277
- * "build": "next build",
278
- * "start": "next start",
279
- * "lint": "next lint",
280
- * + "prebuild": "npx @edgedb/generate edgeql-js"
281
- * },
282
- * ```
283
- *
284
- */
285
20
  export declare function EdgeDBAdapter(client: Client): Adapter;
286
21
  //# 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;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EACV,OAAO,EAIR,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwQG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAmUrD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EACV,OAAO,EAIR,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEpC,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAmUrD"}
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: 16}}>
3
- * <p style={{fontWeight: "normal"}}>Official <a href="https://www.edgedb.com/">Edge DB</a> adapter for Auth.js / NextAuth.js.</p>
2
+ * <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: "16px"}}>
3
+ * <p>Official <a href="https://www.edgedb.com/">Edge DB</a> adapter for Auth.js / NextAuth.js.</p>
4
4
  * <a href="https://www.edgedb.com/">
5
5
  * <img style={{display: "block"}} src="/img/adapters/edgedb.svg" width="38" />
6
6
  * </a>
@@ -15,271 +15,6 @@
15
15
  *
16
16
  * @module @auth/edgedb-adapter
17
17
  */
18
- /**
19
- *
20
- * To use this Adapter, you need to install `edgedb`, `@edgedb/generate`, and the separate `@auth/edgedb-adapter` package:
21
- *
22
- * ```bash npm2yarn
23
- * npm install edgedb @auth/edgedb-adapter
24
- * npm install @edgedb/generate --save-dev
25
- * ```
26
- *
27
- * ## Installation
28
- *
29
- * First, ensure you have the EdgeDB CLI installed.
30
- *
31
- * Follow the instructions below, or read the [EdgeDB quickstart](https://www.edgedb.com/docs/intro/quickstart) to install the EdgeDB CLI and initialize a project
32
- *
33
- * ### Linux or macOS
34
- * ```bash
35
- * curl --proto '=https' --tlsv1.2 -sSf https://sh.edgedb.com | sh
36
- * ```
37
- *
38
- * ### Windows
39
- * ```powershell
40
- * iwr https://ps1.edgedb.com -useb | iex
41
- * ```
42
- *
43
- * Check that the CLI is available with the `edgedb --version` command. If you get a `Command not found` error, you may need to open a new terminal window before the `edgedb` command is available.
44
- *
45
- * Once the CLI is installed, initialize a project from the application’s root directory. You’ll be presented with a series of prompts.
46
- *
47
- * ```bash
48
- * edgedb project init
49
- * ```
50
- *
51
- * This process will spin up an EdgeDB instance and [“link”](https://www.edgedb.com/docs/cli/edgedb_instance/edgedb_instance_link#edgedb-instance-link) it with your current directory. As long as you’re inside that directory, CLI commands and client libraries will be able to connect to the linked instance automatically, without additional configuration.
52
- *
53
- * ## Setup
54
- *
55
- * ### NextAuth.js configuration
56
- *
57
- * Configure your NextAuth.js to use the EdgeDB Adapter:
58
- *
59
- * ```javascript title="pages/api/auth/[...nextauth].js"
60
- * import NextAuth from "next-auth"
61
- * import GoogleProvider from "next-auth/providers/google"
62
- * import { EdgeDBAdapter } from "@auth/edgedb-adapter"
63
- * import { createClient } from "edgedb"
64
- *
65
- * const client = createClient()
66
- *
67
- * export default NextAuth({
68
- * adapter: EdgeDBAdapter(client),
69
- * providers: [
70
- * GoogleProvider({
71
- * clientId: process.env.GOOGLE_CLIENT_ID,
72
- * clientSecret: process.env.GOOGLE_CLIENT_SECRET,
73
- * }),
74
- * ],
75
- * })
76
- * ```
77
- *
78
- * ### Create the EdgeDB schema
79
- *
80
- * Replace the contents of the auto-generated file in `dbschema/default.esdl` with the following:
81
- *
82
- * > This schema is adapted for use in EdgeDB and based upon our main [schema](https://authjs.dev/getting-started/adapters#models)
83
- *
84
- * ```json title="default.esdl"
85
- * module default {
86
- * type User {
87
- * property name -> str;
88
- * required property email -> str {
89
- * constraint exclusive;
90
- * }
91
- * property emailVerified -> datetime;
92
- * property image -> str;
93
- * multi link accounts := .<user[is Account];
94
- * multi link sessions := .<user[is Session];
95
- * property createdAt -> datetime {
96
- * default := datetime_current();
97
- * };
98
- * }
99
- *
100
- * type Account {
101
- * required property userId := .user.id;
102
- * required property type -> str;
103
- * required property provider -> str;
104
- * required property providerAccountId -> str {
105
- * constraint exclusive;
106
- * };
107
- * property refresh_token -> str;
108
- * property access_token -> str;
109
- * property expires_at -> int64;
110
- * property token_type -> str;
111
- * property scope -> str;
112
- * property id_token -> str;
113
- * property session_state -> str;
114
- * required link user -> User {
115
- * on target delete delete source;
116
- * };
117
- * property createdAt -> datetime {
118
- * default := datetime_current();
119
- * };
120
- *
121
- * constraint exclusive on ((.provider, .providerAccountId))
122
- * }
123
- *
124
- * type Session {
125
- * required property sessionToken -> str {
126
- * constraint exclusive;
127
- * }
128
- * required property userId := .user.id;
129
- * required property expires -> datetime;
130
- * required link user -> User {
131
- * on target delete delete source;
132
- * };
133
- * property createdAt -> datetime {
134
- * default := datetime_current();
135
- * };
136
- * }
137
- *
138
- * type VerificationToken {
139
- * required property identifier -> str;
140
- * required property token -> str {
141
- * constraint exclusive;
142
- * }
143
- * required property expires -> datetime;
144
- * property createdAt -> datetime {
145
- * default := datetime_current();
146
- * };
147
- *
148
- * constraint exclusive on ((.identifier, .token))
149
- * }
150
- * }
151
- *
152
- * # Disable the application of access policies within access policies
153
- * # themselves. This behavior will become the default in EdgeDB 3.0.
154
- * # See: https://www.edgedb.com/docs/reference/ddl/access_policies#nonrecursive
155
- * using future nonrecursive_access_policies;
156
- * ```
157
- *
158
- * ### Migrate the database schema
159
- *
160
- * Create a migration
161
- *
162
- * ```
163
- * edgedb migration create
164
- * ```
165
- *
166
- * Apply the migration
167
- *
168
- * ```
169
- * edgedb migrate
170
- * ```
171
- *
172
- * To learn more about [EdgeDB migrations](https://www.edgedb.com/docs/intro/migrations#generate-a-migration), check out the [Migrations docs](https://www.edgedb.com/docs/intro/migrations).
173
- *
174
- * ### Generate the query builder
175
- *
176
- * ```npm2yarn
177
- * npx @edgedb/generate edgeql-js
178
- * ```
179
- *
180
- * This will generate the [query builder](https://www.edgedb.com/docs/clients/js/querybuilder) so that you can write fully typed EdgeQL queries with TypeScript in a code-first way.
181
- *
182
- * For example
183
- *
184
- * ```ts
185
- * const query = e.select(e.User, () => ({
186
- * id: true,
187
- * email: true,
188
- * emailVerified: true,
189
- * name: true,
190
- * image: true,
191
- * filter_single: { email: 'johndoe@example.com' },
192
- * }));
193
- *
194
- * return await query.run(client);
195
- *
196
- * // Return type:
197
- * // {
198
- * // id: string;
199
- * // email: string;
200
- * // emailVerified: Date | null;
201
- * // image: string | null;
202
- * // name: string | null;
203
- * // } | null
204
- *
205
- * ```
206
- *
207
- *
208
- * ## Deploying
209
- *
210
- * ### Deploy EdgeDB
211
- *
212
- * First deploy an EdgeDB instance on your preferred cloud provider:
213
- *
214
- * [AWS](https://www.edgedb.com/docs/guides/deployment/aws_aurora_ecs)
215
- *
216
- * [Google Cloud](https://www.edgedb.com/docs/guides/deployment/gcp)
217
- *
218
- * [Azure](https://www.edgedb.com/docs/guides/deployment/azure_flexibleserver)
219
- *
220
- * [DigitalOcean](https://www.edgedb.com/docs/guides/deployment/digitalocean)
221
- *
222
- * [Fly.io](https://www.edgedb.com/docs/guides/deployment/fly_io)
223
- *
224
- * [Docker](https://www.edgedb.com/docs/guides/deployment/docker) (cloud-agnostic)
225
- *
226
- * ### Find your instance’s DSN
227
- *
228
- * The DSN is also known as a connection string. It will have the format `edgedb://username:password@hostname:port`. The exact instructions for this depend on which cloud you are deploying to.
229
- *
230
- * ### Set an environment variable
231
- *
232
- * ```env title=".env"
233
- * EDGEDB_DSN=edgedb://johndoe:supersecure@myhost.com:420
234
- * ```
235
- *
236
- * ### Update the client
237
- *
238
- * ```diff title="pages/api/auth/[...nextauth].js"
239
- * import NextAuth from "next-auth"
240
- * import GoogleProvider from "next-auth/providers/google"
241
- * import { EdgeDBAdapter } from "@auth/edgedb-adapter"
242
- * import { createClient } from "edgedb"
243
- *
244
- * - const client = createClient()
245
- * + const client = createClient({ dsn: process.env.EDGEDB_DSN })
246
- *
247
- * export default NextAuth({
248
- * adapter: EdgeDBAdapter(client),
249
- * providers: [
250
- * GoogleProvider({
251
- * clientId: process.env.GOOGLE_CLIENT_ID,
252
- * clientSecret: process.env.GOOGLE_CLIENT_SECRET,
253
- * }),
254
- * ],
255
- * })
256
- * ```
257
- *
258
- *
259
- *
260
- * ### Apply migrations
261
- *
262
- * Use the DSN to apply migrations against your remote instance.
263
- *
264
- * ```bash
265
- * edgedb migrate --dsn <your-instance-dsn>
266
- * ```
267
- *
268
- * ### Set up a `prebuild` script
269
- *
270
- * Add the following `prebuild` script to your `package.json`. When your hosting provider initializes the build, it will trigger this script which will generate the query builder. The `npx @edgedb/generate edgeql-js` command will read the value of the `EDGEDB_DSN` environment variable, connect to the database, and generate the query builder before your hosting provider starts building the project.
271
- *
272
- * ```diff title="package.json"
273
- * "scripts": {
274
- * "dev": "next dev",
275
- * "build": "next build",
276
- * "start": "next start",
277
- * "lint": "next lint",
278
- * + "prebuild": "npx @edgedb/generate edgeql-js"
279
- * },
280
- * ```
281
- *
282
- */
283
18
  export function EdgeDBAdapter(client) {
284
19
  return {
285
20
  async createUser({ email, emailVerified, name, image }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auth/edgedb-adapter",
3
- "version": "0.8.0",
3
+ "version": "1.1.0",
4
4
  "description": "EdgeDB adapter for next-auth.",
5
5
  "homepage": "https://authjs.dev",
6
6
  "repository": "https://github.com/nextauthjs/next-auth",
@@ -37,7 +37,7 @@
37
37
  "access": "public"
38
38
  },
39
39
  "dependencies": {
40
- "@auth/core": "0.29.0"
40
+ "@auth/core": "0.31.0"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "edgedb": "^1.0.1"
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: 16}}>
3
- * <p style={{fontWeight: "normal"}}>Official <a href="https://www.edgedb.com/">Edge DB</a> adapter for Auth.js / NextAuth.js.</p>
2
+ * <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: "16px"}}>
3
+ * <p>Official <a href="https://www.edgedb.com/">Edge DB</a> adapter for Auth.js / NextAuth.js.</p>
4
4
  * <a href="https://www.edgedb.com/">
5
5
  * <img style={{display: "block"}} src="/img/adapters/edgedb.svg" width="38" />
6
6
  * </a>
@@ -24,271 +24,6 @@ import type {
24
24
  } from "@auth/core/adapters"
25
25
  import type { Client } from "edgedb"
26
26
 
27
- /**
28
- *
29
- * To use this Adapter, you need to install `edgedb`, `@edgedb/generate`, and the separate `@auth/edgedb-adapter` package:
30
- *
31
- * ```bash npm2yarn
32
- * npm install edgedb @auth/edgedb-adapter
33
- * npm install @edgedb/generate --save-dev
34
- * ```
35
- *
36
- * ## Installation
37
- *
38
- * First, ensure you have the EdgeDB CLI installed.
39
- *
40
- * Follow the instructions below, or read the [EdgeDB quickstart](https://www.edgedb.com/docs/intro/quickstart) to install the EdgeDB CLI and initialize a project
41
- *
42
- * ### Linux or macOS
43
- * ```bash
44
- * curl --proto '=https' --tlsv1.2 -sSf https://sh.edgedb.com | sh
45
- * ```
46
- *
47
- * ### Windows
48
- * ```powershell
49
- * iwr https://ps1.edgedb.com -useb | iex
50
- * ```
51
- *
52
- * Check that the CLI is available with the `edgedb --version` command. If you get a `Command not found` error, you may need to open a new terminal window before the `edgedb` command is available.
53
- *
54
- * Once the CLI is installed, initialize a project from the application’s root directory. You’ll be presented with a series of prompts.
55
- *
56
- * ```bash
57
- * edgedb project init
58
- * ```
59
- *
60
- * This process will spin up an EdgeDB instance and [“link”](https://www.edgedb.com/docs/cli/edgedb_instance/edgedb_instance_link#edgedb-instance-link) it with your current directory. As long as you’re inside that directory, CLI commands and client libraries will be able to connect to the linked instance automatically, without additional configuration.
61
- *
62
- * ## Setup
63
- *
64
- * ### NextAuth.js configuration
65
- *
66
- * Configure your NextAuth.js to use the EdgeDB Adapter:
67
- *
68
- * ```javascript title="pages/api/auth/[...nextauth].js"
69
- * import NextAuth from "next-auth"
70
- * import GoogleProvider from "next-auth/providers/google"
71
- * import { EdgeDBAdapter } from "@auth/edgedb-adapter"
72
- * import { createClient } from "edgedb"
73
- *
74
- * const client = createClient()
75
- *
76
- * export default NextAuth({
77
- * adapter: EdgeDBAdapter(client),
78
- * providers: [
79
- * GoogleProvider({
80
- * clientId: process.env.GOOGLE_CLIENT_ID,
81
- * clientSecret: process.env.GOOGLE_CLIENT_SECRET,
82
- * }),
83
- * ],
84
- * })
85
- * ```
86
- *
87
- * ### Create the EdgeDB schema
88
- *
89
- * Replace the contents of the auto-generated file in `dbschema/default.esdl` with the following:
90
- *
91
- * > This schema is adapted for use in EdgeDB and based upon our main [schema](https://authjs.dev/getting-started/adapters#models)
92
- *
93
- * ```json title="default.esdl"
94
- * module default {
95
- * type User {
96
- * property name -> str;
97
- * required property email -> str {
98
- * constraint exclusive;
99
- * }
100
- * property emailVerified -> datetime;
101
- * property image -> str;
102
- * multi link accounts := .<user[is Account];
103
- * multi link sessions := .<user[is Session];
104
- * property createdAt -> datetime {
105
- * default := datetime_current();
106
- * };
107
- * }
108
- *
109
- * type Account {
110
- * required property userId := .user.id;
111
- * required property type -> str;
112
- * required property provider -> str;
113
- * required property providerAccountId -> str {
114
- * constraint exclusive;
115
- * };
116
- * property refresh_token -> str;
117
- * property access_token -> str;
118
- * property expires_at -> int64;
119
- * property token_type -> str;
120
- * property scope -> str;
121
- * property id_token -> str;
122
- * property session_state -> str;
123
- * required link user -> User {
124
- * on target delete delete source;
125
- * };
126
- * property createdAt -> datetime {
127
- * default := datetime_current();
128
- * };
129
- *
130
- * constraint exclusive on ((.provider, .providerAccountId))
131
- * }
132
- *
133
- * type Session {
134
- * required property sessionToken -> str {
135
- * constraint exclusive;
136
- * }
137
- * required property userId := .user.id;
138
- * required property expires -> datetime;
139
- * required link user -> User {
140
- * on target delete delete source;
141
- * };
142
- * property createdAt -> datetime {
143
- * default := datetime_current();
144
- * };
145
- * }
146
- *
147
- * type VerificationToken {
148
- * required property identifier -> str;
149
- * required property token -> str {
150
- * constraint exclusive;
151
- * }
152
- * required property expires -> datetime;
153
- * property createdAt -> datetime {
154
- * default := datetime_current();
155
- * };
156
- *
157
- * constraint exclusive on ((.identifier, .token))
158
- * }
159
- * }
160
- *
161
- * # Disable the application of access policies within access policies
162
- * # themselves. This behavior will become the default in EdgeDB 3.0.
163
- * # See: https://www.edgedb.com/docs/reference/ddl/access_policies#nonrecursive
164
- * using future nonrecursive_access_policies;
165
- * ```
166
- *
167
- * ### Migrate the database schema
168
- *
169
- * Create a migration
170
- *
171
- * ```
172
- * edgedb migration create
173
- * ```
174
- *
175
- * Apply the migration
176
- *
177
- * ```
178
- * edgedb migrate
179
- * ```
180
- *
181
- * To learn more about [EdgeDB migrations](https://www.edgedb.com/docs/intro/migrations#generate-a-migration), check out the [Migrations docs](https://www.edgedb.com/docs/intro/migrations).
182
- *
183
- * ### Generate the query builder
184
- *
185
- * ```npm2yarn
186
- * npx @edgedb/generate edgeql-js
187
- * ```
188
- *
189
- * This will generate the [query builder](https://www.edgedb.com/docs/clients/js/querybuilder) so that you can write fully typed EdgeQL queries with TypeScript in a code-first way.
190
- *
191
- * For example
192
- *
193
- * ```ts
194
- * const query = e.select(e.User, () => ({
195
- * id: true,
196
- * email: true,
197
- * emailVerified: true,
198
- * name: true,
199
- * image: true,
200
- * filter_single: { email: 'johndoe@example.com' },
201
- * }));
202
- *
203
- * return await query.run(client);
204
- *
205
- * // Return type:
206
- * // {
207
- * // id: string;
208
- * // email: string;
209
- * // emailVerified: Date | null;
210
- * // image: string | null;
211
- * // name: string | null;
212
- * // } | null
213
- *
214
- * ```
215
- *
216
- *
217
- * ## Deploying
218
- *
219
- * ### Deploy EdgeDB
220
- *
221
- * First deploy an EdgeDB instance on your preferred cloud provider:
222
- *
223
- * [AWS](https://www.edgedb.com/docs/guides/deployment/aws_aurora_ecs)
224
- *
225
- * [Google Cloud](https://www.edgedb.com/docs/guides/deployment/gcp)
226
- *
227
- * [Azure](https://www.edgedb.com/docs/guides/deployment/azure_flexibleserver)
228
- *
229
- * [DigitalOcean](https://www.edgedb.com/docs/guides/deployment/digitalocean)
230
- *
231
- * [Fly.io](https://www.edgedb.com/docs/guides/deployment/fly_io)
232
- *
233
- * [Docker](https://www.edgedb.com/docs/guides/deployment/docker) (cloud-agnostic)
234
- *
235
- * ### Find your instance’s DSN
236
- *
237
- * The DSN is also known as a connection string. It will have the format `edgedb://username:password@hostname:port`. The exact instructions for this depend on which cloud you are deploying to.
238
- *
239
- * ### Set an environment variable
240
- *
241
- * ```env title=".env"
242
- * EDGEDB_DSN=edgedb://johndoe:supersecure@myhost.com:420
243
- * ```
244
- *
245
- * ### Update the client
246
- *
247
- * ```diff title="pages/api/auth/[...nextauth].js"
248
- * import NextAuth from "next-auth"
249
- * import GoogleProvider from "next-auth/providers/google"
250
- * import { EdgeDBAdapter } from "@auth/edgedb-adapter"
251
- * import { createClient } from "edgedb"
252
- *
253
- * - const client = createClient()
254
- * + const client = createClient({ dsn: process.env.EDGEDB_DSN })
255
- *
256
- * export default NextAuth({
257
- * adapter: EdgeDBAdapter(client),
258
- * providers: [
259
- * GoogleProvider({
260
- * clientId: process.env.GOOGLE_CLIENT_ID,
261
- * clientSecret: process.env.GOOGLE_CLIENT_SECRET,
262
- * }),
263
- * ],
264
- * })
265
- * ```
266
- *
267
- *
268
- *
269
- * ### Apply migrations
270
- *
271
- * Use the DSN to apply migrations against your remote instance.
272
- *
273
- * ```bash
274
- * edgedb migrate --dsn <your-instance-dsn>
275
- * ```
276
- *
277
- * ### Set up a `prebuild` script
278
- *
279
- * Add the following `prebuild` script to your `package.json`. When your hosting provider initializes the build, it will trigger this script which will generate the query builder. The `npx @edgedb/generate edgeql-js` command will read the value of the `EDGEDB_DSN` environment variable, connect to the database, and generate the query builder before your hosting provider starts building the project.
280
- *
281
- * ```diff title="package.json"
282
- * "scripts": {
283
- * "dev": "next dev",
284
- * "build": "next build",
285
- * "start": "next start",
286
- * "lint": "next lint",
287
- * + "prebuild": "npx @edgedb/generate edgeql-js"
288
- * },
289
- * ```
290
- *
291
- */
292
27
  export function EdgeDBAdapter(client: Client): Adapter {
293
28
  return {
294
29
  async createUser({ email, emailVerified, name, image }) {