gpt4 book ai didi

javascript - 具有多策略 sigup 的用户表架构

转载 作者:太空宇宙 更新时间:2023-11-04 01:08:54 26 4
gpt4 key购买 nike

在从事一个项目时,面临着存储不同 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com