Question

So I have a User Model and Users Store. When a user authenticates, how is it advisable to best manage the lifecycle of this authenticated user? My current approach is: 1. I have a store of all users ("UsersStore") with a model for "User" 2. I have a second store for the authenticated users ("AuthenticatedUsersStore") with model for "AuthenticatedUser" 3. They both have separate REST endpoints.

This seems like a messy approach, but its easier for me to keep authenticated user and other users separate and query them separately etc. But, I'm pretty sure there's a more elegant way to handle this with only one model and one store.

Can someone please point me in the right direction? Any help is much appreciated! Thanks!

Was it helpful?

Solution

The user authentication model I normally implement on an application is that the current user of the application has no identity until they have successfully provided credentials to a back-end. This is typically done through a login form (e-mail/password.)

When the server responds with success, it sets its own authentication information in a cookie, and typically also returns information about the user that the application requires. This information is then what I put into a model and/or store. Depending on if I implemented the backend or someone else, I either manually populate the model/store or it happens automatically.

I don't see what purpose it serves you to maintain a store of un-authenticated user on either the client or server. The best you can do as far as identification is IP address and some combination of HTTP headers, which can lead to all types of errors given how proxies work.

That being said, if it servers some purpose for you to do the work to attempt to maintain a user identity for someone who is un-authenticated, I think your two store/model approach is actually correct. An authenticated and un-authenticated user are two very different things. They could inherit from the same base class model, but that is as far as I would go.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top