ben
ben

Reputation: 29797

Using Devise with Ruby on Rails, how can I send the user to sign_in path if they use an invalid auth_token?

When I send a user to /dashboard?auth_token=XXX, and the auth_token is incorrect, the user gets taken to the root_path.

In this situation, I want the user to be taken to the sign_in path, and then be taken to /dashboard after they sign in. How can I do this?

Upvotes: 0

Views: 77

Answers (1)

José Valim
José Valim

Reputation: 51419

The default in Devise is to redirect to "new_#{scope}_session_path" route if one is available. As seen here:

https://github.com/plataformatec/devise/blob/master/lib/devise/failure_app.rb#L89

So, assuming you are using the user scope, be sure you have a new_user_session_path defined by your router.

About redirecting back to the original page, try out this wiki page:

https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in

Notice the filter in the wiki page needs to be added before you invoke Devise's authentication filters.

Upvotes: 2

Related Questions