Registry /
security / mongo-passport-auth-lib
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default
✓ import auth from 'mongo-passport-auth-lib'
✗ const auth = require('mongo-passport-auth-lib')
Package uses default ESM export; do not destructure.
auth
✓ import { auth } from 'mongo-passport-auth-lib'
✗ const { auth } = require('mongo-passport-auth-lib')
Named export available from v0.0.50+; CommonJS require may fail.
passport
✓ import passport from 'passport'
✗ import { passport } from 'passport'
Passport is a default export, not named.
Shows basic usage: import default auth, connect Mongoose, authenticate with bearer token in Netlify function.
import auth from 'mongo-passport-auth-lib';
import mongoose from 'mongoose';
mongoose.connect(process.env.MONGO_URI ?? 'mongodb://localhost:27017/auth');
export const handler = async (event, context) => {
const { user, token } = await auth.authenticate(event.headers.authorization);
return {
statusCode: 200,
body: JSON.stringify({ user, token })
};
};
Debug
Known issues
breakingBreaking change in v0.0.50: auth.authenticate now returns object with user and token instead of just userfixUpdate call sites to destructure { user, token } from result. affects: >=0.0.50 <0.0.60
deprecatedauth.verifySession is deprecated since v0.0.55; use auth.validateToken insteadfixReplace verifySession calls with validateToken.
affects: >=0.0.55
deprecatedSupport for Node 12 removed; requires Node 14+fixUpgrade Node.js to version 14 or higher.
affects: >=0.0.60
Errors
Common errors & fixes
Error: Cannot find module 'passport'
passport not installed as dependency
fixRun npm install passport
TypeError: auth.authenticate is not a function
Wrong import: destructured named export instead of default
fixUse import auth from 'mongo-passport-auth-lib' (default) instead of import { auth } from ... Audit
Dependencies
passportrequiredAuthentication strategies
mongooserequiredMongoDB object modeling
expressrequiredHTTP request handling