@next-auth/fauna-adapter
Official Fauna adapter for Auth.js / NextAuth.js.
Installationβ
- npm
- yarn
- pnpm
npm install next-auth @next-auth/fauna-adapter faunadb
yarn add next-auth @next-auth/fauna-adapter faunadb
pnpm add next-auth @next-auth/fauna-adapter faunadb
FaunaAdapter()β
Setupβ
This is the Fauna Adapter for next-auth
. This package can only be used in conjunction with the primary next-auth
package. It is not a standalone package.
You can find the Fauna schema and seed information in the docs at authjs.dev/reference/adapters/fauna.
Configure Auth.jsβ
pages/api/auth/[...nextauth].js
import NextAuth from "next-auth"
import { Client as FaunaClient } from "faunadb"
import { FaunaAdapter } from "@next-auth/fauna-adapter"
const client = new FaunaClient({
secret: "secret",
scheme: "http",
domain: "localhost",
port: 8443,
})
// For more information on each option (and a full list of options) go to
// https://authjs.dev/reference/configuration/auth-options
export default NextAuth({
// https://authjs.dev/reference/providers/
providers: [],
adapter: FaunaAdapter(client)
...
})
Schemaβ
Run the following commands inside of the Shell
tab in the Fauna dashboard to setup the appropriate collections and indexes.
CreateCollection({ name: "accounts" });
CreateCollection({ name: "sessions" });
CreateCollection({ name: "users" });
CreateCollection({ name: "verification_tokens" });
CreateIndex({
name: "account_by_provider_and_provider_account_id",
source: Collection("accounts"),
unique: true,
terms: [
{ field: ["data", "provider"] },
{ field: ["data", "providerAccountId"] },
],
});
CreateIndex({
name: "session_by_session_token",
source: Collection("sessions"),
unique: true,
terms: [{ field: ["data", "sessionToken"] }],
});
CreateIndex({
name: "user_by_email",
source: Collection("users"),
unique: true,
terms: [{ field: ["data", "email"] }],
});
CreateIndex({
name: "verification_token_by_identifier_and_token",
source: Collection("verification_tokens"),
unique: true,
terms: [{ field: ["data", "identifier"] }, { field: ["data", "token"] }],
});
This schema is adapted for use in Fauna and based upon our main schema
FaunaAdapter(
f
:default
):Adapter
Parametersβ
Parameter | Type |
---|---|
f | default |
Returnsβ
Adapter
query()β
Fauna throws an error when something is not found in the db,
next-auth
expects null
to be returned
query(
f
:default
,format
:Function
):Function
Parametersβ
Parameter | Type |
---|---|
f | default |
format | (...args : any ) => any |
Returnsβ
Function
<T>(
expr
:ExprArg
):Promise
<null |T
>
Type parametersβ
T
Parametersβ
Parameter | Type |
---|---|
expr | ExprArg |
Returnsβ
Promise
<null | T
>