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

No flash alert on failed login attempt by ajax... #534

Closed
marzdrel opened this issue Sep 27, 2010 · 8 comments
Closed

No flash alert on failed login attempt by ajax... #534

marzdrel opened this issue Sep 27, 2010 · 8 comments

Comments

@marzdrel
Copy link

I am trying to sign in using remote form (:remote => true). If the login fails, action new.js is properly triggered, but there is no indication about the problem. As fas as I can check no flash is beeing set whatsoever. If the request is set by normal request asking for html format response, then everything works just fine.

Any idea what is the problem here?

Is there any other resonable way to check if theres an error on login in the new action?

@josevalim
Copy link
Contributor

How do you get the "new.js" to be rendered for remote calls? Have you added :js to navigational formats? We usually redirect or return 401 status for XHR.

@marzdrel
Copy link
Author

I just set form :remote => true and now the form is submitted with ajax call. If the data are valid, the proper action is triggered. If data are invalid new is rendered again with filled data from previuos request. I haven't done anything aside from altering views. Check out the view/controller code here http://gist.github.com/599914
Both config.http_authenticatable and config.http_authenticatable_on_xhr are false.

@josevalim
Copy link
Contributor

My advice for a more robust application is to turn http_authenticatable_on_xhr to true (the default) and handle the error with javascript when a 401 is returned by the server. Use devise master to ensure proper behavior.

However, if you want to go down the other road, I must say it was supposed to be working according to this line:

http://github.com/plataformatec/devise/blob/master/lib/devise/failure_app.rb#L43

I recommend you to debug the failure app in order to find out why flash is not being set. :)

@marzdrel
Copy link
Author

Is there any working example of ajax login form with http_authenticatable_on_xhr? Since the call is made using remote form it seems like tons of work to actually get the the loggin working with this... :-/

@marzdrel
Copy link
Author

Please forgive me this report. While debugging I found out an error in my javascript response, so the form wasn't even rendered again. Thats why the flash was empty. Devise works as a charm. Also I reimplemented everything with http_authenticatable_on_xhr = true, and it way clearner and simpler now. I am catching 401 reported on ajax calls, and rendering login in colorbox.

Thanks for suggestion!

Edit: I meant http_authenticatable_on_xhr = true

@josevalim
Copy link
Contributor

Glad to know! :D

@ovenbits
Copy link

how are you catching the 401's on the ajax calls? html redirects are working fine... but I'm setting up a system that has some :remote=>true forms and links, and if the user isn't logged in, i want some js to catch the fact that devise sent back a 401, and have some js fire a login modal. The way I'm starting to tackle it is with a custom_failure.rb file and having it override the failure app, and defining how to respond to authentication errors in there (whether it's xhr or normal html). Is this the best way?

@josevalim
Copy link
Contributor

You can handle 401 using failure callbacks in your JS framework. Devise will pass the message as json.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants