Rails 6, Devis: How to confirm user after successful email confirmation

970 Views Asked by At

I working on a app with Rails 6, React Devise & GraphQl & devise-token_authenticatable for authentication.

I'm trying to confirm the user after they successfully confirm their email. After searching and finding some possible answers I have tried this: in devise>> confirmation_controller.rb

class Devise::ConfirmationsController < DeviseController

  protected

    # The path used after confirmation.
    def after_confirmation_path_for(resource_name, resource)
      if signed_in?(resource_name)
        redirect_to app_root_url
      else

        resource.confirm!
        redirect_to "#{request.base_url}/app/login", notice: "Email confirmed!"
      end
    end

end

But this doesn't work as expected.

I also tried the following without any luck:

def after_confirmation
  self.confirm!
end

Any suggestions? Thanks for your time

1

There are 1 best solutions below

1
Bhatiya J On

Ok, I figured it out finally. Here's my solution. I just updated the users confirmed_at attribute in Users::ConfirmationsController#show action.

class Users::ConfirmationsController < Devise::ConfirmationsController
  # GET /resource/confirmation/new
  # def new
  #   super
  # end

  # POST /resource/confirmation
  # def create
  #   super
  # end

  # GET /resource/confirmation?confirmation_token=abcdef
  def show
    @user = User.find_by_confirmation_token(params[:confirmation_token])
    @user.update(confirmed_at: Time.now.utc)
    # super
  end
end 

In routes.rb devise_for :users, skip: :sessions, controllers: { confirmations: 'users/confirmations' }