ruby-on-railsdevise-confirmabledevise-token-auth

Devise Token Auth confirmation email link expired


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


Solution

  • 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