1

I am currently developing a website and i have a problem with te confirmation link with devise token auth.

Everything is working right, after someones registers they get an email with a confirmation link. This link is confirming and working properly BUT when this link expires (i set it up in the configuration with config.confirm_within = 1.day ) or someone clicks this link again they get a "Routing error". So i suppose there should be a way of redirecting to the homepage when that link expires and maybe showing a message saying that they have to ask for the email confirmation again..

i have this confirmation routes:

new_api_user_confirmation GET    /api/auth/confirmation/new(.:format)   devise_token_auth/confirmations#new
api_user_confirmation     GET        /api/auth/confirmation(.:format)   devise_token_auth/confirmations#show
                          POST       /api/auth/confirmation(.:format)   devise_token_auth/confirmations#create

I use the last route POST for resending the email and it is working, but the other to routes are not working and that makes sense because i am using API. But there should be a redirect url for when you get an error

Any thoughts? thank you in advance

Julio Lopez
  • 1,107
  • 1
  • 9
  • 17

1 Answers1

1

you can override the DeviseTokenAuth::ConfirmationsController#show and redirect to root_path

DeviseTokenAuth ConfirmationsController#show

class ConfirmationsController < DeviseTokenAuth::ConfirmationsController    
  def show
    ...
    else
      # raise ActionController::RoutingError, 'Not Found'
      redirect_to :root_path
    end
  ...

in routes

mount_devise_token_auth_for 'User', at: 'auth', controllers: {
  # confirmations:  'devise_token_auth/confirmations',
  confirmations:  'confirmations',

devise-token-auth docs

PGill
  • 3,373
  • 18
  • 21
  • Perfect... i did this yesterday after lots of reading.. your answer is correct. now i am struggling with other thing... i would love to send a message depending on the error.. they have in the controller a variable called >resource< and inside somewhere there is an error message.. i am trying to send this one as a querystring... or simply send somehitng like redirecto_to login_path(message: "my message") but this message depeding on the error that could be link expired or user already confirm.. i am sorry maybe i am asking for to much now.. but do you know how to achieve this? – Julio Lopez Apr 24 '20 at 15:59
  • you can use `@resource.errors` object. To get first message `@resource.errors.full_messages.first`. [docs](https://api.rubyonrails.org/classes/ActiveModel/Errors.html#method-i-full_messages) – PGill Apr 24 '20 at 19:18
  • thank you so much MASTER!!.. everything works perfect !!. – Julio Lopez Apr 25 '20 at 00:46