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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge STI model fix #27

Merged
merged 2 commits into from
Jun 22, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Enable logging in with STI subclass
Say you have a `User` model using STI, with an `Admin` subclass.
Previously, if an `Admin` attempted to log in, their id would be saved in the `admin_id` key.
Then, when calling `authenticate_by_cookie(User)`, no user would be loaded, since it would look for the `user_id` key.

This changes the session keys to use the `base_class`, which is the root class of the STI hierarchy. That way, for the above scenario, the ID is both saved and loaded using the `user_id` key, so logging in works.

This shouldn't affect non-STI models, since `base_class` would just return the class itself
  • Loading branch information
iancanderson authored and mikker committed Jun 22, 2018
commit c937b256c2b3b1d4139cbc044cd7b345511142fb
4 changes: 2 additions & 2 deletions lib/passwordless/controller_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def reset_passwordless_redirect_location!(authenticatable_class)
private

def session_key(authenticatable_class)
:"passwordless_prev_location--#{authenticatable_class}"
:"passwordless_prev_location--#{authenticatable_class.base_class}"
end

def cookie_name(authenticatable_class)
:"#{authenticatable_class.to_s.underscore}_id"
:"#{authenticatable_class.base_class.to_s.underscore}_id"
end
end
end