index.js 631 Bytes
const passport = require('passport');
const localStrategy = require('./localStrategy');
const models = require('../models/index');

module.exports = () => {
    passport.serializeUser((user, done) => {
        return done(null, user.email);
    });
    passport.deserializeUser(async (email, done) => {
        try {
            const user = await models.User.findOne({
                where: {email},
                attributes: ['id', 'nickName']
            });
            return done(null, user);
        } catch (e) {
            console.error(e);
            return done(e);
        }
    });
    localStrategy(passport);
};