Passport local authentication: deseralizeUser never calledWhat is the difference between call and apply?How do I return the response from an asynchronous call?phonegap ajax user authentication with nodejs-expresss-mongo-passportjsExpress4 and passport: Unable to authenticatePassport seems to forget the user sessionnot getting expected result while using passport in nodejs for authenticationPassport Authentication not working. Passport.serializeUser and passport.deserializeUser never called gets calledUnable to authenticate using email with passport-local nodejs..tried several examplesNodejs Passport authentication & local strategy not work through API Callpassport js deserialize user never gets called
Is a world with one country feeding everyone possible?
What is Orcus doing with Mind Flayers in the art on the last page of Volo's Guide to Monsters?
What is the use case for non-breathable waterproof pants?
Is keeping the forking link on a true fork necessary (Github/GPL)?
Flatten not working
Status of proof by contradiction and excluded middle throughout the history of mathematics?
Was this scene in S8E06 added because of fan reactions to S8E04?
Is it normal to "extract a paper" from a master thesis?
Why does FOO=bar; export the variable into my environment
Are there historical examples of audiences drawn to a work that was "so bad it's good"?
Does water in vacuum form a solid shell or freeze solid?
Possibility of faking someone's public key
Complications of displaced core material?
Is there a simple example that empirical evidence is misleading?
How can I minimize the damage of an unstable nuclear reactor to the surrounding area?
Is this homebrew "Cactus Grenade" cantrip balanced?
How would a developer who mostly fixed bugs for years at a company call out their contributions in their CV?
Did Game of Thrones end the way that George RR Martin intended?
Papers on ArXiv as main references
Did significant numbers of Japanese officers escape prosecution during the Tokyo Trials?
To exponential digit growth and beyond!
The disk image is 497GB smaller than the target device
Merge pdfs sequentially
Are cells guaranteed to get at least one mitochondrion when they divide?
Passport local authentication: deseralizeUser never called
What is the difference between call and apply?How do I return the response from an asynchronous call?phonegap ajax user authentication with nodejs-expresss-mongo-passportjsExpress4 and passport: Unable to authenticatePassport seems to forget the user sessionnot getting expected result while using passport in nodejs for authenticationPassport Authentication not working. Passport.serializeUser and passport.deserializeUser never called gets calledUnable to authenticate using email with passport-local nodejs..tried several examplesNodejs Passport authentication & local strategy not work through API Callpassport js deserialize user never gets called
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm testing passport-local authentication in a test app but I can't understand why deserializeUser is not called when sending a post request with Postman but never called when the post request comes from my front end (Vuejs).
I guess there's something wrong with my way of managing session but I don't know what... Could anyone help me to understand?
Vue frontend:
export default
name: "Login",
methods:
login: (e) =>
e.preventDefault();
let username = "user1";
let password = "password";
let login = () =>
let data =
username: username,
password: password
;
axios.post("http://localhost:5000/api/users", data)
.then((response) =>
console.log("Logged in");
router.push("/");
)
.catch((errors) =>
console.log("Cannot log in");
);
;
login();
Node backend:
app.use(cookieSession(
name: 'mysession',
keys: ['vueauthrandomkey'],
maxAge: 24 * 60 * 60 * 1000
));
app.use(passport.initialize());
app.use(passport.session());`
passport-config.js
`passport.use(new LocalStrategy(
function(username, password, done)
if(User[0].name == username)
return done(null, JSON.stringify(User[0]));
else
return done(null, false, message: 'Incorrect password.' );
));
passport.serializeUser((user, done) =>
done(null, user);
);
passport.deserializeUser((user, done) => // never called if request from Vuejs, no problem if the request is sent through Postam
done(null, user);
);
Router:
router.post('/',
passport.authenticate('local',
successRedirect: './',
failureRedirect: '/',
failureFlash: false
)
);
If successRedirect:
router.get('/', (req, res) =>
console.log(req.isAuthenticated()); // true if Postman, false if vuejs
res.send('welcome !!!');
);
javascript node.js vue.js passport.js
add a comment |
I'm testing passport-local authentication in a test app but I can't understand why deserializeUser is not called when sending a post request with Postman but never called when the post request comes from my front end (Vuejs).
I guess there's something wrong with my way of managing session but I don't know what... Could anyone help me to understand?
Vue frontend:
export default
name: "Login",
methods:
login: (e) =>
e.preventDefault();
let username = "user1";
let password = "password";
let login = () =>
let data =
username: username,
password: password
;
axios.post("http://localhost:5000/api/users", data)
.then((response) =>
console.log("Logged in");
router.push("/");
)
.catch((errors) =>
console.log("Cannot log in");
);
;
login();
Node backend:
app.use(cookieSession(
name: 'mysession',
keys: ['vueauthrandomkey'],
maxAge: 24 * 60 * 60 * 1000
));
app.use(passport.initialize());
app.use(passport.session());`
passport-config.js
`passport.use(new LocalStrategy(
function(username, password, done)
if(User[0].name == username)
return done(null, JSON.stringify(User[0]));
else
return done(null, false, message: 'Incorrect password.' );
));
passport.serializeUser((user, done) =>
done(null, user);
);
passport.deserializeUser((user, done) => // never called if request from Vuejs, no problem if the request is sent through Postam
done(null, user);
);
Router:
router.post('/',
passport.authenticate('local',
successRedirect: './',
failureRedirect: '/',
failureFlash: false
)
);
If successRedirect:
router.get('/', (req, res) =>
console.log(req.isAuthenticated()); // true if Postman, false if vuejs
res.send('welcome !!!');
);
javascript node.js vue.js passport.js
add a comment |
I'm testing passport-local authentication in a test app but I can't understand why deserializeUser is not called when sending a post request with Postman but never called when the post request comes from my front end (Vuejs).
I guess there's something wrong with my way of managing session but I don't know what... Could anyone help me to understand?
Vue frontend:
export default
name: "Login",
methods:
login: (e) =>
e.preventDefault();
let username = "user1";
let password = "password";
let login = () =>
let data =
username: username,
password: password
;
axios.post("http://localhost:5000/api/users", data)
.then((response) =>
console.log("Logged in");
router.push("/");
)
.catch((errors) =>
console.log("Cannot log in");
);
;
login();
Node backend:
app.use(cookieSession(
name: 'mysession',
keys: ['vueauthrandomkey'],
maxAge: 24 * 60 * 60 * 1000
));
app.use(passport.initialize());
app.use(passport.session());`
passport-config.js
`passport.use(new LocalStrategy(
function(username, password, done)
if(User[0].name == username)
return done(null, JSON.stringify(User[0]));
else
return done(null, false, message: 'Incorrect password.' );
));
passport.serializeUser((user, done) =>
done(null, user);
);
passport.deserializeUser((user, done) => // never called if request from Vuejs, no problem if the request is sent through Postam
done(null, user);
);
Router:
router.post('/',
passport.authenticate('local',
successRedirect: './',
failureRedirect: '/',
failureFlash: false
)
);
If successRedirect:
router.get('/', (req, res) =>
console.log(req.isAuthenticated()); // true if Postman, false if vuejs
res.send('welcome !!!');
);
javascript node.js vue.js passport.js
I'm testing passport-local authentication in a test app but I can't understand why deserializeUser is not called when sending a post request with Postman but never called when the post request comes from my front end (Vuejs).
I guess there's something wrong with my way of managing session but I don't know what... Could anyone help me to understand?
Vue frontend:
export default
name: "Login",
methods:
login: (e) =>
e.preventDefault();
let username = "user1";
let password = "password";
let login = () =>
let data =
username: username,
password: password
;
axios.post("http://localhost:5000/api/users", data)
.then((response) =>
console.log("Logged in");
router.push("/");
)
.catch((errors) =>
console.log("Cannot log in");
);
;
login();
Node backend:
app.use(cookieSession(
name: 'mysession',
keys: ['vueauthrandomkey'],
maxAge: 24 * 60 * 60 * 1000
));
app.use(passport.initialize());
app.use(passport.session());`
passport-config.js
`passport.use(new LocalStrategy(
function(username, password, done)
if(User[0].name == username)
return done(null, JSON.stringify(User[0]));
else
return done(null, false, message: 'Incorrect password.' );
));
passport.serializeUser((user, done) =>
done(null, user);
);
passport.deserializeUser((user, done) => // never called if request from Vuejs, no problem if the request is sent through Postam
done(null, user);
);
Router:
router.post('/',
passport.authenticate('local',
successRedirect: './',
failureRedirect: '/',
failureFlash: false
)
);
If successRedirect:
router.get('/', (req, res) =>
console.log(req.isAuthenticated()); // true if Postman, false if vuejs
res.send('welcome !!!');
);
javascript node.js vue.js passport.js
javascript node.js vue.js passport.js
edited Mar 29 at 22:19
kururin
asked Mar 23 at 22:02
kururinkururin
91127
91127
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
After browsing the entire web, I finally found the solution.
First I had to explicity ask axios to use credentials:
axios.defaults.withCredentials = true; // in the frontend
This config produced a CORS issue. To fix it I had to set my cors middleware as following server side:
app.use(cors(
origin: 'http://localhost:8080', // frontend base url
credentials: true
));
And now it's working.
Hope it will save time to people facing the same issue...
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55318806%2fpassport-local-authentication-deseralizeuser-never-called%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
After browsing the entire web, I finally found the solution.
First I had to explicity ask axios to use credentials:
axios.defaults.withCredentials = true; // in the frontend
This config produced a CORS issue. To fix it I had to set my cors middleware as following server side:
app.use(cors(
origin: 'http://localhost:8080', // frontend base url
credentials: true
));
And now it's working.
Hope it will save time to people facing the same issue...
add a comment |
After browsing the entire web, I finally found the solution.
First I had to explicity ask axios to use credentials:
axios.defaults.withCredentials = true; // in the frontend
This config produced a CORS issue. To fix it I had to set my cors middleware as following server side:
app.use(cors(
origin: 'http://localhost:8080', // frontend base url
credentials: true
));
And now it's working.
Hope it will save time to people facing the same issue...
add a comment |
After browsing the entire web, I finally found the solution.
First I had to explicity ask axios to use credentials:
axios.defaults.withCredentials = true; // in the frontend
This config produced a CORS issue. To fix it I had to set my cors middleware as following server side:
app.use(cors(
origin: 'http://localhost:8080', // frontend base url
credentials: true
));
And now it's working.
Hope it will save time to people facing the same issue...
After browsing the entire web, I finally found the solution.
First I had to explicity ask axios to use credentials:
axios.defaults.withCredentials = true; // in the frontend
This config produced a CORS issue. To fix it I had to set my cors middleware as following server side:
app.use(cors(
origin: 'http://localhost:8080', // frontend base url
credentials: true
));
And now it's working.
Hope it will save time to people facing the same issue...
answered Mar 24 at 21:12
kururinkururin
91127
91127
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55318806%2fpassport-local-authentication-deseralizeuser-never-called%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown