[英]Role-Based login in nodejs and mongoose
I have an application with 2 roles, a User and a Photographer . 我有一个具有两个角色的应用程序,一个用户和一个摄影师 。 the difference between these 2 models is a isAdmin field in User and a Photo[ ] in Photographer and a order[ ] in User .
这两个模型之间的区别是User中的isAdmin字段和Photographer中的Photo []和User中的order [] 。 But I need only one login for both of them!
但是我两个都只需要登录一次! Clearly, need different views and routs for them!
显然,他们需要不同的见解和溃败! how can I do this?
我怎样才能做到这一点? If any guide, I would be appreciated!
如果有任何指导,我将不胜感激! Thanks a lot!
非常感谢!
The schemas are as below: 模式如下:
var userSchema = new Schema({
//some other fields, the same with photographer
isAdmin: { type: Boolean, default: false },
orders: [{
price: { type: Number, default: 0 }
},
{timestamps: true}
]
});
var photographerSchema = new Schema({
//some other fields, the same with user
photos: [{
title: { type: String, default: '' },
path: { type: String },
price: { type: Number, default: 0 },
isAppoved: { type: Boolean, default: false },
},
{timestamps: true}
]
});
You should rethink your architecture. 您应该重新考虑您的体系结构。 Better solution would be to have 1
User
model and 2 profile
submodels. 更好的解决方案是拥有1个
User
模型和2个profile
子模型。 User
model would contain the type
of the user and fetch profile info(writer_profile/user_profile) from the submodels. User
模型将包含User
的type
,并从子模型中获取配置文件信息(writer_profile / user_profile)。
If you won't refactor, this will turn in to a mess pretty fast. 如果您不进行重构,那将很快变得一团糟。 Think about it, what happens when a
User
and a Writer
registers with the same credentials? 想一想,当
User
和Writer
使用相同的凭据注册时会发生什么? You will need to check that too. 您也需要检查一下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.