Closed thaDude closed 8 months ago
You'd need to encapsulate the two instances in separate plugins.
Thank you for your reply Matteo and sorry for the n00b question but how do I do this? Any examples are appreciated. I am using fastify-passport in a commonJS setting.
/David
Something like:
fastify.register(async (fastify) => {
const LocalStrategy = require('passport-local');
let passport1 = new Authenticator({ key: 'userAuth1', userProperty: 'user1' })
passport1.use('local-1', new LocalStrategy({},
function (username, password, done) {
if (username === _username1 && password == _password1) {
return done(null, {username});
}
return done('local-1: You got this wrong');
}));
fastify.register(passport1.initialize());
fastify.register(passport1.secureSession());
fastify.post("/login-password-1", {
preValidation: passport1.authenticate('local-1', {
failureMessage: true,
failWithError: true,
})
}, async function (request, reply) {
console.log(request.user)
reply.code(200).send({...request.user1})
})
})
Do the same for passport2
Prerequisites
Fastify version
4.17.0
Plugin version
2.3.0
Node.js version
16.2
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
14.2.1
Description
Hello,
I followed instructions as per documentation but the Fastify server does not start up with the error quoted below:
Best regards,
David
Steps to Reproduce
Expected Behavior
The fastify server should start up and I should have 2 authentication stacks.