在从事一个项目时,面临着存储不同 Passport 策略(本地、facebook、twitter)的用户信息的问题。
一开始我的 UserSchema
看起来是这样的:
User = mongoose.Schema(
{
"email" : { type : String , lowercase: true , trim : true , unique : true } ,
"providerId" : { type : String } ,
"providerName" : { type : String } ,
"hashedPassword" : { type : String } ,
"salt" : { type : String } ,
"strategy" : { type : String } ,
"created" : { type : Date , default : new Date().valueOf() } ,
"lastConnected" : { type : Date , default : new Date().valueOf() } ,
"accessToken" : { type : String } ,
"securityToken" : { type : String , default : "" } ,
"roles" : [ { type : String } ]
}
);
但是独特的电子邮件会带来电子邮件问题,因为具有 Twitter 策略的两个用户将拥有空电子邮件,这会导致错误。
我想过不让电子邮件变得独特,但这会带来很多(从第一眼看上去)问题。 我看到的解决方案之一是为每个策略制定不同的模式,但这非常难以维护。
还有其他方法可以解决这个问题吗?最佳实践是什么?
附注我发誓我用谷歌搜索但没有找到任何解决方案
最佳答案
您似乎希望能够说 unique:true 并指定allowNulls。现在这似乎是可能的,正如您在这里看到的:https://stackoverflow.com/a/9693138/1935918
关于javascript - 具有多策略 sigup 的用户表架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19984656/