Skip to content
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

User model with additional fields #4

Closed
maberer opened this issue Nov 25, 2018 · 2 comments
Closed

User model with additional fields #4

maberer opened this issue Nov 25, 2018 · 2 comments

Comments

@maberer
Copy link
Contributor

maberer commented Nov 25, 2018

The docs say

The users.User type is an interface. Bring your own user model.

Thats what I do.

Nevertheless I feel the need that the user model should contain other fields one could describe as "profile information". While it is certainly easy to add additional fields to the user struct, I am not sure how/if one should convert the users.User interface back to the own user model in order to access the additional fields. I stumbled about that, when I tried to convert the users.User interface from users.IsLoggedIn(res, req) into my own user model.

I am not sure if it is intended to do a type cast here... at all OR:

Instead I tend to separate the user model (deals with account information, the one that is controlled by this library) from the profile model (the one that contains user added content but has nothing to do with auth). When I view both as two separate concerns, there is no need to type cast the users.User interface.

Instead I can do a getID() on the interface, and then look-up the profile information if required. On the database side, the profile information would be its own table, linked with the user model by the user ID...

Polluting the user model with profile fields would have another disadvantage, as the standard implementation for the session cache seems to cache the whole user model (and not only the user ID). Thus, changes in the profile information (could happen regularly) would need a manual refresh of the cache object... That would not be required, if the profile information is not part of the user model (and thus not written to the cache).

What do you think?

@rivo
Copy link
Owner

rivo commented Mar 4, 2019

First of all apologies for not replying to you in such a long time. I got too caught up in other projects.

I am not sure if it is intended to do a type cast here

In my application, I use a type cast. Since the User interface is only used by one concrete implementation, the cast is safe (except for when the interface is nil, of course).

Yes, I think separating other profile information from the account user model is an option. I haven't tried this myself but if you expect problems from adding more fields to this User, it's something you could try (if you haven't already).

Regarding the cache, I simply purge it (sessions.PurgeSessions()) when there are changes.

Let me know if you need more help here.

@maberer
Copy link
Contributor Author

maberer commented Mar 20, 2019

OK - I have solved this issue already.... so it is not relevant anymore...
Thanks for your response - I am currently using a type cast as well.

@maberer maberer closed this as completed Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants