I am in a situation where I need to edit the credentials that users input on the login page before calling Devise's authenticate_user! method. In my UserSessions controller, I just override the login method and edit the sign-in parameters accordingly:
def login
params[:user][:email] = fix_email # Some method that returns the correct email address, which may be different from the initially entered one
authenticate_user!
# ...
end
The authentication fails here if the email ends up being changed as it seems that Devise does not actually use the params for authentication. However, after studying both Devise's and Warden's source, I still haven't been able to figure out where exactly I need to write the correct email to in order for Devise to actually authenticate with it. Can anybody clear this up for me?
Hey – Interesting problem. This looks like a good job for the
before_filtermethods. You should be able to modify parameters before strong parameters come into playIdeally, this should solve the issue for you. Kindly let me know!