@auth/edgedb-adapter 1.0.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 +1 -1
- package/index.d.ts +1 -217
- package/index.d.ts.map +1 -1
- package/index.js +1 -217
- package/package.json +2 -2
- package/src/index.ts +1 -217
package/README.md
CHANGED
|
@@ -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="
|
|
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
2
|
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: "16px"}}>
|
|
3
|
-
* <p
|
|
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,221 +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
|
-
*
|
|
37
|
-
* ```bash
|
|
38
|
-
* curl --proto '=https' --tlsv1.2 -sSf https://sh.edgedb.com | sh
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* ### Windows
|
|
42
|
-
*
|
|
43
|
-
* ```powershell
|
|
44
|
-
* iwr https://ps1.edgedb.com -useb | iex
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* 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.
|
|
48
|
-
*
|
|
49
|
-
* Once the CLI is installed, initialize a project from the application’s root directory. You’ll be presented with a series of prompts.
|
|
50
|
-
*
|
|
51
|
-
* ```bash
|
|
52
|
-
* edgedb project init
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* 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.
|
|
56
|
-
*
|
|
57
|
-
* ## Setup
|
|
58
|
-
*
|
|
59
|
-
* ### NextAuth.js configuration
|
|
60
|
-
*
|
|
61
|
-
* Configure your NextAuth.js to use the EdgeDB Adapter:
|
|
62
|
-
*
|
|
63
|
-
* ```js title="pages/api/auth/[...nextauth].js"
|
|
64
|
-
* import NextAuth from "next-auth"
|
|
65
|
-
* import GoogleProvider from "next-auth/providers/google"
|
|
66
|
-
* import { EdgeDBAdapter } from "@auth/edgedb-adapter"
|
|
67
|
-
* import { createClient } from "edgedb"
|
|
68
|
-
*
|
|
69
|
-
* const client = createClient()
|
|
70
|
-
*
|
|
71
|
-
* export default NextAuth({
|
|
72
|
-
* adapter: EdgeDBAdapter(client),
|
|
73
|
-
* providers: [
|
|
74
|
-
* GoogleProvider({
|
|
75
|
-
* clientId: process.env.GOOGLE_CLIENT_ID,
|
|
76
|
-
* clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
|
77
|
-
* }),
|
|
78
|
-
* ],
|
|
79
|
-
* })
|
|
80
|
-
* ```
|
|
81
|
-
*
|
|
82
|
-
* ### Create the EdgeDB schema
|
|
83
|
-
*
|
|
84
|
-
* Replace the contents of the auto-generated file in `dbschema/default.esdl` with the following:
|
|
85
|
-
*
|
|
86
|
-
* > This schema is adapted for use in EdgeDB and based upon our main [schema](https://authjs.dev/getting-started/adapters#models)
|
|
87
|
-
*
|
|
88
|
-
* ```json title="default.esdl"
|
|
89
|
-
* module default {
|
|
90
|
-
* type User {
|
|
91
|
-
* property name -> str;
|
|
92
|
-
* required property email -> str {
|
|
93
|
-
* constraint exclusive;
|
|
94
|
-
* };
|
|
95
|
-
* property emailVerified -> datetime;
|
|
96
|
-
* property image -> str;
|
|
97
|
-
* multi link accounts := .<user[is Account];
|
|
98
|
-
* multi link sessions := .<user[is Session];
|
|
99
|
-
* property createdAt -> datetime {
|
|
100
|
-
* default := datetime_current();
|
|
101
|
-
* };
|
|
102
|
-
* }
|
|
103
|
-
*
|
|
104
|
-
* type Account {
|
|
105
|
-
* required property userId := .user.id;
|
|
106
|
-
* required property type -> str;
|
|
107
|
-
* required property provider -> str;
|
|
108
|
-
* required property providerAccountId -> str {
|
|
109
|
-
* constraint exclusive;
|
|
110
|
-
* };
|
|
111
|
-
* property refresh_token -> str;
|
|
112
|
-
* property access_token -> str;
|
|
113
|
-
* property expires_at -> int64;
|
|
114
|
-
* property token_type -> str;
|
|
115
|
-
* property scope -> str;
|
|
116
|
-
* property id_token -> str;
|
|
117
|
-
* property session_state -> str;
|
|
118
|
-
* required link user -> User {
|
|
119
|
-
* on target delete delete source;
|
|
120
|
-
* };
|
|
121
|
-
* property createdAt -> datetime {
|
|
122
|
-
* default := datetime_current();
|
|
123
|
-
* };
|
|
124
|
-
* constraint exclusive on ((.provider, .providerAccountId));
|
|
125
|
-
* }
|
|
126
|
-
*
|
|
127
|
-
* type Session {
|
|
128
|
-
* required property sessionToken -> str {
|
|
129
|
-
* constraint exclusive;
|
|
130
|
-
* };
|
|
131
|
-
* required property userId := .user.id;
|
|
132
|
-
* required property expires -> datetime;
|
|
133
|
-
* required link user -> User {
|
|
134
|
-
* on target delete delete source;
|
|
135
|
-
* };
|
|
136
|
-
* property createdAt -> datetime {
|
|
137
|
-
* default := datetime_current();
|
|
138
|
-
* };
|
|
139
|
-
* }
|
|
140
|
-
*
|
|
141
|
-
* type VerificationToken {
|
|
142
|
-
* required property identifier -> str;
|
|
143
|
-
* required property token -> str {
|
|
144
|
-
* constraint exclusive;
|
|
145
|
-
* };
|
|
146
|
-
* required property expires -> datetime;
|
|
147
|
-
* property createdAt -> datetime {
|
|
148
|
-
* default := datetime_current();
|
|
149
|
-
* };
|
|
150
|
-
*
|
|
151
|
-
* constraint exclusive on ((.identifier, .token));
|
|
152
|
-
* }
|
|
153
|
-
* }
|
|
154
|
-
*
|
|
155
|
-
* # Disable the application of access policies within access policies
|
|
156
|
-
* # themselves. This behavior will become the default in EdgeDB 3.0.
|
|
157
|
-
* # See: https://www.edgedb.com/docs/reference/ddl/access_policies#nonrecursive
|
|
158
|
-
*
|
|
159
|
-
* using future nonrecursive_access_policies;
|
|
160
|
-
* ```
|
|
161
|
-
*
|
|
162
|
-
* ### Migrate the database schema
|
|
163
|
-
*
|
|
164
|
-
* 1. Create a migration
|
|
165
|
-
*
|
|
166
|
-
* ```bash
|
|
167
|
-
* edgedb migration create
|
|
168
|
-
* ```
|
|
169
|
-
*
|
|
170
|
-
* 2. Apply the migration
|
|
171
|
-
*
|
|
172
|
-
* ```bash
|
|
173
|
-
* edgedb migrate
|
|
174
|
-
* ```
|
|
175
|
-
*
|
|
176
|
-
* 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).
|
|
177
|
-
*
|
|
178
|
-
* ### Generate the query builder
|
|
179
|
-
*
|
|
180
|
-
* ```bash
|
|
181
|
-
* npx @edgedb/generate edgeql-js
|
|
182
|
-
* ```
|
|
183
|
-
*
|
|
184
|
-
* 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.
|
|
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
|
-
*
|
|
199
|
-
* ## Deploying
|
|
200
|
-
*
|
|
201
|
-
* ### Deploy EdgeDB
|
|
202
|
-
*
|
|
203
|
-
* First deploy an EdgeDB instance on your preferred cloud provider:
|
|
204
|
-
*
|
|
205
|
-
* - [AWS](https://www.edgedb.com/docs/guides/deployment/aws_aurora_ecs)
|
|
206
|
-
* - [Google Cloud](https://www.edgedb.com/docs/guides/deployment/gcp)
|
|
207
|
-
* - [Azure](https://www.edgedb.com/docs/guides/deployment/azure_flexibleserver)
|
|
208
|
-
* - [DigitalOcean](https://www.edgedb.com/docs/guides/deployment/digitalocean)
|
|
209
|
-
* - [Fly.io](https://www.edgedb.com/docs/guides/deployment/fly_io)
|
|
210
|
-
* - [Docker](https://www.edgedb.com/docs/guides/deployment/docker) (cloud-agnostic)
|
|
211
|
-
*
|
|
212
|
-
* ### Find your instance’s DSN
|
|
213
|
-
*
|
|
214
|
-
* 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 provider your'e deploying to.
|
|
215
|
-
*
|
|
216
|
-
* ### Set an environment variable
|
|
217
|
-
*
|
|
218
|
-
* ```
|
|
219
|
-
* EDGEDB_DSN="edgedb://johndoe:supersecure@myhost.com:420"
|
|
220
|
-
* ```
|
|
221
|
-
*
|
|
222
|
-
* ### Apply migrations
|
|
223
|
-
*
|
|
224
|
-
* Use the DSN to apply migrations against your remote instance.
|
|
225
|
-
*
|
|
226
|
-
* ```bash
|
|
227
|
-
* edgedb migrate --dsn <your-instance-dsn>
|
|
228
|
-
* ```
|
|
229
|
-
*
|
|
230
|
-
* ### Set up a `prebuild` script
|
|
231
|
-
*
|
|
232
|
-
* 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.
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*/
|
|
236
20
|
export declare function EdgeDBAdapter(client: Client): Adapter;
|
|
237
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
|
|
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
2
|
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: "16px"}}>
|
|
3
|
-
* <p
|
|
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,222 +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
|
-
*
|
|
35
|
-
* ```bash
|
|
36
|
-
* curl --proto '=https' --tlsv1.2 -sSf https://sh.edgedb.com | sh
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* ### Windows
|
|
40
|
-
*
|
|
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
|
-
* ```js 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
|
-
* constraint exclusive on ((.provider, .providerAccountId));
|
|
123
|
-
* }
|
|
124
|
-
*
|
|
125
|
-
* type Session {
|
|
126
|
-
* required property sessionToken -> str {
|
|
127
|
-
* constraint exclusive;
|
|
128
|
-
* };
|
|
129
|
-
* required property userId := .user.id;
|
|
130
|
-
* required property expires -> datetime;
|
|
131
|
-
* required link user -> User {
|
|
132
|
-
* on target delete delete source;
|
|
133
|
-
* };
|
|
134
|
-
* property createdAt -> datetime {
|
|
135
|
-
* default := datetime_current();
|
|
136
|
-
* };
|
|
137
|
-
* }
|
|
138
|
-
*
|
|
139
|
-
* type VerificationToken {
|
|
140
|
-
* required property identifier -> str;
|
|
141
|
-
* required property token -> str {
|
|
142
|
-
* constraint exclusive;
|
|
143
|
-
* };
|
|
144
|
-
* required property expires -> datetime;
|
|
145
|
-
* property createdAt -> datetime {
|
|
146
|
-
* default := datetime_current();
|
|
147
|
-
* };
|
|
148
|
-
*
|
|
149
|
-
* constraint exclusive on ((.identifier, .token));
|
|
150
|
-
* }
|
|
151
|
-
* }
|
|
152
|
-
*
|
|
153
|
-
* # Disable the application of access policies within access policies
|
|
154
|
-
* # themselves. This behavior will become the default in EdgeDB 3.0.
|
|
155
|
-
* # See: https://www.edgedb.com/docs/reference/ddl/access_policies#nonrecursive
|
|
156
|
-
*
|
|
157
|
-
* using future nonrecursive_access_policies;
|
|
158
|
-
* ```
|
|
159
|
-
*
|
|
160
|
-
* ### Migrate the database schema
|
|
161
|
-
*
|
|
162
|
-
* 1. Create a migration
|
|
163
|
-
*
|
|
164
|
-
* ```bash
|
|
165
|
-
* edgedb migration create
|
|
166
|
-
* ```
|
|
167
|
-
*
|
|
168
|
-
* 2. Apply the migration
|
|
169
|
-
*
|
|
170
|
-
* ```bash
|
|
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
|
-
* ```bash
|
|
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
|
-
* ```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
|
-
*
|
|
197
|
-
* ## Deploying
|
|
198
|
-
*
|
|
199
|
-
* ### Deploy EdgeDB
|
|
200
|
-
*
|
|
201
|
-
* First deploy an EdgeDB instance on your preferred cloud provider:
|
|
202
|
-
*
|
|
203
|
-
* - [AWS](https://www.edgedb.com/docs/guides/deployment/aws_aurora_ecs)
|
|
204
|
-
* - [Google Cloud](https://www.edgedb.com/docs/guides/deployment/gcp)
|
|
205
|
-
* - [Azure](https://www.edgedb.com/docs/guides/deployment/azure_flexibleserver)
|
|
206
|
-
* - [DigitalOcean](https://www.edgedb.com/docs/guides/deployment/digitalocean)
|
|
207
|
-
* - [Fly.io](https://www.edgedb.com/docs/guides/deployment/fly_io)
|
|
208
|
-
* - [Docker](https://www.edgedb.com/docs/guides/deployment/docker) (cloud-agnostic)
|
|
209
|
-
*
|
|
210
|
-
* ### Find your instance’s DSN
|
|
211
|
-
*
|
|
212
|
-
* 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 provider your'e deploying to.
|
|
213
|
-
*
|
|
214
|
-
* ### Set an environment variable
|
|
215
|
-
*
|
|
216
|
-
* ```
|
|
217
|
-
* EDGEDB_DSN="edgedb://johndoe:supersecure@myhost.com:420"
|
|
218
|
-
* ```
|
|
219
|
-
*
|
|
220
|
-
* ### Apply migrations
|
|
221
|
-
*
|
|
222
|
-
* Use the DSN to apply migrations against your remote instance.
|
|
223
|
-
*
|
|
224
|
-
* ```bash
|
|
225
|
-
* edgedb migrate --dsn <your-instance-dsn>
|
|
226
|
-
* ```
|
|
227
|
-
*
|
|
228
|
-
* ### Set up a `prebuild` script
|
|
229
|
-
*
|
|
230
|
-
* 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.
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*/
|
|
234
18
|
export function EdgeDBAdapter(client) {
|
|
235
19
|
return {
|
|
236
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": "1.
|
|
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.
|
|
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
2
|
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: "16px"}}>
|
|
3
|
-
* <p
|
|
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,222 +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
|
-
*
|
|
44
|
-
* ```bash
|
|
45
|
-
* curl --proto '=https' --tlsv1.2 -sSf https://sh.edgedb.com | sh
|
|
46
|
-
* ```
|
|
47
|
-
*
|
|
48
|
-
* ### Windows
|
|
49
|
-
*
|
|
50
|
-
* ```powershell
|
|
51
|
-
* iwr https://ps1.edgedb.com -useb | iex
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* 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.
|
|
55
|
-
*
|
|
56
|
-
* Once the CLI is installed, initialize a project from the application’s root directory. You’ll be presented with a series of prompts.
|
|
57
|
-
*
|
|
58
|
-
* ```bash
|
|
59
|
-
* edgedb project init
|
|
60
|
-
* ```
|
|
61
|
-
*
|
|
62
|
-
* 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.
|
|
63
|
-
*
|
|
64
|
-
* ## Setup
|
|
65
|
-
*
|
|
66
|
-
* ### NextAuth.js configuration
|
|
67
|
-
*
|
|
68
|
-
* Configure your NextAuth.js to use the EdgeDB Adapter:
|
|
69
|
-
*
|
|
70
|
-
* ```js title="pages/api/auth/[...nextauth].js"
|
|
71
|
-
* import NextAuth from "next-auth"
|
|
72
|
-
* import GoogleProvider from "next-auth/providers/google"
|
|
73
|
-
* import { EdgeDBAdapter } from "@auth/edgedb-adapter"
|
|
74
|
-
* import { createClient } from "edgedb"
|
|
75
|
-
*
|
|
76
|
-
* const client = createClient()
|
|
77
|
-
*
|
|
78
|
-
* export default NextAuth({
|
|
79
|
-
* adapter: EdgeDBAdapter(client),
|
|
80
|
-
* providers: [
|
|
81
|
-
* GoogleProvider({
|
|
82
|
-
* clientId: process.env.GOOGLE_CLIENT_ID,
|
|
83
|
-
* clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
|
84
|
-
* }),
|
|
85
|
-
* ],
|
|
86
|
-
* })
|
|
87
|
-
* ```
|
|
88
|
-
*
|
|
89
|
-
* ### Create the EdgeDB schema
|
|
90
|
-
*
|
|
91
|
-
* Replace the contents of the auto-generated file in `dbschema/default.esdl` with the following:
|
|
92
|
-
*
|
|
93
|
-
* > This schema is adapted for use in EdgeDB and based upon our main [schema](https://authjs.dev/getting-started/adapters#models)
|
|
94
|
-
*
|
|
95
|
-
* ```json title="default.esdl"
|
|
96
|
-
* module default {
|
|
97
|
-
* type User {
|
|
98
|
-
* property name -> str;
|
|
99
|
-
* required property email -> str {
|
|
100
|
-
* constraint exclusive;
|
|
101
|
-
* };
|
|
102
|
-
* property emailVerified -> datetime;
|
|
103
|
-
* property image -> str;
|
|
104
|
-
* multi link accounts := .<user[is Account];
|
|
105
|
-
* multi link sessions := .<user[is Session];
|
|
106
|
-
* property createdAt -> datetime {
|
|
107
|
-
* default := datetime_current();
|
|
108
|
-
* };
|
|
109
|
-
* }
|
|
110
|
-
*
|
|
111
|
-
* type Account {
|
|
112
|
-
* required property userId := .user.id;
|
|
113
|
-
* required property type -> str;
|
|
114
|
-
* required property provider -> str;
|
|
115
|
-
* required property providerAccountId -> str {
|
|
116
|
-
* constraint exclusive;
|
|
117
|
-
* };
|
|
118
|
-
* property refresh_token -> str;
|
|
119
|
-
* property access_token -> str;
|
|
120
|
-
* property expires_at -> int64;
|
|
121
|
-
* property token_type -> str;
|
|
122
|
-
* property scope -> str;
|
|
123
|
-
* property id_token -> str;
|
|
124
|
-
* property session_state -> str;
|
|
125
|
-
* required link user -> User {
|
|
126
|
-
* on target delete delete source;
|
|
127
|
-
* };
|
|
128
|
-
* property createdAt -> datetime {
|
|
129
|
-
* default := datetime_current();
|
|
130
|
-
* };
|
|
131
|
-
* constraint exclusive on ((.provider, .providerAccountId));
|
|
132
|
-
* }
|
|
133
|
-
*
|
|
134
|
-
* type Session {
|
|
135
|
-
* required property sessionToken -> str {
|
|
136
|
-
* constraint exclusive;
|
|
137
|
-
* };
|
|
138
|
-
* required property userId := .user.id;
|
|
139
|
-
* required property expires -> datetime;
|
|
140
|
-
* required link user -> User {
|
|
141
|
-
* on target delete delete source;
|
|
142
|
-
* };
|
|
143
|
-
* property createdAt -> datetime {
|
|
144
|
-
* default := datetime_current();
|
|
145
|
-
* };
|
|
146
|
-
* }
|
|
147
|
-
*
|
|
148
|
-
* type VerificationToken {
|
|
149
|
-
* required property identifier -> str;
|
|
150
|
-
* required property token -> str {
|
|
151
|
-
* constraint exclusive;
|
|
152
|
-
* };
|
|
153
|
-
* required property expires -> datetime;
|
|
154
|
-
* property createdAt -> datetime {
|
|
155
|
-
* default := datetime_current();
|
|
156
|
-
* };
|
|
157
|
-
*
|
|
158
|
-
* constraint exclusive on ((.identifier, .token));
|
|
159
|
-
* }
|
|
160
|
-
* }
|
|
161
|
-
*
|
|
162
|
-
* # Disable the application of access policies within access policies
|
|
163
|
-
* # themselves. This behavior will become the default in EdgeDB 3.0.
|
|
164
|
-
* # See: https://www.edgedb.com/docs/reference/ddl/access_policies#nonrecursive
|
|
165
|
-
*
|
|
166
|
-
* using future nonrecursive_access_policies;
|
|
167
|
-
* ```
|
|
168
|
-
*
|
|
169
|
-
* ### Migrate the database schema
|
|
170
|
-
*
|
|
171
|
-
* 1. Create a migration
|
|
172
|
-
*
|
|
173
|
-
* ```bash
|
|
174
|
-
* edgedb migration create
|
|
175
|
-
* ```
|
|
176
|
-
*
|
|
177
|
-
* 2. Apply the migration
|
|
178
|
-
*
|
|
179
|
-
* ```bash
|
|
180
|
-
* edgedb migrate
|
|
181
|
-
* ```
|
|
182
|
-
*
|
|
183
|
-
* 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).
|
|
184
|
-
*
|
|
185
|
-
* ### Generate the query builder
|
|
186
|
-
*
|
|
187
|
-
* ```bash
|
|
188
|
-
* npx @edgedb/generate edgeql-js
|
|
189
|
-
* ```
|
|
190
|
-
*
|
|
191
|
-
* 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.
|
|
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
|
-
*
|
|
206
|
-
* ## Deploying
|
|
207
|
-
*
|
|
208
|
-
* ### Deploy EdgeDB
|
|
209
|
-
*
|
|
210
|
-
* First deploy an EdgeDB instance on your preferred cloud provider:
|
|
211
|
-
*
|
|
212
|
-
* - [AWS](https://www.edgedb.com/docs/guides/deployment/aws_aurora_ecs)
|
|
213
|
-
* - [Google Cloud](https://www.edgedb.com/docs/guides/deployment/gcp)
|
|
214
|
-
* - [Azure](https://www.edgedb.com/docs/guides/deployment/azure_flexibleserver)
|
|
215
|
-
* - [DigitalOcean](https://www.edgedb.com/docs/guides/deployment/digitalocean)
|
|
216
|
-
* - [Fly.io](https://www.edgedb.com/docs/guides/deployment/fly_io)
|
|
217
|
-
* - [Docker](https://www.edgedb.com/docs/guides/deployment/docker) (cloud-agnostic)
|
|
218
|
-
*
|
|
219
|
-
* ### Find your instance’s DSN
|
|
220
|
-
*
|
|
221
|
-
* 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 provider your'e deploying to.
|
|
222
|
-
*
|
|
223
|
-
* ### Set an environment variable
|
|
224
|
-
*
|
|
225
|
-
* ```
|
|
226
|
-
* EDGEDB_DSN="edgedb://johndoe:supersecure@myhost.com:420"
|
|
227
|
-
* ```
|
|
228
|
-
*
|
|
229
|
-
* ### Apply migrations
|
|
230
|
-
*
|
|
231
|
-
* Use the DSN to apply migrations against your remote instance.
|
|
232
|
-
*
|
|
233
|
-
* ```bash
|
|
234
|
-
* edgedb migrate --dsn <your-instance-dsn>
|
|
235
|
-
* ```
|
|
236
|
-
*
|
|
237
|
-
* ### Set up a `prebuild` script
|
|
238
|
-
*
|
|
239
|
-
* 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.
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*/
|
|
243
27
|
export function EdgeDBAdapter(client: Client): Adapter {
|
|
244
28
|
return {
|
|
245
29
|
async createUser({ email, emailVerified, name, image }) {
|