You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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.
The docs say
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?
The text was updated successfully, but these errors were encountered: