fastify-passport: fastifyPassport.initialize is not a function
🐛 Bug Report
A clear and concise description of what the bug is.
To Reproduce
Steps to reproduce the behavior:
// Paste your code here
const fastify = require('fastify')();
const fastifyPassport= require('fastify-passport')
const fastifySecureSession= require('fastify-secure-session')
// set up secure sessions for fastify-passport to store data in
fastify.register(fastifySecureSession, { key: fs.readFileSync(path.join(__dirname, "secret-key")) });
// initialize fastify-passport and connect it to the secure-session storage. Note: both of these plugins are mandatory.
fastify.register(fastifyPassport.initialize());
fastify.register(fastifyPassport.secureSession());
console.log(fastifyPassport);
Error FastifyPassport.initialize is not a function
Expected behavior
A clear and concise description of what you expected to happen.
fastifyPassport.initialize should initialize passport
also on same note when someone console `fastifyPassport`
below appears
{
Strategy: [Getter],
default: Authenticator {
key: 'passport',
userProperty: 'user',
strategies: { session: [SessionStrategy] },
serializers: [],
deserializers: [],
infoTransformers: [],
sessionManager: SecureSessionManager {
key: 'passport',
serializeUser: [Function: bound serializeUser] AsyncFunction
}
}
}
Your Environment
- node version: v14.15.1
- fastify version: >=^3.9.1
- os: windows-wsl-ubuntu
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 17 (11 by maintainers)
Commits related to this issue
- for https://github.com/fastify/fastify-passport/issues/36 reproduction — committed to matt212/Nodejs_Postgresql_VanillaJS_Fastify by matt212 4 years ago
- fastify issue resolved by inputs from repo stakeholder https://github.com/fastify/fastify-passport/issues/36 — committed to matt212/Nodejs_Postgresql_VanillaJS_Fastify by matt212 4 years ago
Yes, there are 2 viable solutions:
.default
prop ifexport default
is used).default
property (CJS and older Node.js versions mainly)@Melodyn I’ve just seen that your file is a
.js
one, so you are not using anyesModuleInterop: true
since your context is a CJS context and your case is the same as @matt212 one. In fact, your fix is just to add.default
.Thanks for the bug report. Super weird. Which version of
fastify-passport
are you experiencing this on?