Open maooricio opened 6 years ago
Well, after 1 day of prove all the things, I decided to put some logic, taking into account that the problem comes from the async function that uses 'bluebird' to resolve Promises. The thing here is that in development, the webpack plugins accept the PassportJS connection as Promises, but when I compiled my app to production was mandatory to use async/await to resolve Promises, and PassportJS as itself do not work well with async functions. So we have to do manually. You have to manage the strategy with async/await manually as follows:
exports.localStrategy = new LocalStrategy({
usernameField: 'userclient',
passwordField: 'password',
session: false,
passReqToCallback: true
}, async (req, userclient, password, done) => {
var authData = {
userclient,
password
}
var authToken = await ClientApi.authenticate(authData);
if(authToken) {
var token = authToken.data
var user = await ClientApi.getClient(userclient);
if (user) {
user.token = token
const userData = {
id: (user.data.client_id) ? user.data.client_id : user.data.clientId,
userclient: (user.data.userclient) ? user.data.userclient : ((user.data.sellerUserName) ? user.data.sellerUserName : user.data.kitchenUserName),
codeOfSeller: (user.data.client_id) ? false : ((user.data.codeOfSeller) ? user.data.codeOfSeller : 'kitchenSeller'),
token: user.token
};
done(null, userData, token);
} else {
done(err);
}
} else {
done(err);
}
})
Hope it helps to someone, I really wasted many time, but I learnt. If you want you can declare this issue as closed
Hi,
I am using passport to make the login routine of the users of my app. My app is developed in React, and I am using webpack as my bundler. When I compile my app in a development environment all works fine, but when I compile it in a production environment using webpack, it throws me the following error:
I read a lot about this issue but none of the solutions works with me. What I am missing? What I am doing worng? In advance thanks for anything that help me.
Here is my webpack server configuration
Here is my webpack client configuration
And here is the node function where I call the passport strategy to make the authentication: