我正在玩passport-local
。它的使用非常简单,但是护照建立cookie-session-id和连接用户之间关系的方式对我来说仍然很神秘。
我想在数据库中存储已连接的会话,以便:
从下面这个无效的片段中,您可以看到我有两个集合:
这里是片段:
import passport from 'passport'
import LocalStrategy from 'passport-local'
import mongoose from 'mongoose'
var UserSchema = new mongoose.Schema({
username: String,
password: String
})
var Sessions = new mongoose.Schema({
session: String, // Sessions of connected users
username: { type: Schema.Types.ObjectId, ref: 'User' },
ip: String, // IP of the connected user
lastSeen: Date, // When the user made his last request
})
var User = mongoose.model('UserSchema')
我应该如何使用passport
填充会话表?