我使用passport-facebook创建了一个用户
api.get('/facebook', passport.authenticate('facebook', {
scope: 'email'
}))
删除用户
从用户那里删除电子邮件=?
转到#1来重新创建用户
但是,当我尝试#3错误时
Failed to deserialize user out of session
所以我试图删除数据库上的会话
delete from sessions where session_id = 'p8TaEeb-GH87lbi-a5hpmY6YX6me6yHf'
我尝试了3号方法。
我放了一些日志检查护照-脸书作品。
passport.use(new FacebookStrategy({
clientID: config.FACEBOOK_CLIENT_ID,
clientSecret: config.FACEBOOK_CLIENT_SECRET,
callbackURL: '/api/auth/facebook/callback',
profileFields: ['id', 'name', 'email', 'displayName', 'photos']
}, async (accessToken, refreshToken, profile, done) => {
//log for checking passport-facebook works
console.log('Is it works??')
const type = 'facebook'
const nickname = profile.displayName
const email = profile.emails[0].value
const thumbnail = profile.photos[0].value
try {
let [existsUser] = await conn.query(`SELECT * FROM users WHERE email = ?`, [email])
existsUser = existsUser[0]
// is user already exists
if (existsUser) return done(null, existsUser)
const fields = { nickname, email, thumbnail, type }
await conn.query(`INSERT INTO users SET ?`, fields)
let [createdUser] = await conn.query(`SELECT * FROM users WHERE email = ?`, [email])
createdUser = createdUser[0]
return done(null, createdUser)
} catch (err) {
return done(err)
}
}))
})
但是,日志没有出现,所以似乎是FacebookStrategy在我执行#3时不起作用
这是我的护照。deserializeUser
passport.deserializeUser(async (id, done) => {
const sql = 'SELECT * FROM users WHERE id = ?'
const fields = [id]
try {
const [user] = await conn.query(sql, fields)
return done(null, user[0])
} catch (err) {
return done(err)
}
})
这是我的会话选项
const sessionOpt = {
name: config.SESSION_COOKIE_KEY,
secret: config.SESSION_SECRET_KEY,
resave: false,
saveUninitialized: true,
store: new MySQLStore(mysqlOpt),
cookie: {
maxAge: expiry,
httpOnly: true
},
unset: 'destroy'
}
这是我的完整代码
https://github.com/qkreltms/relay-novel-server/blob/develop/src/config/passport.js
有什么想法吗?
答案 0 :(得分:0)
https://github.com/jaredhanson/passport/issues/6#issuecomment-4857287
我添加了if语句,当用户不存在时,var title = '<?php echo "{$_SESSION['email']}"; ?>';
var check = window.prompt('Confirm Email: ' + title);
if (check) {
}
return done(null, false)