Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local strategy deserializeUser not be used #996

Open
zilin-zhou opened this issue Aug 23, 2023 · 0 comments
Open

local strategy deserializeUser not be used #996

zilin-zhou opened this issue Aug 23, 2023 · 0 comments

Comments

@zilin-zhou
Copy link

zilin-zhou commented Aug 23, 2023

After using the https protocol, the local passport cannot be used, but the google and twitter strategies can be used. The local strategy does not run this function deserializeUser. In the callback function of the local strategy, req.session has passport information, but it does not exist after the jump There is no pasport information in the session

my code:

passport.serializeUser((user, done) => {
    console.log("========serializeUser========\n", user)
    done(null, user);
});

passport.deserializeUser((user, done) => {
    console.log("========deserializeUser========\n", user)
    done(null, user)
});
passport.use(new LocalStrategy(
    {
        usernameField: 'email',
        passwordField: 'password'
    },
    async function (email, password, done) {
        ........//database process
        } else {
            return done(null, false, { message: 'Incorrect username and password' })
        }
    }
));
module.exports = passport

my route

router.post("/login_email", passport.authenticate("local", {
    failureRedirect: "/login",
    failureMessage: true
}),
    (req, res) => {
        console.log("========session========\n", req.session)
        res.redirect("/auth/user")
    }
);

** This function deserializeUser is not called **

const session = require("express-session");
const bodyParser = require("body-parser");
const config = require('./config')
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json());
app.use(require('cookie-parser')());
app.use(
    session({
        secret: config.jwtSecretKey,
        resave: false,
        saveUninitialized: true,
        cookie: {
            secure: true,
            sameSite: "none",
            maxAge: 24 * 60 * 60 * 1000 * 7
        }
    })
);

image

please help me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant