How to detect that user is going to be authenticated? (before authenticate)
-
05-07-2021 - |
سؤال
I need to trigger callback before Devise redirects user to login page, probably because authenticate_user!
method detected he's not logged in. Something like:
before_filter :authenticate_user!, :only => :edit
def not_authenticated_callback
# do something
end
It shouldn't be called if authenticate_user!
has not been called.
المحلول
I've found an ugly solution:
around_filter :intersect_warden
def intersect_warden
success = false
result = catch(:warden) do
result = yield
success = true
result
end
unless success
not_authenticated_callback
throw(:warden, result)
end
end
نصائح أخرى
while using before_filter: authenticate_user! ,the action will not go inside your controller, if the user not logged in.
if you use before_filter, You cant access any functions inside your controller, when the user not logged in.
لا تنتمي إلى StackOverflow