Skip to content
This repository has been archived by the owner on Jul 17, 2022. It is now read-only.

Migrate faunadb adapter to TS #43

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion packages/fauna/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Fauna Adapter

### Initial Setup
## Initial Setup

Run these FQL queries in your Fauna dashboard _one after another_.

```javascript
CreateCollection({ name: 'accounts' })
Expand Down Expand Up @@ -35,3 +37,32 @@ CreateIndex({
terms: [{ field: ['data', 'token'] }],
})
```

## Usage

Your `pages/api/auth/[...nextauth].ts` file may look like this

```ts
import { Client } from 'faunadb'
import { NextApiHandler } from 'next'
import NextAuth, { InitOptions } from 'next-auth'
import FaunaAdapter from '@next-auth/fauna-adapter'

const faunaSecret = process.env.FAUNA_SECRET

if (!faunaSecret) throw new Error(`Env variable FAUNA_SECRET must be set`)

const faunaAdapter = FaunaAdapter({
faunaClient: new Client({
secret: faunaSecret,
}),
})

const options: InitOptions = {
adapter: faunaAdapter,
}

const authHandler: NextApiHandler = (req, res) => NextAuth(req, res, options)

export default authHandler
```
10 changes: 9 additions & 1 deletion packages/fauna/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@
"name": "@next-auth/fauna-adapter",
"version": "0.0.0",
"description": "",
"main": "src/index.js",
"main": "dist/index.js",
"private": false,
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "tsc"
},
"author": "Bhanu Teja P",
"license": "ISC",
"peerDependencies": {
"faunadb": "^4.1.1",
"next-auth": "^3.11.2"
},
"devDependencies": {
"faunadb": "^4.1.1",
"next-auth": "^3.11.2",
"typescript": "^4.1.3"
}
}
Loading