@auth/fauna-adapter 2.2.0 → 3.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 +5 -6
- package/index.d.ts.map +1 -1
- package/index.js +9 -8
- package/package.json +2 -2
- package/src/index.ts +43 -22
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://fauna.com" target="_blank">
|
|
7
7
|
<img height="64px" src="https://authjs.dev/img/adapters/fauna.svg"/>
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding:
|
|
3
|
-
* <p style={{fontWeight: "
|
|
2
|
+
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: "16px"}}>
|
|
3
|
+
* <p style={{fontWeight: "300"}}>Official <a href="https://docs.fauna.com/fauna/current/">Fauna</a> adapter for Auth.js / NextAuth.js.</p>
|
|
4
4
|
* <a href="https://fauna.com/features">
|
|
5
5
|
* <img style={{display: "block"}} src="https://authjs.dev/img/adapters/fauna.svg" height="30"/>
|
|
6
6
|
* </a>
|
|
@@ -43,7 +43,7 @@ type AdapterConfig = {
|
|
|
43
43
|
*
|
|
44
44
|
* ### Configure Auth.js
|
|
45
45
|
*
|
|
46
|
-
* ```
|
|
46
|
+
* ```js title="pages/api/auth/[...nextauth].js"
|
|
47
47
|
* import NextAuth from "next-auth"
|
|
48
48
|
* import { Client } from "fauna"
|
|
49
49
|
* import { FaunaAdapter } from "@auth/fauna-adapter"
|
|
@@ -54,12 +54,11 @@ type AdapterConfig = {
|
|
|
54
54
|
* })
|
|
55
55
|
*
|
|
56
56
|
* // For more information on each option (and a full list of options) go to
|
|
57
|
-
* // https://authjs.dev/reference/
|
|
57
|
+
* // https://authjs.dev/reference/core/types#authconfig
|
|
58
58
|
* export default NextAuth({
|
|
59
|
-
* // https://authjs.dev/
|
|
59
|
+
* // https://authjs.dev/getting-started/authentication/oauth
|
|
60
60
|
* providers: [],
|
|
61
61
|
* adapter: FaunaAdapter(client)
|
|
62
|
-
* ...
|
|
63
62
|
* })
|
|
64
63
|
* ```
|
|
65
64
|
*
|
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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EACL,MAAM,EACN,QAAQ,EAGR,UAAU,EACV,gBAAgB,EAEjB,MAAM,OAAO,CAAA;AAEd,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,GACpC,QAAQ,GAAG,IAAI,GACf,CAAC,CAAC,CAAC,CAAC,SAAS,SAAS,GACpB,IAAI,GACJ,CAAC,CAAC,CAAC,CAAC,SAAS,UAAU,GACrB,CAAC,CAAC,CAAC,CAAC,GACJ,gBAAgB;CACzB,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA4KI;AACJ,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAsI5E;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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding:
|
|
3
|
-
* <p style={{fontWeight: "
|
|
2
|
+
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: "16px"}}>
|
|
3
|
+
* <p style={{fontWeight: "300"}}>Official <a href="https://docs.fauna.com/fauna/current/">Fauna</a> adapter for Auth.js / NextAuth.js.</p>
|
|
4
4
|
* <a href="https://fauna.com/features">
|
|
5
5
|
* <img style={{display: "block"}} src="https://authjs.dev/img/adapters/fauna.svg" height="30"/>
|
|
6
6
|
* </a>
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* @module @auth/fauna-adapter
|
|
16
16
|
*/
|
|
17
|
-
import { TimeStub, fql, NullDocument } from "fauna";
|
|
17
|
+
import { TimeStub, fql, NullDocument, } from "fauna";
|
|
18
18
|
const defaultCollectionNames = {
|
|
19
19
|
user: "User",
|
|
20
20
|
session: "Session",
|
|
@@ -31,7 +31,7 @@ const defaultCollectionNames = {
|
|
|
31
31
|
*
|
|
32
32
|
* ### Configure Auth.js
|
|
33
33
|
*
|
|
34
|
-
* ```
|
|
34
|
+
* ```js title="pages/api/auth/[...nextauth].js"
|
|
35
35
|
* import NextAuth from "next-auth"
|
|
36
36
|
* import { Client } from "fauna"
|
|
37
37
|
* import { FaunaAdapter } from "@auth/fauna-adapter"
|
|
@@ -42,12 +42,11 @@ const defaultCollectionNames = {
|
|
|
42
42
|
* })
|
|
43
43
|
*
|
|
44
44
|
* // For more information on each option (and a full list of options) go to
|
|
45
|
-
* // https://authjs.dev/reference/
|
|
45
|
+
* // https://authjs.dev/reference/core/types#authconfig
|
|
46
46
|
* export default NextAuth({
|
|
47
|
-
* // https://authjs.dev/
|
|
47
|
+
* // https://authjs.dev/getting-started/authentication/oauth
|
|
48
48
|
* providers: [],
|
|
49
49
|
* adapter: FaunaAdapter(client)
|
|
50
|
-
* ...
|
|
51
50
|
* })
|
|
52
51
|
* ```
|
|
53
52
|
*
|
|
@@ -291,7 +290,9 @@ export function FaunaAdapter(client, config) {
|
|
|
291
290
|
return null;
|
|
292
291
|
// Delete the verification token so it can only be used once
|
|
293
292
|
await client.query(fql `Collection(${collectionNames.verificationToken}).byId(${response.data.id}).delete()`);
|
|
294
|
-
const _verificationToken = {
|
|
293
|
+
const _verificationToken = {
|
|
294
|
+
...response.data,
|
|
295
|
+
};
|
|
295
296
|
delete _verificationToken.id;
|
|
296
297
|
return format.from(_verificationToken);
|
|
297
298
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auth/fauna-adapter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.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.30.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"fauna": "^1.3.1"
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding:
|
|
3
|
-
* <p style={{fontWeight: "
|
|
2
|
+
* <div style={{display: "flex", justifyContent: "space-between", alignItems: "center", padding: "16px"}}>
|
|
3
|
+
* <p style={{fontWeight: "300"}}>Official <a href="https://docs.fauna.com/fauna/current/">Fauna</a> adapter for Auth.js / NextAuth.js.</p>
|
|
4
4
|
* <a href="https://fauna.com/features">
|
|
5
5
|
* <img style={{display: "block"}} src="https://authjs.dev/img/adapters/fauna.svg" height="30"/>
|
|
6
6
|
* </a>
|
|
@@ -14,7 +14,15 @@
|
|
|
14
14
|
*
|
|
15
15
|
* @module @auth/fauna-adapter
|
|
16
16
|
*/
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
Client,
|
|
19
|
+
TimeStub,
|
|
20
|
+
fql,
|
|
21
|
+
NullDocument,
|
|
22
|
+
QueryValue,
|
|
23
|
+
QueryValueObject,
|
|
24
|
+
Module,
|
|
25
|
+
} from "fauna"
|
|
18
26
|
|
|
19
27
|
import type {
|
|
20
28
|
Adapter,
|
|
@@ -25,7 +33,13 @@ import type {
|
|
|
25
33
|
} from "@auth/core/adapters"
|
|
26
34
|
|
|
27
35
|
type ToFauna<T> = {
|
|
28
|
-
[P in keyof T]: T[P] extends Date | null
|
|
36
|
+
[P in keyof T]: T[P] extends Date | null
|
|
37
|
+
? TimeStub | null
|
|
38
|
+
: T[P] extends undefined
|
|
39
|
+
? null
|
|
40
|
+
: T[P] extends QueryValue
|
|
41
|
+
? T[P]
|
|
42
|
+
: QueryValueObject
|
|
29
43
|
}
|
|
30
44
|
|
|
31
45
|
export type FaunaUser = ToFauna<AdapterUser>
|
|
@@ -59,7 +73,7 @@ const defaultCollectionNames = {
|
|
|
59
73
|
*
|
|
60
74
|
* ### Configure Auth.js
|
|
61
75
|
*
|
|
62
|
-
* ```
|
|
76
|
+
* ```js title="pages/api/auth/[...nextauth].js"
|
|
63
77
|
* import NextAuth from "next-auth"
|
|
64
78
|
* import { Client } from "fauna"
|
|
65
79
|
* import { FaunaAdapter } from "@auth/fauna-adapter"
|
|
@@ -70,12 +84,11 @@ const defaultCollectionNames = {
|
|
|
70
84
|
* })
|
|
71
85
|
*
|
|
72
86
|
* // For more information on each option (and a full list of options) go to
|
|
73
|
-
* // https://authjs.dev/reference/
|
|
87
|
+
* // https://authjs.dev/reference/core/types#authconfig
|
|
74
88
|
* export default NextAuth({
|
|
75
|
-
* // https://authjs.dev/
|
|
89
|
+
* // https://authjs.dev/getting-started/authentication/oauth
|
|
76
90
|
* providers: [],
|
|
77
91
|
* adapter: FaunaAdapter(client)
|
|
78
|
-
* ...
|
|
79
92
|
* })
|
|
80
93
|
* ```
|
|
81
94
|
*
|
|
@@ -229,20 +242,20 @@ export function FaunaAdapter(client: Client, config?: AdapterConfig): Adapter {
|
|
|
229
242
|
return {
|
|
230
243
|
async createUser(user) {
|
|
231
244
|
const response = await client.query<FaunaUser>(
|
|
232
|
-
fql`Collection(${collectionNames.user}).create(${format.to(user)})
|
|
245
|
+
fql`Collection(${collectionNames.user}).create(${format.to(user)})`
|
|
233
246
|
)
|
|
234
247
|
return format.from(response.data)
|
|
235
248
|
},
|
|
236
249
|
async getUser(id) {
|
|
237
250
|
const response = await client.query<FaunaUser | NullDocument>(
|
|
238
|
-
fql`Collection(${collectionNames.user}).byId(${id})
|
|
251
|
+
fql`Collection(${collectionNames.user}).byId(${id})`
|
|
239
252
|
)
|
|
240
253
|
if (response.data instanceof NullDocument) return null
|
|
241
254
|
return format.from(response.data)
|
|
242
255
|
},
|
|
243
256
|
async getUserByEmail(email) {
|
|
244
257
|
const response = await client.query<FaunaUser>(
|
|
245
|
-
fql`Collection(${collectionNames.user}).byEmail(${email}).first()
|
|
258
|
+
fql`Collection(${collectionNames.user}).byEmail(${email}).first()`
|
|
246
259
|
)
|
|
247
260
|
if (response.data === null) return null
|
|
248
261
|
return format.from(response.data)
|
|
@@ -262,7 +275,9 @@ export function FaunaAdapter(client: Client, config?: AdapterConfig): Adapter {
|
|
|
262
275
|
const _user: Partial<AdapterUser> = { ...user }
|
|
263
276
|
delete _user.id
|
|
264
277
|
const response = await client.query<FaunaUser>(
|
|
265
|
-
fql`Collection(${collectionNames.user}).byId(${
|
|
278
|
+
fql`Collection(${collectionNames.user}).byId(${
|
|
279
|
+
user.id
|
|
280
|
+
}).update(${format.to(_user)})`
|
|
266
281
|
)
|
|
267
282
|
return format.from(response.data)
|
|
268
283
|
},
|
|
@@ -280,13 +295,15 @@ export function FaunaAdapter(client: Client, config?: AdapterConfig): Adapter {
|
|
|
280
295
|
},
|
|
281
296
|
async linkAccount(account) {
|
|
282
297
|
await client.query<FaunaAccount>(
|
|
283
|
-
fql`Collection(${collectionNames.account}).create(${format.to(
|
|
298
|
+
fql`Collection(${collectionNames.account}).create(${format.to(
|
|
299
|
+
account
|
|
300
|
+
)})`
|
|
284
301
|
)
|
|
285
302
|
return account
|
|
286
303
|
},
|
|
287
304
|
async unlinkAccount({ provider, providerAccountId }) {
|
|
288
305
|
const response = await client.query<FaunaAccount>(
|
|
289
|
-
fql`Collection(${collectionNames.account}).byProviderAndProviderAccountId(${provider}, ${providerAccountId}).first().delete()
|
|
306
|
+
fql`Collection(${collectionNames.account}).byProviderAndProviderAccountId(${provider}, ${providerAccountId}).first().delete()`
|
|
290
307
|
)
|
|
291
308
|
return format.from<AdapterAccount>(response.data)
|
|
292
309
|
},
|
|
@@ -310,7 +327,9 @@ export function FaunaAdapter(client: Client, config?: AdapterConfig): Adapter {
|
|
|
310
327
|
},
|
|
311
328
|
async createSession(session) {
|
|
312
329
|
await client.query<FaunaSession>(
|
|
313
|
-
fql`Collection(${collectionNames.session}).create(${format.to(
|
|
330
|
+
fql`Collection(${collectionNames.session}).create(${format.to(
|
|
331
|
+
session
|
|
332
|
+
)})`
|
|
314
333
|
)
|
|
315
334
|
return session
|
|
316
335
|
},
|
|
@@ -318,33 +337,35 @@ export function FaunaAdapter(client: Client, config?: AdapterConfig): Adapter {
|
|
|
318
337
|
const response = await client.query<FaunaSession>(
|
|
319
338
|
fql`Collection(${collectionNames.session}).bySessionToken(${
|
|
320
339
|
session.sessionToken
|
|
321
|
-
}).first().update(${format.to(session)})
|
|
340
|
+
}).first().update(${format.to(session)})`
|
|
322
341
|
)
|
|
323
342
|
return format.from(response.data)
|
|
324
343
|
},
|
|
325
344
|
async deleteSession(sessionToken) {
|
|
326
345
|
await client.query(
|
|
327
|
-
fql`Collection(${collectionNames.session}).bySessionToken(${sessionToken}).first().delete()
|
|
346
|
+
fql`Collection(${collectionNames.session}).bySessionToken(${sessionToken}).first().delete()`
|
|
328
347
|
)
|
|
329
348
|
},
|
|
330
349
|
async createVerificationToken(verificationToken) {
|
|
331
350
|
await client.query<FaunaVerificationToken>(
|
|
332
351
|
fql`Collection(${collectionNames.verificationToken}).create(${format.to(
|
|
333
|
-
verificationToken
|
|
334
|
-
)})
|
|
352
|
+
verificationToken
|
|
353
|
+
)})`
|
|
335
354
|
)
|
|
336
355
|
return verificationToken
|
|
337
356
|
},
|
|
338
357
|
async useVerificationToken({ identifier, token }) {
|
|
339
358
|
const response = await client.query<FaunaVerificationToken>(
|
|
340
|
-
fql`Collection(${collectionNames.verificationToken}).byIdentifierAndToken(${identifier}, ${token}).first()
|
|
359
|
+
fql`Collection(${collectionNames.verificationToken}).byIdentifierAndToken(${identifier}, ${token}).first()`
|
|
341
360
|
)
|
|
342
361
|
if (response.data === null) return null
|
|
343
362
|
// Delete the verification token so it can only be used once
|
|
344
363
|
await client.query(
|
|
345
|
-
fql`Collection(${collectionNames.verificationToken}).byId(${response.data.id}).delete()
|
|
364
|
+
fql`Collection(${collectionNames.verificationToken}).byId(${response.data.id}).delete()`
|
|
346
365
|
)
|
|
347
|
-
const _verificationToken: Partial<FaunaVerificationToken> = {
|
|
366
|
+
const _verificationToken: Partial<FaunaVerificationToken> = {
|
|
367
|
+
...response.data,
|
|
368
|
+
}
|
|
348
369
|
delete _verificationToken.id
|
|
349
370
|
return format.from(_verificationToken)
|
|
350
371
|
},
|