Questions tagged [passport-local]

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

passport-local
Filter by
Sorted by
Tagged with
60 votes
20 answers
61k views

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 (...
CodyBugstein's user avatar
  • 22.7k
69 votes
6 answers
61k views

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 ...
kurisukun's user avatar
  • 3,149
30 votes
2 answers
29k views

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 ...
desmondlee's user avatar
  • 1,703
27 votes
10 answers
34k views

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....
l2silver's user avatar
  • 3,353
15 votes
2 answers
15k views

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', ...
Hyra's user avatar
  • 828
0 votes
2 answers
1k views

Passport js local strategy custom callback showing user as false and info as “Missing credentials”

I am using Node.js,angularjs,express and passport. I have tried all options I can think of, but still no solution. Couldn't find a solution from other posts for this problem. app.post('/login', ...
charan tej's user avatar
  • 1,054
219 votes
11 answers
133k views

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 ...
user2244925's user avatar
  • 2,344
27 votes
3 answers
11k views

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 ...
callmekatootie's user avatar
20 votes
7 answers
20k views

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 ...
Forivin's user avatar
  • 15.1k
12 votes
3 answers
8k views

NestJS' Passport Local Strategy "validate" method never called

I'm trying to implement a Passport Local Strategy but the validate method is not working. When I do @UseGuards(AuthGuard("local")), it automatically throws an Unauthorized Exception without ...
Skull Cutter's user avatar
10 votes
2 answers
4k views

Passport authentication not working in sails.js application

I have a Sails JS application. I am trying to setup authentication using Passport.js authentication layer sails-generate-auth. I have configured my app by following the steps given in their ...
Yedhu Krishnan's user avatar
7 votes
1 answer
7k views

req.session.passport and req.user empty, serializeUser and deserializeUser are never called

I'm using Express (v4.11.2) with Passport in order to support multiple providers (local, facebook, twitter and google) for access to the web app I'm building. As a backend I'm using mysql. For now I ...
Neman's user avatar
  • 369
5 votes
3 answers
4k views

Support for multiple user types by Passport-local mongoose node.js

I wanted two types of users logging in (User, Client). How exactly can I create localStrategies, serialize and deserialize user for both types in my app.js I have two separate schemas, both using the ...
Abhijit S's user avatar
  • 319
1 vote
1 answer
920 views

Passport.js redirects to |successRedirect: '/profile'| but req.isAuthenticated() returns false

The following code is a section of an app developed by Node.js + Express + Passport.js. A valid user gets redirected to /profile url (successRedirect), however the req.isAuthenticated returns false ...
Megidd's user avatar
  • 7,459
0 votes
2 answers
5k views

Passport Authenticate doesn't redirect

I was writing a local-signup strategy and noticed that it doesn't work so I stepped back and tried to authenticate against my empty collection. Every time I submit the form it takes ~30-40s until it ...
kentor's user avatar
  • 17.5k
25 votes
6 answers
20k views

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 ...
Gene Lim's user avatar
  • 1,068
15 votes
1 answer
11k views

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(). ...
Kyle Richardson's user avatar
13 votes
4 answers
17k views

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 ...
shamila's user avatar
  • 1,290
10 votes
3 answers
4k views

NestJS/GraphQL/Passport - getting unauthorised error from guard

I'm trying to follow along with this tutorial and I'm struggling to convert the implementation to GraphQL. local.strategy.ts @Injectable() export class LocalStrategy extends PassportStrategy(Strategy) ...
Ellie G's user avatar
  • 259
9 votes
6 answers
13k views

how to send json as a response after passport authenticationin node.js

I am trying this git example. Which works well when I integrated it with my project, but what I want to achieve is to send json as a response to the client/request, instead of successRedirect : '/...
pitu's user avatar
  • 820
8 votes
3 answers
8k views

TypeError: req.logIn is not a function - Passport JS

I'm pretty sure this is not a bug since googling it hasn't turned anything up. I'm using passport JS with the local strategy. On my login route I'm using a custom callback and calling req.login once ...
chap's user avatar
  • 1,860
7 votes
1 answer
2k views

Session is not correctly obtained from a storage, using express-session and passportjs

I'm using passport, express-session and connect-pg-simple. The problem is that session is not correctly obtained from a storage, where it gets properly (i hope, but doubt) saved. My setup is the ...
AntonAL's user avatar
  • 17k
7 votes
3 answers
3k views

Authentication is returning "401 (Unauthorized)" when it shouldn't

I am setting up an authentication functionality for my first time and am getting some unexpected results after a user has been logged in. A colleague has given me an application with working ...
Zach Cook's user avatar
  • 614
6 votes
1 answer
299 views

Mean.js req.isAuthenticated is showing fail?

i have downloaded meanjs [email protected] i have used two servers for front end i hvae used angular with ionic its running in localhost:3000,for backend i have used meanjs.in that meanjs i have ...
user avatar
5 votes
5 answers
10k views

NestJS and passport-local : AuthGuard('local') validate() never get called

I've followed the official Nest doc (https://docs.nestjs.com/security/authentication) step by step, but I can't get validate() method called when using @AuthGuard('local') or @AuthGuard(LocalAuthGuard)...
Gigs's user avatar
  • 349
5 votes
8 answers
9k views

passport-local-mongoose: createStrategy is not a function / authenticate is not a function

I'm building on top of this starter project and trying to add user login with passport-local-mongoose. Depending on which of the two ways I try to use the strategy I'm getting either this error: [1] ...
LJNielsenDk's user avatar
  • 1,450
4 votes
1 answer
938 views

Simple Auth With Passport-Local and deSerializeUser problem

After reading an excellent description here on how deserialize and serialize user works in the Passport flow Understanding passport serialize deserialize I'm concerned about the performance impact ...
Peter Kellner's user avatar
4 votes
2 answers
4k views

Node.js / Express: POST being turned into GET (code 302)

In brief, I have a login page where my POST request is turning into a GET in Express 4. Here is the business part of my login page: <form id='loginForm' action='/login' method='post'> <...
Jerome P Mrozak's user avatar
4 votes
1 answer
4k views

Does the passport.js support ajax?

I want to make ajax login with the passport.js. I have the usual code for setting the passport.js: //route app.post('/api/auth/login', passport.authenticate('local-login', { successRedirect: '/', ...
user348173's user avatar
  • 9,118
4 votes
1 answer
2k views

Passport.js strategy with no field required

I'm surprised that it's so hard to find, or maybe something wrong with me. I need a passport.js strategy that requires no fields - to run authentication with it on simple user GET request to '/' and ...
Max Yari's user avatar
  • 3,627
4 votes
2 answers
1k views

Using Passport for Authentication of API Endpoints

Following a couple tutorials on adding authentication using jsonwebtoken, passport, and passport-local I've become stuck on integrating it into my project. I want it so that any requests to any of the ...
gh0st's user avatar
  • 1,682
3 votes
1 answer
2k views

Additional fields to passport-local-mongoose account registration?

I'm using passport-local-mongoose with Node.js, Express.js, MongoDB for a webapp, and I want to register users with a username field, a password field, a company name field, and a phone number field (...
Y-M's user avatar
  • 75
3 votes
3 answers
7k views

NestJS Authentification with JWT Passport not working

I am trying to set up a very simple login system using jwt-passport with nestjs. I followed this tutorial: https://docs.nestjs.com/techniques/authentication but I just can't get it to work. I am ...
xDrago's user avatar
  • 1,962
3 votes
2 answers
13k views

Passport-local-mongoose : Authenticate user right after registration

I am trying to use passport-local-mongoose to authenticate a user after submitting a POST on the /register form. I can't figure out why i always get "unauthorized" & oddly no data is submitted on ...
TasDePixels's user avatar
2 votes
1 answer
3k views

passport.js session lost after redirect

I am trying to integrate passport into my node.js app. app.js file const app = express(); app.set('view engine', 'pug'); app.use('/libs', express.static('node_modules')); require('../config/auth....
Ivan Mladenov's user avatar
2 votes
1 answer
8k views

Having issues with integrating passport-local with restify

My sample application is as follows var util = require("util") restify = require("restify"), q = require("q"), _ = require("lodash"); //Create Server var server = restify.createServer({ ...
indigo0086's user avatar
2 votes
1 answer
784 views

Express router create a new session not wanted

I am doing a react project using express and passport-local for the authentication part based on this tutorial : https://scotch.io/tutorials/easy-node-authentication-setup-and-local The ...
fandro's user avatar
  • 4,873
2 votes
1 answer
4k views

Browser Back Button doesn't destroy the session in PassportJS + ExpressJS. How to kill/terminate the session entirely?

The code for my Logout Mechanism is app.get('/logout', isLoggedIn, function(req, res) { req.logout(); res.redirect('/'); }); Am using a Express-session package using a secret ...
godimedia's user avatar
  • 997
2 votes
2 answers
7k views

getting bad request while using passport in login form

I am trying to create a user login [.ejs file] form using passport local session in nodejs. My problem is that I keep on getting bad request when I hit on the submit button,can anyone please check my ...
Celestine's user avatar
2 votes
2 answers
3k views

LocalAuthGuard not working in nestjs app with typeorm and passport-local

I am using nestjs 8.0 with typeorm, passport-jwt, and passport-local. Everything seems to be working fine other than the LocalAuthGuard. I am able to successfully create a new user and even use the ...
Shiladitya Thakur's user avatar
2 votes
1 answer
5k views

Passport.js throwing "undefined is not a function" with LocalStrategy

I am implementing local authentication using Passport.js. I have already implemented Github Oauth, which is fine but for some reason the local strategy is failing with the above error. I cannot find ...
user avatar
1 vote
2 answers
4k views

Lose cookie/session when reload page

I have two separate applications: AngularJS client working on http://localhost:8080 NodeJS API server working on http://localhost:3000 NodeJS API Server just gives json data to client (and does not ...
HelterShelter's user avatar
1 vote
1 answer
1k views

PassportJS(Local) with Sequelize and Express stuck on pending after serializing user

I'm trying to make login work, using the tutorial I've found in http://code.tutsplus.com/tutorials/authenticating-nodejs-applications-with-passport--cms-21619. I modified the code to work with ...
Kylie's user avatar
  • 83
1 vote
1 answer
641 views

Passport local strategy auth seems to only work on localhost with a shared MongoDB instance

This is a weird one, but I'm not sure what else could be going on. I've successfully deployed the passport-local strategy for a Node.js Express app with user accounts stored in MongoDB. I'm using ...
Matt Vukas's user avatar
  • 3,255
1 vote
0 answers
710 views

Passport.js - Local strategy doesn't authenticate

I've build a simple app that allows users to log in through google using passport's google strategy and it all works fine. I'm trying to add a local strategy as well, but I can't find a solution. ...
robruf's user avatar
  • 131
1 vote
1 answer
3k views

Passport local returns error 400 bad request with postman

Hi i am getting 400 Bad Request error every time i use passport local. Please tell me where i am doing something wrong. I am trying to call my /login route using postman but every time i am getting ...
vishal's user avatar
  • 53
1 vote
1 answer
2k views

passport local type error

I'm trying to use passport-local for authentication in my Sails project. In my controller: passport.authenticate('local', function(err, user, info) { if ((err) || (!user)) { res.json({message: '...
Alex Lenail's user avatar
  • 13.8k
1 vote
1 answer
4k views

Update or add fields in passport.js local-strategy?

Im all over the docs, but I cant seem to find a way to update credentials. This is what I was able to pick up by analyzing the code. passport.deserializeUser(function(id, done) { AppUser....
Michael Joseph Aubry's user avatar
1 vote
1 answer
2k views

isAuthenticated() function not working node.js passport

I am creating online course application and I want only authenticated users to see the course details and course lecture. I am using local strategy of passport authentication for user authentication. ...
Scalaboy's user avatar
  • 173
1 vote
1 answer
4k views

Unable to set cookie in express + passport with nodejs

Here i'm trying to set cookie when user select remember checkbox when user logins, but even the console.log("hello"); is not working. // process the login form app.post('/login',passport....
Manjesh V's user avatar
  • 1,230