-
-
Notifications
You must be signed in to change notification settings - Fork 157
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
Load the user from the database each time it's fetched from the cache by default #563
Comments
Hi @danschultzer ^^ |
Yup, it will be configurable. I just have a strong distaste for configs, I prefer explicit logic where-ever possible so have to think about what can be a good approach here 😄 I might also push this to 1.1.0 release which will have all breaking changes.
The reload logic could also be removed? |
Yep of course it can be. I was just a bit lazzy about reviewing it. ^^ With less configs, we have a cleaner code for sure. |
Hey @danschultzer, had a two questions/observations here with this change that maybe you could provide some insight into both which relate to changes currently on master... Possible to delete the session from within a custom I had previously left you a question Help in understanding custom contexts/purpose of With the changes here with (which are great and removes the need to have a separate plug for reloading the user) I'm wondering if you have a way such that if the custom The reason being that I want to be able to better support my app by modifying Should the custom
I've noticed with the newest changes that when I sign in the single keyword within Thoughts on both/more information needed? Thanks again. |
Great point! I've opened PR #573 to solve this. At first I was a bit unsure if it could introduce race condition, but that shouldn't be an issue here at all. Also, #567 kinda touches this, where all sessions for a user that's being deleted should be expired.
The It could look like: MyApp.Users.User
|> Repo.get_by(clauses)
|> case do
%{deleted_at: nil} = user -> user
_any -> nil
end Or maybe it's possible with a where clause (not sure if the macro accepts this though): MyApp.Users.User
|> where([u], ^clauses)
|> where([u], is_nil(u.deleted_at))
|> Repo.one() |
As described in the docs the fetched user object assigned as
current_user
may be stale. This is more performant as a db lookup isn't necessary for each load. However, I think for the majority of use cases the user is expected to have been fetched from the database. This default is probably confusing for many. So I think it's better to load thecurrent_user
from the database by default, and let it be easy for devs to optimize later on.The text was updated successfully, but these errors were encountered: