Passport.js不删除req.logout()上的会话

时间:2018-10-29 10:31:27

标签: node.js mongodb express passport.js

我也尝试过req.session.destroy(),但抛出一个错误,说=> Error: req.flash() requires sessions.

    // Logout route
    router.get('/logout' , (req , res) => {

    req.logOut();
    // req.session.destroy();
    req.flash('success_msg' , 'You are successfully logged out');
    res.redirect('/users/login');
    })
    module.exports = router;
    require part of app.js
    const express = require('express');
    const exphbs = require('express-handlebars');
    const bodyParser = require('body-parser');
    const path = require('path');
    const mongoose = require('mongoose');
    const methodOverride = require('method-override');
    const flash = require('connect-flash');
    const session = require('express-session');
    require('./config/passport')(passport);
    const db = require('./config/database');

   middleware of app.js
    handlebar middleware
   app.engine('handlebars', exphbs({
   defaultLayout: 'main'
   }));
   express session middleware
   app.use(
   session({
   secret: "my secret",
   resave: true,
   saveUninitialized: true
   })
   );
   app.set('view engine', 'handlebars');

   passport
   app.use(passport.initialize());
   app.use(passport.session());


   flash middleware
   app.use(flash());

0 个答案:

没有答案