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

Ensure user isn't soft deleted when querying for user #723

Open
chadwilken opened this issue Sep 23, 2015 · 2 comments
Open

Ensure user isn't soft deleted when querying for user #723

chadwilken opened this issue Sep 23, 2015 · 2 comments

Comments

@chadwilken
Copy link

We soft delete our user records, is there a way to ensure a property has a certain value in the query executed to find the user by the login method?

@arnvald
Copy link
Collaborator

arnvald commented Sep 23, 2015

Hi @chadwilken,
that's a good question. Currently there is no way to add custom scope to finding user, however since version 0.9.1, there's a support for method called active_for_authentication? which you may use to prevent user from logging in - just simply add this method to User class like this:

def active_for_authentication?
  !deleted_at
end

However, if in your case it is possible to create a next account with the same email/login (after one is soft deleted, if user creates a new account, you create new record instead of reusing old on), this will not work, because it's still old user, not new, that will be fetched from database

@chadwilken
Copy link
Author

@arnvald, thanks for the quick reply. I worked around it for now using a default_scope, but it isn't an ideal setup long term. There are rare circumstances where a email can be used twice in the old setup and is causing headaches still :). Maybe if I get some time I can make this contribution.

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

No branches or pull requests

2 participants