I have two models, User and Account. When a user signs up, an account is automatically generated for him and he becomes the owner of that account like so:
Account model
{
"_id" : ObjectId("54f3391c96bfc9fb0b46f088"),
"account" : "Company Name",
"auth_token" : "test auth token",
"owner" : ObjectId("54f3391c96bfc9fb0b46f087"),
"users" : [
ObjectId("54f3391c96bfc9fb0b46f087")
],
"__v" : 0
}
Users can also be assigned to other accounts, this is saved in the users attribute for the account, Users and owner are subdocuments.
Now I would like to ensure that when a user logs in, I fetch a list of all the accounts accessible by that user, so that I can build a UI for switching account.
I have not idea how to approach the issue, any help would be appreciated!
Aucun commentaire:
Enregistrer un commentaire