Devise: Redirect to "/signup" on registration failure - ruby-on-rails

I wanted to redirect to "/signup" page after a user fails the registration process. How do you do it?
Every time the registration fails, it redirects to "/users" which is not what I wanted, I want it to redirect to the registration page.
TIA

You have to write a custom method in the initializer and call it.
See this post here, hope it gets you where you need to!
Devise redirect after login fail

Related

devise_token_auth forget password API shows Use POST /sign_in to sign in. GET is not supported error

Following this solution https://stackoverflow.com/a/47761138/7818637 I am designing forgot password flow APIs on rails where I am using devise_token_auth gem for authentication.
1. A POST call to send a Password Reset Email
URL: http://localhost:3000/client/auth/password
form-data: {email: 'john#gmail.com', redirect_url: 'http://localhost:3000/client/auth/sign_in'}
2. A GET call to verify the password reset token (clicked in email)
I am receiving the the following URL on my console containing redirect_url and reset_password_token:
http://localhost:3000/client/auth/password/edit?config=default&redirect_url=http%3A%2F%2Flocalhost%3A3000%2Fclient%2Fauth%2Fsign_in&reset_password_token=ZBsx64Gk1VBraM3THZTn
When I call on this URL, I am receiving the following error:
Use POST /sign_in to sign in. GET is not supported.
What I have already tried:
Following the issue here I have found that I am already using include DeviseTokenAuth::Concerns::SetUserByToken in my controller.
Console Logs:
When the users clicks the url in your email you redirect them to /password/edit path. In this action you verify the user. If everything goes right the user will be redirected in redirect_url which is the sign_in path in your case.
You should change the redirect_url in your email and create an action and a view in which the user will be redirected. In this new view you will have the fields so the user can reset the password. Make sure that the new url will use 'GET'. On form submission redirect user to sign_in path so he/she can log in with their new password.
Please read https://devise-token-auth.gitbook.io/devise-token-auth/usage/reset_password for more info.

How to hook into Devise action before facebook redirect

I'm trying to hook into an action that will get called before devise users are redirected to facebook for login. The login link suggests I look into the passthru action in the omniauth_callbacks but that doesn't seem to work
user_facebook_omniauth_authorize_path GET|POST /users/auth/facebook(.:format) my_devise/omniauth_callbacks#passthru
Any ideas how to make a call before the redirect?
Thanks!

Rails: redirect back to previous page after sign in / sign up

I am using Rails and devise for user authentication, I don’t know how to redirect the user back to the previous page after successful sign in/sign up.
I know about after_sign_in_path_for, but I don’t know what I should write inside.
You can write custom sessions controller for devise login and use request.referrer to get the URL of the page the user is coming from. Then just redirect back to the previous page after login. Also refer this doc. You could go by one of the methods. Hope it helps.

Rails, Devise: invalid login redirects to root page instead of displaying errors

For some reason, my app redirects failed session creation to the root page of the application, instead of displaying errors on why the login failed, such as, wrong password.
I captured the http response:
Request URL:http://localhost:3000/users/sign_in
Request Method:POST
Status Code:302 Moved Temporarily
My code performs a :
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
If I change the url to user_session_path - I get the following:
Invalid email or password.
However, it is just rendered as simple text.
Request URL:http://localhost:3000/users/sign_in.user
Request Method:POST
Status Code:401 Unauthorized
I have omniauth and cancan gems installed. Not sure where to start looking - any ideas?
(on another note, I do not see the route session in rake routes, but if I perform a correct login, it logs me in. How is this possible?)
Thank you!
I found that my app had a CustomFailure class in the lib folder. This always redirect to the root upon login. After removing this failure app, the app redirected me back to the login screen after a failed login.
According to Rails - Devise - Error messages when signing in? , the errors are not given to form fields, but to flash messages. So you need to include them to the default devise new session view.
I still did not figure out why session_path works, and why user_session_path produces the results posted in my question.

Handling Devise login in my own controller

I'd like to override the way Devise currently handle the login flow. I don't need/want /users/sign_in, I just want to use my own root_path for login handling, i.e. logging user in and handling failed password entries.
I have successfully created the form which logs in, but if an user fails to put his/her password correctly, he/she being redirected to /users/sign_in. How to make sure I keep on the same action and handle failed passwords?
This is probably what you're looking for: https://github.com/plataformatec/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes

Resources