keep getting a 401 on overriden create devise

40 Views Asked by At

I keep getting a 401 on the create action. I have tried to change the file along with the routes.

here is my routes file.

mount_devise_token_auth_for "User", at: "auth", controllers: { passwords: "passwords", sessions: "custom_sessions" }

this is the custom_sessions_controller.rb file.

class CustomSessionsController < Devise::SessionsController

  def create
    binding.pry
    super
  end

  def destroy
  end


end
1

There are 1 best solutions below

0
widjajayd On

if you want to override devise SessionsController then

create file /app/controllers/devise/sessions_controller.rb

and below are the sample program that I use to redirect user after successfully login

  # frozen_string_literal: true

  class Devise::SessionsController < DeviseController
    include ApplicationHelper

    def new; end

    def create
      user = User.find_by_email(params[:user][:email])
      if user && user.valid_password?(params[:user][:password])
        sign_in(:user, user)
        flash[:success] = 'Login Success'
        redirect_to your_path_if_user_successfully_login
      else
        flash[:error] = 'Sorry, Login Error'
        redirect_to root_path
      end
    end

    def destroy
      sign_out current_user
      flash[:success] = 'Log Out Success'
      redirect_to root_url
    end
  end