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

Adds current_active_session helper, memoization for current_user #95

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mdchaney
Copy link

Closes #93, "Why is the ||= removed? current_user method". This adds memoization back to current_user / Current.user, plus causes log out when the current session is destroyed.

With this change, it's easy to find the current session and check its id against the param. The user is logged out if the current session is destroyed, allowing the tests to pass with memoization in place.

Closes stevepolitodesign#93, "Why is the ||= removed? current_user method".  This adds
memoization back to current_user / Current.user, plus causes log out
when the current session is destroyed.
Copy link
Owner

@stevepolitodesign stevepolitodesign left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I might push edits to README.md to reflect these changes if that's OK with you.

forget_active_session
active_session.destroy

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we still call active_session.destroy before the if statement? I only ask because we're calling it in both branches.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That bothered me as it doesn't feel DRY, but there's no good way to handle it. "current_active_session" will certainly be memoized by the time "destroy" is called because of "authenticate_user!". But "current_active_session" has code to do a lookup for the comparison, and destroying it before then creates a dependency on "authenticate_user!" being called first.

So, yes, we can call it before the "if" statement, but I prefer everything to be explicit at the expense of an extra line. This might save a headache later during refactoring.

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

Successfully merging this pull request may close these issues.

Why is the ||= removed? current_user method
2 participants