I would like to redirect to another url when auth failed.
Any idea please thanks!
plugins
myplugin
lib
auth
my_auth_controller.rb
def after_authenticate(auth_hash)
if not auth
redirect_to "https://example.com"
end
result = Auth::Result.new
end
In your code, you have the if not auth condition, but there is no corresponding else statement.
The redirect_to method should be used within a controller action. If you’re using it in a separate method like after_authenticate , make sure it’s within the scope of a controller.
So here is the correct code.
def after_authenticate(auth_hash)
if not auth
redirect_to "https://example.com"
else
# Authentication succeeded, continue with the authentication process
result = Auth::Result.new
end
end
The result world be, If the authentication fails auth is not true, it will redirect to “https://example.com”. Otherwise, if authentication succeeds, it will continue with the authentication process.
To verify, You may check browser developer tools to inspect network requests and redirects or use any online tool such as redirect checker This can help you identify redirection issue and status code.