Skip to content

Extra user details: in user schema, or a different schema? #1689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AmirGilboa opened this issue Mar 7, 2016 · 5 comments
Closed

Extra user details: in user schema, or a different schema? #1689

AmirGilboa opened this issue Mar 7, 2016 · 5 comments
Labels

Comments

@AmirGilboa
Copy link

Users are important part of my app. they have tons of information.
address, phones, location, bio, etc.
Should i add all this to the user schema, or create a separate schema/table for that, and reference back to user schema?

as always, any link to discussion, blog, example, tutorial, is much appreciated.

@smirciat
Copy link

smirciat commented Mar 7, 2016

I've done it both ways, they both work fine. The generator is definitely set up to include additional user attributes in the schema, then add then to the User and Auth services for manipulation. My problem was I tried it a few times, made a mistake, then I couldn't authenticate my users at all. But certainly if you do it carefully, I think using the user schema would be preferred.

@AmirGilboa
Copy link
Author

i have found this interesting project, Drywall, http://jedireza.github.io/drywall/
and they used a separate account schema too. so i guess that's the right way to go.
thanks!

@AmirGilboa
Copy link
Author

but how to connect these 2?
should they have the same _id ?
or each have their own _id, and the schema has like a "foreign key" to the user?
how to seed the user with the account? i need to know the _id that has been created...

@smirciat
Copy link

smirciat commented Mar 7, 2016

When I set up the separate model, I had a field for user id, which is self explanatory. Then I looked it up based on this.getCurrentUser()._id. The danger here is ending up with duplicate entries for the same user, so you'll either have to check for that, or place a unique index on your database for the user id field.

@remicastaing
Copy link
Contributor

Having two separate model, one for the account and another for the user could be an answer to the multiple social account issue (#1681 or #359).
After checking that the email is the same and also verified, you could link several accounts to the same user. To simplify the process I wouldn't allow to fill additional infos in the user model before the email is verified (local strategy and tw strategy).
With two separate models, the complete registration logic would be hold in the account model and users of this generator would only focus on specific logic in a custom user model.
The generator could also provide some hooks to automatically fill some user infos according to the provided social data (first name, last name, etc.)

@Awk34 Awk34 added the question label Mar 10, 2016
@Awk34 Awk34 closed this as completed Mar 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants