@next-auth/mongodb-adapter
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -0,4 +1,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MongoDBAdapter = exports._id = exports.format = exports.defaultCollections = void 0; | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { ObjectId } from "mongodb"; | ||
export const defaultCollections = { | ||
const mongodb_1 = require("mongodb"); | ||
exports.defaultCollections = { | ||
Users: "users", | ||
@@ -9,3 +12,3 @@ Accounts: "accounts", | ||
}; | ||
export const format = { | ||
exports.format = { | ||
/** Takes a mongoDB object and returns a plain old JavaScript object */ | ||
@@ -46,13 +49,14 @@ from(object) { | ||
/** Converts from string to ObjectId */ | ||
export function _id(hex) { | ||
function _id(hex) { | ||
if ((hex === null || hex === void 0 ? void 0 : hex.length) !== 24) | ||
return new ObjectId(); | ||
return new ObjectId(hex); | ||
return new mongodb_1.ObjectId(); | ||
return new mongodb_1.ObjectId(hex); | ||
} | ||
export function MongoDBAdapter(client, options = {}) { | ||
exports._id = _id; | ||
function MongoDBAdapter(client, options = {}) { | ||
const { collections } = options; | ||
const { from, to } = format; | ||
const { from, to } = exports.format; | ||
const db = (async () => { | ||
const _db = (await client).db(); | ||
const c = { ...defaultCollections, ...collections }; | ||
const c = { ...exports.defaultCollections, ...collections }; | ||
return { | ||
@@ -87,3 +91,3 @@ U: _db.collection(c.Users), | ||
return null; | ||
const user = await (await db).U.findOne({ _id: new ObjectId(account.userId) }); | ||
const user = await (await db).U.findOne({ _id: new mongodb_1.ObjectId(account.userId) }); | ||
if (!user) | ||
@@ -120,3 +124,3 @@ return null; | ||
return null; | ||
const user = await (await db).U.findOne({ _id: new ObjectId(session.userId) }); | ||
const user = await (await db).U.findOne({ _id: new mongodb_1.ObjectId(session.userId) }); | ||
if (!user) | ||
@@ -160,1 +164,2 @@ return null; | ||
} | ||
exports.MongoDBAdapter = MongoDBAdapter; |
{ | ||
"name": "@next-auth/mongodb-adapter", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "mongoDB adapter for next-auth.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://next-auth.js.org", |
10666
181