"Encountering an issue where the route function in Passport and ExpressJS is not being

When using passport for admin authentication, I am facing an issue where the redirect is not calling my function. Consequently, all that gets printed on login is [object Object]

Here is my code:

app.get('/admin', isLoggedIn, Routes.admin);
        app.get('/login', Routes.adminLogin);
        app.post('/login', passport.authenticate('local-login', {
            successRedirect : '/admin',
            failureRedirect : '/login'
        }));

Passport setup

var LocalStrategy = require('passport-local').Strategy;
        passport.serializeUser(function(user,done){
            done(null, user._id);
        });
        passport.deserializeUser(function(id, done){
            user.getCollection().findById(id)
            .on('success', function(doc){done(doc)});
        });
        passport.use('local-login', new LocalStrategy({
            usernameField : 'username',
            passwordField : 'password',
            passReqToCallback : true
        }, function(req,username,password,done){
            user.getName(username)
            .on('success', function(doc){
                if(doc == null || doc.password != password) {return done(null, false, "Invalid password");}
                return done(null, doc);
            })
            .on('error', function(err){return done(err);});
        }));
    };

Admin route :

var adminRoute = exports.adminRoute = function(req,res){
        console.log(" ADMIN PAGE");
        res.render('admin.jade');
    };

Answer №1

@robertklep was absolutely correct - using null as the first parameter in the done function within the deserializeUser method did the trick.

passport.deserializeUser(function(id, done){
            user.getCollection().findById(id)
            .on('success', function(doc){done(null,doc)});
        });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The iframe content is not updating despite using jQuery

On this site , the following code is present: <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <iframe style="position: absolute; top: 0; left: 0; height: 100%; width: 100%" src="blank.html"></iframe ...

Exploring the United States: Using React to generate a comprehensive list of cities for each state

There are a total of 51 states in the United States, each state comprising numerous cities. I aim to compile a list of cities for each state. To achieve this, I decided to experiment with the following approach: List of libraries used: country-state-city ...

Refresh only a portion of a page using PHP and JavaScript

I have a webpage set up with multiple sections in separate divs. Currently, the essential divs required are <div id="main">...</div> & <div id="sidebar">...</div> Each div contains PHP code like: <?php include("page.php") ...

Encountering issues with SSL websocket connection after updating node to version 20.10 (previously on 14.7) and socket.io to version 4.7.2 (previously on 1.4.36)

I've hit a wall and could really use some fresh perspectives... My task involves managing code that sets up a secure websocket using Express. The original socket.io libraries were v1, which I have upgraded to v4 along with Node 20.10 (previously 14.7 ...

What is the best way to transfer the $http response value to another function?

I currently have these two functions set up. One function, $scope.submit, handles posting data to the server and capturing the response value. The other function, $scope.addTeams, is responsible for adding teams based on the response from $scope.submit. ...

Master the Art of Crafting Unique URLs

I am developing a web page that requires me to call two queries, each requiring an ID. However, I'm unsure of the best way to pass these IDs in the URL. For instance, one query is for books and the other is for authors. Currently, I have considered tw ...

Customizing build dependencies in Google App Engine allows developers to tailor their applications to

For my application to be built, it requires cmake, libx11-dev, and libpng-dev. I found guidance in this documentation suggesting that these dependencies can be listed for the Google App Engine platform, but I am unsure of the process. While I managed to ...

NPM is experiencing issues because it can't run as a result of an E

Despite my best efforts to troubleshoot by removing, re-installing, and re-hashing npm, I continue to encounter this persistent error whenever attempting to run any npm related command: prompt$ npm ------ npm ERR! EEXIST, mkdir '/usr/local/bin/npm ...

Pass data in JSON format from Laravel controller to AngularJS

When working with Laravel, I successfully converted data in MySQL to JSON for use in AngularJS. However, I am now unsure of how to effectively utilize these values in AngularJS. Can anyone offer assistance? View output data (hide each value) Controller ...

Having trouble accessing the `then` property of undefined while utilizing Promise.all()?

An issue has occurred where the property 'then' of undefined cannot be read: getAll(id).then((resp) => {...} ... export function getAll(id){ all([getOne(id), getTwo(id)]); } ... export all(){ return Promise.all([...arg]) } I' ...

Tips on invoking a function from an array in JavaScript when a button is clicked

Being new to JavaScript, I encountered a challenge where I have an array of functions: allFunctions = () => [ function1(), function2(), function3(), function4(), function5(), function6(), function7(), function8(), function9() ] My go ...

How can I organize node js query results into distinct objects?

I am facing an issue with my node query where the handlebars helpers on my view are treating the entire array as one single result: {{#if donations}} {{#each donations}} {{this}} is displaying the whole set of donations! {{/each}} {{ ...

Should you stick with pre-defined styles or switch to dynamic inline style changes?

I am currently developing a custom element that displays playing cards using SVG images as the background. I want to make sure that the background image changes whenever the attributes related to the card's suit or rank are updated. From what I under ...

What is the best way to stop Quasar dropdown list from moving along with the page scroll?

I am facing an issue with my code while using Quasar (Vue 3.0). The code snippet in question is: <q-select filled v-model="model" :options="options" label="Filled" /> When the drop-down menu is open and I scroll the pag ...

use ajax to dynamically append a dropdown menu

Currently working on creating a form that includes a dropdown menu populated with elements from a database. The challenge I'm facing is ensuring that once an element is selected from the dropdown, another one appears dynamically. My goal is to use AJA ...

The node is currently operating on a non-existent version

While attempting to set up Strapi in my Angular project, an error arises: The Node.js version running is 14.20.0 Strapi mandates using a Node.js version between >=16.0.0 and <=20.x.x Kindly ensure that the correct Node.js version is being used The i ...

Is there a way to transfer textbox value to ng-repeat in AngularJS?

1) The Industry dropdown menu corresponds with a code textbox. Depending on the selected industry, the code will change accordingly. 2) There is a dynamic feature to add or delete Movie Names and Directors' names. In this table, there are three colu ...

Using Selenium and Python to showcase the source of an image within an iframe

My goal is to automatically download an image from shapeNet using Python and selenium. I have made progress, but I am stuck on the final step. from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.s ...

Tips for navigating upwards to a specific element and successfully clicking on it in Selenium

I am facing a situation where the system needs to scroll upwards to reach the web element located in the left panel of the page and then click on it to proceed with other operations. I have attempted various methods but none seem to be effective. Can anyon ...

The curious case of Node.JS: The mysterious behaviour of await not waiting

I am currently utilizing a lambda function within AWS to perform certain tasks, and it is essential for the function to retrieve some data from the AWS SSM resource in order to carry out its operations effectively. However, I am encountering difficulties i ...