Closed GabrielLeonte closed 5 years ago
app.post('/login', passport.authenticate('local-login', { successRedirect: '/dashboard', // redirect to the secure profile section failureRedirect: '/login' // redirect back to the signup page if there is an error }), function (req, res) { console.log("hello"); if (req.body.remember) { req.session.cookie.maxAge = 1000 60 3; } else { req.session.cookie.expires = false; } res.redirect('/'); }); app.get('/dashboard', isLoggedIn, async function (req, res) {
// render the page and pass in any flash data if it exists
res.render('dashboard', {
user: req.user
});
})
And this is from routes
Solved. passport.serializeUser(function (user, done) { done(null, user.id); });
I have this code: `// load all the things we need const passport = require('passport'); const LocalStrategy = require('passport-local').Strategy; const fs = require('fs'); var sqlite3 = require('sqlite3').verbose(); const bcrypt = require('bcrypt-nodejs'); const db = require('./database'); const settings = require('./settings'); var database; database = new sqlite3.Database(settings.dbName);
//Check if database exists or not. If it not exist it will create one.
if (fs.existsSync(settings.dbName)) {} else { db.Init();
}
// expose this function to our app using module.exports module.exports = function (passport) {
};`
When i log in and try to get req.user.username or id i get in console.log that
[]
Some help please?