@auth/mongodb-adapter
Official MongoDB adapter for Auth.js / NextAuth.js.
Installation
npm install @auth/mongodb-adapter mongodb
MongoDBAdapterOptions
This is the interface of the MongoDB adapter options.
Properties
collections?
optional collections: {
Accounts: string;
Sessions: string;
Users: string;
VerificationTokens: string;
};
The name of the MongoDB collections.
Accounts?
optional Accounts: string;
Sessions?
optional Sessions: string;
Users?
optional Users: string;
VerificationTokens?
optional VerificationTokens: string;
databaseName?
optional databaseName: string;
The name you want to give to the MongoDB database
defaultCollections
const defaultCollections: Required<Required<MongoDBAdapterOptions>["collections"]>;
format
const format: {
from: T;
to: T & {
_id: ObjectId;
};
};
Type declaration
from()
Takes a MongoDB object and returns a plain old JavaScript object
Type parameters
Type parameter | Value |
---|---|
T | Record <string , unknown > |
Parameters
Parameter | Type |
---|---|
object | Record <string , any > |
Returns
T
to()
Takes a plain old JavaScript object and turns it into a MongoDB object
Type parameters
Type parameter | Value |
---|---|
T | Record <string , unknown > |
Parameters
Parameter | Type |
---|---|
object | Record <string , any > |
Returns
T
& {
_id
: ObjectId
;
}
MongoDBAdapter()
MongoDBAdapter(client, options): Adapter
Parameters
Parameter | Type |
---|---|
client | Promise <MongoClient > |
options | MongoDBAdapterOptions |