Skip to content

Commit

Permalink
feat(adapters): let user configure MongoDB database name (#5290)
Browse files Browse the repository at this point in the history
* feat: added providing database name in options

* fix: added database name providing in readme

* Apply suggestions from code review

Co-authored-by: Balázs Orbán <info@balazsorban.com>
  • Loading branch information
AVStarikovich and balazsorban44 committed Sep 7, 2022
1 parent 6b3a82d commit 14b4ed1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/adapter-mongodb/README.md
Expand Up @@ -72,7 +72,9 @@ import clientPromise from "lib/mongodb"
// For more information on each option (and a full list of options) go to
// https://next-auth.js.org/configuration/options
export default NextAuth({
adapter: MongoDBAdapter(clientPromise),
adapter: MongoDBAdapter(clientPromise, {
databaseName: 'my-data-base-name'
}),
...
})
```
Expand Down
3 changes: 2 additions & 1 deletion packages/adapter-mongodb/src/index.ts
Expand Up @@ -17,6 +17,7 @@ export interface MongoDBAdapterOptions {
Sessions?: string
VerificationTokens?: string
}
databaseName?: string
}

export const defaultCollections: Required<
Expand Down Expand Up @@ -73,7 +74,7 @@ export function MongoDBAdapter(
const { from, to } = format

const db = (async () => {
const _db = (await client).db()
const _db = (await client).db(options.databaseName)
const c = { ...defaultCollections, ...collections }
return {
U: _db.collection<AdapterUser>(c.Users),
Expand Down

0 comments on commit 14b4ed1

Please sign in to comment.