Questions tagged [passport-local]

Authentication strategy for Passport JS using a username/email and password. Passport JS is authentication middleware for Node.js

866 questions
217
votes
11 answers

Passport.js - Error: failed to serialize user into session

I got a problem with the Passport.js module and Express.js. This is my code and I just want to use a hardcoded login for the first try. I always get the message: I searched a lot and found some posts in stackoverflow but I didnt get the…
user2244925
  • 2,314
  • 3
  • 14
  • 11
68
votes
6 answers

Sending back a JSON response when failing Passport.js authentication

I'm using Node.js as a backend API server for an iPhone client. I'm using Passport.js to authenticate with a local strategy. The relevant code is below: // This is in user.js, my user model UserSchema.static('authenticate', function(username,…
kurisukun
  • 3,149
  • 5
  • 37
  • 69
58
votes
21 answers

passport's req.isAuthenticated always returning false, even when I hardcode done(null, true)

I'm trying to get my Passport local strategy working. I've got this middleware set up: passport.use(new LocalStrategy(function(username, password, done) { //return done(null, user); if (username=='ben' && password=='benny'){ …
CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
30
votes
2 answers

How does passport js stores user object in session?

I am using node/express with passport in my development. I came across an article which says: Express loads the session data and attaches it to the req. As passport stores the serialised user in the session, the serialised user object can be found…
desmondlee
  • 1,643
  • 4
  • 21
  • 33
27
votes
1 answer

Passport local strategy done callback does not pass error json message

I am trying to pass a JSON message when authentication fails, using done callback in the LocalStrategy, but all I get is 401 and "Unauthorized" string in the response. var express = require('express'); var bodyParser = require('body-parser'); var…
milagvoniduak
  • 3,214
  • 1
  • 18
  • 18
27
votes
3 answers

Update logged in user details in session

I am using PassportJS with ExpressJS. I need to update the logged in user details. While I do update this in the DB, how do I update it in the session too so that request.user contains the updated user details? That is, after updating the database,…
callmekatootie
  • 10,989
  • 15
  • 69
  • 104
26
votes
9 answers

passport js missing credentials

Been working on this for a few hours now, pretty frustrating... router.post('/', passport.authenticate('local-signup', function(err, user, info) { console.log(err); }), function(req, res){ console.log(req); res.setHeader('Content-Type',…
l2silver
  • 3,283
  • 6
  • 23
  • 28
25
votes
5 answers

Passport local returns error 400 bad request with Angular

I am trying to integrate passport to my code's login form. Client side calling server side works as it should until i call passport.authenticate in the request, 400 Bad Request was returned. What am I missing here. HTML
Gene Lim
  • 1,068
  • 2
  • 14
  • 36
20
votes
7 answers

Passport: Allow sign up with name and email address? (Local Strategy)

Is there any way to allow a user to register on the local strategy with his password, email and name? Every example I could find online only use name/password or email/password. I also searched through the the whole passport documentation, but…
Forivin
  • 14,780
  • 27
  • 106
  • 199
17
votes
1 answer

Verification email with token in passport.js

I just looking for solution which makes verification email with token for my local autentification in passport.js Is there some plugin or component for node which can make me verification easyer? Or I have to do it myself? My…
Makromat
  • 1,540
  • 5
  • 26
  • 47
15
votes
2 answers

Can you authenticate with Passport without redirecting?

I have the following working code to authenticate through the passport-local strategy: app.post('/api/login', passport.authenticate('local-login', { successRedirect : '/api/login/success', failureRedirect : '/api/login/error', …
Hyra
  • 798
  • 1
  • 5
  • 21
14
votes
1 answer

how to get passport.authenticate local strategy working with async/await pattern

I've been failing to get passport.authenticate to work at all inside of an async/await or promise pattern. Here is an example I feel should work, but it fails to execute passport.authenticate(). const passport = require("passport"); let user; try…
Kyle Richardson
  • 5,567
  • 3
  • 17
  • 40
14
votes
2 answers

How to handle unauthorized requests with nodejs/passport

As per the documentation, if I was handling authentication requests like so, I would be able to capture successful attempts. app.post('/login', passport.authenticate('local'), function(req, res) { // If this function gets called,…
Adam K Dean
  • 7,387
  • 10
  • 47
  • 68
13
votes
4 answers

How to show custom error messages using passport and express

I check if the email already exist when registering a user. If a user already exist I pass the error message "email already exists". But in the front end it shows "Unauthorized" error 401. I want to pass the error message which I pass to the front…
shamila
  • 1,280
  • 6
  • 20
  • 45
12
votes
2 answers

Manually call passport for authentication

I develop a restful nodeJS API protected by a oauth2 authentication using passport. var express = require('express'); var passport = require('passport'); var port = process.env.PORT || 8080; var app = express(); …
Bob
  • 589
  • 1
  • 11
  • 25
1
2 3
57 58