@auth/fauna-adapter 2.1.1 → 2.2.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/index.d.ts +25 -1
- package/index.d.ts.map +1 -1
- package/index.js +43 -20
- package/package.json +2 -2
- package/src/index.ts +55 -21
package/index.d.ts
CHANGED
|
@@ -25,6 +25,14 @@ export type FaunaVerificationToken = ToFauna<VerificationToken> & {
|
|
|
25
25
|
id: string;
|
|
26
26
|
};
|
|
27
27
|
export type FaunaAccount = ToFauna<AdapterAccount>;
|
|
28
|
+
type AdapterConfig = {
|
|
29
|
+
collectionNames: {
|
|
30
|
+
user: string;
|
|
31
|
+
session: string;
|
|
32
|
+
account: string;
|
|
33
|
+
verificationToken: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
28
36
|
/**
|
|
29
37
|
*
|
|
30
38
|
* ## Setup
|
|
@@ -128,6 +136,22 @@ export type FaunaAccount = ToFauna<AdapterAccount>;
|
|
|
128
136
|
*
|
|
129
137
|
* > This schema is adapted for use in Fauna and based upon our main [schema](https://authjs.dev/reference/core/adapters#models)
|
|
130
138
|
*
|
|
139
|
+
* #### Custom collection names
|
|
140
|
+
* If you want to use custom collection names, you can pass them as an option to the adapter, like this:
|
|
141
|
+
*
|
|
142
|
+
* ```javascript
|
|
143
|
+
* FaunaAdapter(client, {
|
|
144
|
+
* collectionNames: {
|
|
145
|
+
* user: "CustomUser",
|
|
146
|
+
* account: "CustomAccount",
|
|
147
|
+
* session: "CustomSession",
|
|
148
|
+
* verificationToken: "CustomVerificationToken",
|
|
149
|
+
* }
|
|
150
|
+
* })
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* Make sure the collection names you pass to the provider match the collection names of your Fauna database.
|
|
154
|
+
*
|
|
131
155
|
* ### Migrating from v1
|
|
132
156
|
* In v2, we've renamed the collections to use uppercase naming, in accordance with Fauna best practices. If you're migrating from v1, you'll need to rename your collections to match the new naming scheme.
|
|
133
157
|
* Additionally, we've renamed the indexes to match the new method-like index names.
|
|
@@ -183,7 +207,7 @@ export type FaunaAccount = ToFauna<AdapterAccount>;
|
|
|
183
207
|
* ```
|
|
184
208
|
*
|
|
185
209
|
**/
|
|
186
|
-
export declare function FaunaAdapter(client: Client): Adapter;
|
|
210
|
+
export declare function FaunaAdapter(client: Client, config?: AdapterConfig): Adapter;
|
|
187
211
|
export declare const format: {
|
|
188
212
|
/** Takes an object that's coming from the database and converts it to plain JavaScript. */
|
|
189
213
|
from<T>(object?: Record<string, any>): T;
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAqB,UAAU,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAqB,UAAU,EAAE,gBAAgB,EAAU,MAAM,OAAO,CAAA;AAEjG,OAAO,KAAK,EACV,OAAO,EACP,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,cAAc,EACf,MAAM,qBAAqB,CAAA;AAE5B,KAAK,OAAO,CAAC,CAAC,IAAI;KACf,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,gBAAgB;CAC/I,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;AAC5C,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;AAClD,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAA;AAChF,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;AAElD,KAAK,aAAa,GAAG;IACnB,eAAe,EAAE;QACf,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,OAAO,EAAE,MAAM,CAAA;QACf,iBAAiB,EAAE,MAAM,CAAA;KAC1B,CAAA;CACF,CAAA;AASD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA6KI;AACJ,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CA8H5E;AAED,eAAO,MAAM,MAAM;IACjB,2FAA2F;qBAC3E,OAAO,MAAM,EAAE,GAAG,CAAC;IASnC,gGAAgG;oBAClF,OAAO,MAAM,EAAE,GAAG,CAAC;CAUlC,CAAA"}
|
package/index.js
CHANGED
|
@@ -15,6 +15,12 @@
|
|
|
15
15
|
* @module @auth/fauna-adapter
|
|
16
16
|
*/
|
|
17
17
|
import { TimeStub, fql, NullDocument } from "fauna";
|
|
18
|
+
const defaultCollectionNames = {
|
|
19
|
+
user: "User",
|
|
20
|
+
session: "Session",
|
|
21
|
+
account: "Account",
|
|
22
|
+
verificationToken: "VerificationToken",
|
|
23
|
+
};
|
|
18
24
|
/**
|
|
19
25
|
*
|
|
20
26
|
* ## Setup
|
|
@@ -118,6 +124,22 @@ import { TimeStub, fql, NullDocument } from "fauna";
|
|
|
118
124
|
*
|
|
119
125
|
* > This schema is adapted for use in Fauna and based upon our main [schema](https://authjs.dev/reference/core/adapters#models)
|
|
120
126
|
*
|
|
127
|
+
* #### Custom collection names
|
|
128
|
+
* If you want to use custom collection names, you can pass them as an option to the adapter, like this:
|
|
129
|
+
*
|
|
130
|
+
* ```javascript
|
|
131
|
+
* FaunaAdapter(client, {
|
|
132
|
+
* collectionNames: {
|
|
133
|
+
* user: "CustomUser",
|
|
134
|
+
* account: "CustomAccount",
|
|
135
|
+
* session: "CustomSession",
|
|
136
|
+
* verificationToken: "CustomVerificationToken",
|
|
137
|
+
* }
|
|
138
|
+
* })
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* Make sure the collection names you pass to the provider match the collection names of your Fauna database.
|
|
142
|
+
*
|
|
121
143
|
* ### Migrating from v1
|
|
122
144
|
* In v2, we've renamed the collections to use uppercase naming, in accordance with Fauna best practices. If you're migrating from v1, you'll need to rename your collections to match the new naming scheme.
|
|
123
145
|
* Additionally, we've renamed the indexes to match the new method-like index names.
|
|
@@ -173,29 +195,30 @@ import { TimeStub, fql, NullDocument } from "fauna";
|
|
|
173
195
|
* ```
|
|
174
196
|
*
|
|
175
197
|
**/
|
|
176
|
-
export function FaunaAdapter(client) {
|
|
198
|
+
export function FaunaAdapter(client, config) {
|
|
199
|
+
const { collectionNames = defaultCollectionNames } = config || {};
|
|
177
200
|
return {
|
|
178
201
|
async createUser(user) {
|
|
179
|
-
const response = await client.query(fql `
|
|
202
|
+
const response = await client.query(fql `Collection(${collectionNames.user}).create(${format.to(user)})`);
|
|
180
203
|
return format.from(response.data);
|
|
181
204
|
},
|
|
182
205
|
async getUser(id) {
|
|
183
|
-
const response = await client.query(fql `
|
|
206
|
+
const response = await client.query(fql `Collection(${collectionNames.user}).byId(${id})`);
|
|
184
207
|
if (response.data instanceof NullDocument)
|
|
185
208
|
return null;
|
|
186
209
|
return format.from(response.data);
|
|
187
210
|
},
|
|
188
211
|
async getUserByEmail(email) {
|
|
189
|
-
const response = await client.query(fql `
|
|
212
|
+
const response = await client.query(fql `Collection(${collectionNames.user}).byEmail(${email}).first()`);
|
|
190
213
|
if (response.data === null)
|
|
191
214
|
return null;
|
|
192
215
|
return format.from(response.data);
|
|
193
216
|
},
|
|
194
217
|
async getUserByAccount({ provider, providerAccountId }) {
|
|
195
218
|
const response = await client.query(fql `
|
|
196
|
-
let account =
|
|
219
|
+
let account = Collection(${collectionNames.account}).byProviderAndProviderAccountId(${provider}, ${providerAccountId}).first()
|
|
197
220
|
if (account != null) {
|
|
198
|
-
|
|
221
|
+
Collection(${collectionNames.user}).byId(account.userId)
|
|
199
222
|
} else {
|
|
200
223
|
null
|
|
201
224
|
}
|
|
@@ -205,34 +228,34 @@ export function FaunaAdapter(client) {
|
|
|
205
228
|
async updateUser(user) {
|
|
206
229
|
const _user = { ...user };
|
|
207
230
|
delete _user.id;
|
|
208
|
-
const response = await client.query(fql `
|
|
231
|
+
const response = await client.query(fql `Collection(${collectionNames.user}).byId(${user.id}).update(${format.to(_user)})`);
|
|
209
232
|
return format.from(response.data);
|
|
210
233
|
},
|
|
211
234
|
async deleteUser(userId) {
|
|
212
235
|
await client.query(fql `
|
|
213
236
|
// Delete the user's sessions
|
|
214
|
-
|
|
237
|
+
Collection(${collectionNames.session}).byUserId(${userId}).forEach(session => session.delete())
|
|
215
238
|
|
|
216
239
|
// Delete the user's accounts
|
|
217
|
-
|
|
240
|
+
Collection(${collectionNames.account}).byUserId(${userId}).forEach(account => account.delete())
|
|
218
241
|
|
|
219
242
|
// Delete the user
|
|
220
|
-
|
|
243
|
+
Collection(${collectionNames.user}).byId(${userId}).delete()
|
|
221
244
|
`);
|
|
222
245
|
},
|
|
223
246
|
async linkAccount(account) {
|
|
224
|
-
await client.query(fql `
|
|
247
|
+
await client.query(fql `Collection(${collectionNames.account}).create(${format.to(account)})`);
|
|
225
248
|
return account;
|
|
226
249
|
},
|
|
227
250
|
async unlinkAccount({ provider, providerAccountId }) {
|
|
228
|
-
const response = await client.query(fql `
|
|
251
|
+
const response = await client.query(fql `Collection(${collectionNames.account}).byProviderAndProviderAccountId(${provider}, ${providerAccountId}).first().delete()`);
|
|
229
252
|
return format.from(response.data);
|
|
230
253
|
},
|
|
231
254
|
async getSessionAndUser(sessionToken) {
|
|
232
255
|
const response = await client.query(fql `
|
|
233
|
-
let session =
|
|
256
|
+
let session = Collection(${collectionNames.session}).bySessionToken(${sessionToken}).first()
|
|
234
257
|
if (session != null) {
|
|
235
|
-
let user =
|
|
258
|
+
let user = Collection(${collectionNames.user}).byId(session.userId)
|
|
236
259
|
if (user != null) {
|
|
237
260
|
[user, session]
|
|
238
261
|
} else {
|
|
@@ -248,26 +271,26 @@ export function FaunaAdapter(client) {
|
|
|
248
271
|
return { session: format.from(session), user: format.from(user) };
|
|
249
272
|
},
|
|
250
273
|
async createSession(session) {
|
|
251
|
-
await client.query(fql `
|
|
274
|
+
await client.query(fql `Collection(${collectionNames.session}).create(${format.to(session)})`);
|
|
252
275
|
return session;
|
|
253
276
|
},
|
|
254
277
|
async updateSession(session) {
|
|
255
|
-
const response = await client.query(fql `
|
|
278
|
+
const response = await client.query(fql `Collection(${collectionNames.session}).bySessionToken(${session.sessionToken}).first().update(${format.to(session)})`);
|
|
256
279
|
return format.from(response.data);
|
|
257
280
|
},
|
|
258
281
|
async deleteSession(sessionToken) {
|
|
259
|
-
await client.query(fql `
|
|
282
|
+
await client.query(fql `Collection(${collectionNames.session}).bySessionToken(${sessionToken}).first().delete()`);
|
|
260
283
|
},
|
|
261
284
|
async createVerificationToken(verificationToken) {
|
|
262
|
-
await client.query(fql `
|
|
285
|
+
await client.query(fql `Collection(${collectionNames.verificationToken}).create(${format.to(verificationToken)})`);
|
|
263
286
|
return verificationToken;
|
|
264
287
|
},
|
|
265
288
|
async useVerificationToken({ identifier, token }) {
|
|
266
|
-
const response = await client.query(fql `
|
|
289
|
+
const response = await client.query(fql `Collection(${collectionNames.verificationToken}).byIdentifierAndToken(${identifier}, ${token}).first()`);
|
|
267
290
|
if (response.data === null)
|
|
268
291
|
return null;
|
|
269
292
|
// Delete the verification token so it can only be used once
|
|
270
|
-
await client.query(fql `
|
|
293
|
+
await client.query(fql `Collection(${collectionNames.verificationToken}).byId(${response.data.id}).delete()`);
|
|
271
294
|
const _verificationToken = { ...response.data };
|
|
272
295
|
delete _verificationToken.id;
|
|
273
296
|
return format.from(_verificationToken);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auth/fauna-adapter",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Fauna 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.29.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"fauna": "^1.3.1"
|
package/src/index.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* @module @auth/fauna-adapter
|
|
16
16
|
*/
|
|
17
|
-
import { Client, TimeStub, fql, NullDocument, QueryValue, QueryValueObject } from "fauna"
|
|
17
|
+
import { Client, TimeStub, fql, NullDocument, QueryValue, QueryValueObject, Module } from "fauna"
|
|
18
18
|
|
|
19
19
|
import type {
|
|
20
20
|
Adapter,
|
|
@@ -33,6 +33,22 @@ export type FaunaSession = ToFauna<AdapterSession>
|
|
|
33
33
|
export type FaunaVerificationToken = ToFauna<VerificationToken> & { id: string }
|
|
34
34
|
export type FaunaAccount = ToFauna<AdapterAccount>
|
|
35
35
|
|
|
36
|
+
type AdapterConfig = {
|
|
37
|
+
collectionNames: {
|
|
38
|
+
user: string
|
|
39
|
+
session: string
|
|
40
|
+
account: string
|
|
41
|
+
verificationToken: string
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const defaultCollectionNames = {
|
|
46
|
+
user: "User",
|
|
47
|
+
session: "Session",
|
|
48
|
+
account: "Account",
|
|
49
|
+
verificationToken: "VerificationToken",
|
|
50
|
+
}
|
|
51
|
+
|
|
36
52
|
/**
|
|
37
53
|
*
|
|
38
54
|
* ## Setup
|
|
@@ -136,6 +152,22 @@ export type FaunaAccount = ToFauna<AdapterAccount>
|
|
|
136
152
|
*
|
|
137
153
|
* > This schema is adapted for use in Fauna and based upon our main [schema](https://authjs.dev/reference/core/adapters#models)
|
|
138
154
|
*
|
|
155
|
+
* #### Custom collection names
|
|
156
|
+
* If you want to use custom collection names, you can pass them as an option to the adapter, like this:
|
|
157
|
+
*
|
|
158
|
+
* ```javascript
|
|
159
|
+
* FaunaAdapter(client, {
|
|
160
|
+
* collectionNames: {
|
|
161
|
+
* user: "CustomUser",
|
|
162
|
+
* account: "CustomAccount",
|
|
163
|
+
* session: "CustomSession",
|
|
164
|
+
* verificationToken: "CustomVerificationToken",
|
|
165
|
+
* }
|
|
166
|
+
* })
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* Make sure the collection names you pass to the provider match the collection names of your Fauna database.
|
|
170
|
+
*
|
|
139
171
|
* ### Migrating from v1
|
|
140
172
|
* In v2, we've renamed the collections to use uppercase naming, in accordance with Fauna best practices. If you're migrating from v1, you'll need to rename your collections to match the new naming scheme.
|
|
141
173
|
* Additionally, we've renamed the indexes to match the new method-like index names.
|
|
@@ -191,33 +223,35 @@ export type FaunaAccount = ToFauna<AdapterAccount>
|
|
|
191
223
|
* ```
|
|
192
224
|
*
|
|
193
225
|
**/
|
|
194
|
-
export function FaunaAdapter(client: Client): Adapter {
|
|
226
|
+
export function FaunaAdapter(client: Client, config?: AdapterConfig): Adapter {
|
|
227
|
+
const { collectionNames = defaultCollectionNames } = config || {}
|
|
228
|
+
|
|
195
229
|
return {
|
|
196
230
|
async createUser(user) {
|
|
197
231
|
const response = await client.query<FaunaUser>(
|
|
198
|
-
fql`
|
|
232
|
+
fql`Collection(${collectionNames.user}).create(${format.to(user)})`,
|
|
199
233
|
)
|
|
200
234
|
return format.from(response.data)
|
|
201
235
|
},
|
|
202
236
|
async getUser(id) {
|
|
203
237
|
const response = await client.query<FaunaUser | NullDocument>(
|
|
204
|
-
fql`
|
|
238
|
+
fql`Collection(${collectionNames.user}).byId(${id})`,
|
|
205
239
|
)
|
|
206
240
|
if (response.data instanceof NullDocument) return null
|
|
207
241
|
return format.from(response.data)
|
|
208
242
|
},
|
|
209
243
|
async getUserByEmail(email) {
|
|
210
244
|
const response = await client.query<FaunaUser>(
|
|
211
|
-
fql`
|
|
245
|
+
fql`Collection(${collectionNames.user}).byEmail(${email}).first()`,
|
|
212
246
|
)
|
|
213
247
|
if (response.data === null) return null
|
|
214
248
|
return format.from(response.data)
|
|
215
249
|
},
|
|
216
250
|
async getUserByAccount({ provider, providerAccountId }) {
|
|
217
251
|
const response = await client.query<FaunaUser>(fql`
|
|
218
|
-
let account =
|
|
252
|
+
let account = Collection(${collectionNames.account}).byProviderAndProviderAccountId(${provider}, ${providerAccountId}).first()
|
|
219
253
|
if (account != null) {
|
|
220
|
-
|
|
254
|
+
Collection(${collectionNames.user}).byId(account.userId)
|
|
221
255
|
} else {
|
|
222
256
|
null
|
|
223
257
|
}
|
|
@@ -228,39 +262,39 @@ export function FaunaAdapter(client: Client): Adapter {
|
|
|
228
262
|
const _user: Partial<AdapterUser> = { ...user }
|
|
229
263
|
delete _user.id
|
|
230
264
|
const response = await client.query<FaunaUser>(
|
|
231
|
-
fql`
|
|
265
|
+
fql`Collection(${collectionNames.user}).byId(${user.id}).update(${format.to(_user)})`,
|
|
232
266
|
)
|
|
233
267
|
return format.from(response.data)
|
|
234
268
|
},
|
|
235
269
|
async deleteUser(userId) {
|
|
236
270
|
await client.query(fql`
|
|
237
271
|
// Delete the user's sessions
|
|
238
|
-
|
|
272
|
+
Collection(${collectionNames.session}).byUserId(${userId}).forEach(session => session.delete())
|
|
239
273
|
|
|
240
274
|
// Delete the user's accounts
|
|
241
|
-
|
|
275
|
+
Collection(${collectionNames.account}).byUserId(${userId}).forEach(account => account.delete())
|
|
242
276
|
|
|
243
277
|
// Delete the user
|
|
244
|
-
|
|
278
|
+
Collection(${collectionNames.user}).byId(${userId}).delete()
|
|
245
279
|
`)
|
|
246
280
|
},
|
|
247
281
|
async linkAccount(account) {
|
|
248
282
|
await client.query<FaunaAccount>(
|
|
249
|
-
fql`
|
|
283
|
+
fql`Collection(${collectionNames.account}).create(${format.to(account)})`,
|
|
250
284
|
)
|
|
251
285
|
return account
|
|
252
286
|
},
|
|
253
287
|
async unlinkAccount({ provider, providerAccountId }) {
|
|
254
288
|
const response = await client.query<FaunaAccount>(
|
|
255
|
-
fql`
|
|
289
|
+
fql`Collection(${collectionNames.account}).byProviderAndProviderAccountId(${provider}, ${providerAccountId}).first().delete()`,
|
|
256
290
|
)
|
|
257
291
|
return format.from<AdapterAccount>(response.data)
|
|
258
292
|
},
|
|
259
293
|
async getSessionAndUser(sessionToken) {
|
|
260
294
|
const response = await client.query<[FaunaUser, FaunaSession]>(fql`
|
|
261
|
-
let session =
|
|
295
|
+
let session = Collection(${collectionNames.session}).bySessionToken(${sessionToken}).first()
|
|
262
296
|
if (session != null) {
|
|
263
|
-
let user =
|
|
297
|
+
let user = Collection(${collectionNames.user}).byId(session.userId)
|
|
264
298
|
if (user != null) {
|
|
265
299
|
[user, session]
|
|
266
300
|
} else {
|
|
@@ -276,13 +310,13 @@ export function FaunaAdapter(client: Client): Adapter {
|
|
|
276
310
|
},
|
|
277
311
|
async createSession(session) {
|
|
278
312
|
await client.query<FaunaSession>(
|
|
279
|
-
fql`
|
|
313
|
+
fql`Collection(${collectionNames.session}).create(${format.to(session)})`,
|
|
280
314
|
)
|
|
281
315
|
return session
|
|
282
316
|
},
|
|
283
317
|
async updateSession(session) {
|
|
284
318
|
const response = await client.query<FaunaSession>(
|
|
285
|
-
fql`
|
|
319
|
+
fql`Collection(${collectionNames.session}).bySessionToken(${
|
|
286
320
|
session.sessionToken
|
|
287
321
|
}).first().update(${format.to(session)})`,
|
|
288
322
|
)
|
|
@@ -290,12 +324,12 @@ export function FaunaAdapter(client: Client): Adapter {
|
|
|
290
324
|
},
|
|
291
325
|
async deleteSession(sessionToken) {
|
|
292
326
|
await client.query(
|
|
293
|
-
fql`
|
|
327
|
+
fql`Collection(${collectionNames.session}).bySessionToken(${sessionToken}).first().delete()`,
|
|
294
328
|
)
|
|
295
329
|
},
|
|
296
330
|
async createVerificationToken(verificationToken) {
|
|
297
331
|
await client.query<FaunaVerificationToken>(
|
|
298
|
-
fql`
|
|
332
|
+
fql`Collection(${collectionNames.verificationToken}).create(${format.to(
|
|
299
333
|
verificationToken,
|
|
300
334
|
)})`,
|
|
301
335
|
)
|
|
@@ -303,12 +337,12 @@ export function FaunaAdapter(client: Client): Adapter {
|
|
|
303
337
|
},
|
|
304
338
|
async useVerificationToken({ identifier, token }) {
|
|
305
339
|
const response = await client.query<FaunaVerificationToken>(
|
|
306
|
-
fql`
|
|
340
|
+
fql`Collection(${collectionNames.verificationToken}).byIdentifierAndToken(${identifier}, ${token}).first()`,
|
|
307
341
|
)
|
|
308
342
|
if (response.data === null) return null
|
|
309
343
|
// Delete the verification token so it can only be used once
|
|
310
344
|
await client.query(
|
|
311
|
-
fql`
|
|
345
|
+
fql`Collection(${collectionNames.verificationToken}).byId(${response.data.id}).delete()`,
|
|
312
346
|
)
|
|
313
347
|
const _verificationToken: Partial<FaunaVerificationToken> = { ...response.data }
|
|
314
348
|
delete _verificationToken.id
|