我正在使用Express,PassportJS和MongoDB构建身份验证系统,该系统将运行2种身份验证策略:
我遇到的关键问题是管理不同的帐户类型。经过O365身份验证的用户不需要密码,也不能使用本地身份验证登录。
我的userSchema
当前看起来像这样:
const userSchema = new mongoose.Schema({
username: { type: String, required: true, lowercase: true, index: true }, // Depending on the user type it can be tomd (for local auth) or tomd@example.com.au for O365
hash: { type: String, required: false },
salt: { type: String, required: false },
firstname: String,
lastname: String,
image: String,
lastLoggedIn: Date,
services: Array,
userType: String, // Local or O365
activationCode: String,
activationConfirmed: { type: Boolean, default: false },
isActive: { type: Boolean, default: true }, // Handles disabling accounts
deleted: { type: Boolean, default: false } // Handles removing users
}, {timestamps: true});