next-auth-couchbase-adapter
v0.0.7
Published
Couchbase adapter for next-auth.
Downloads
8
Maintainers
Readme
Overview
This is the Couchbase Adapter for next-auth
. This package can only be used in conjunction with the primary next-auth
package. It is not a standalone package.
This adapter uses Ottoman ODM to connect next-auth
to Couchbase.
Getting Started
- Install
[email protected]
andnext-auth-couchbase-adapter
, as well asottoman
. (Ottoman depends on Couchbase Node SDK, which is included as a dep in ottoman, so no need to install couchbase)
npm install [email protected] next-auth-couchbase-adapter ottoman
- Add this adapter to your
pages/api/[...nextauth].ts
next-auth configuration object.
import NextAuth, { Profile } from "next-auth";
import { OAuthConfig } from "next-auth/providers";
import Google from "next-auth/providers/google";
import CouchbaseAdapter, { adapterOptions } from "next-auth-couchbase-adapter";
const options: adapterOptions = {
connectionString: "couchbase://localhost",
bucketName: "connext",
username: "Administrator",
password: "1234567890",
// ensure collections and indexes for quick setup in development (DON'T DO THIS IN PRODUCTION)
ensureCollections: true,
ensureIndexes: true,
};
export default NextAuth({
// Configure one or more authentication providers
providers: [
Google({
clientId: process.env.GOOGLE_ID as string,
clientSecret: process.env.GOOGLE_SECRET as string,
}) as OAuthConfig<Profile>,
],
jwt: {
secret: process.env.SECRET as string,
},
adapter: CouchbaseAdapter(options),
// ...
})
Custom Collection Names
In the options objection you can add a collectionNames
property to name the next-auth collections (models) whatever you would like:
const options: adapterOptions = {
connectionString: "couchbase://localhost",
// ...
collectionNames: {
User: "WhateverUser", // default is User
Account: "WhateverAccount", // default is UserAccount
Session: "WhateverSession", // default is UserSession
VerificationToken: "WhateverToken", // default is UserVerificationToken
},
}
Using your own ottoman instance
You can use your own ottoman instance if you already have a module setup that you would like to reuse, just need a reference to the Ottoman instance and make sure you export your connection settings so the couchbase adapter can connect if needed.
// somewhere.ts <--- your module file
const ottoman = new Ottoman()
const connectionOptions = {
connectionString: "couchbase://localhost",
bucketName: "connext",
username: "Administrator",
password: "1234567890",
}
export { connectionOptions }
export default ottoman
and then in the nextauth route:
// [...nextauth].ts file
import yourOttomanInstance, { connectionOptions } from "somewhere"
const options: adapterOptions = {
instance: yourOttomanInstance,
...connectionOptions,
}
Contributing
We're open to all community contributions! If you'd like to contribute in any way, please read our Contributing Guide.
License
ISC