nejdetkadir / devise-api

The devise-api gem is a convenient way to add authentication to your Ruby on Rails application using the devise gem. It provides support for access tokens and refresh tokens, which allow you to authenticate API requests and keep the user's session active for a longer period of time on the client side
MIT License
145 stars 22 forks source link

Support for both Api and webapp #41

Open ausangshukla opened 3 months ago

ausangshukla commented 3 months ago
  1. I have an existing web app with devise, and user login via a UI
  2. I want to enable APIs for the existing codebase
  3. Does this gem support both simultaneously?
  4. How can I set the current_user if the authentication is via devise-api gem ?

Thanks in advance

ausangshukla commented 3 months ago

For those looking to do this, here is what Ive done to make it work

def authenticate_user!
    if request.headers['Authorization'].present?
      authenticate_devise_api_token!
      @current_user = current_devise_api_user
    else
      super
    end
  end

  def verify_authenticity_token
    super if request.headers['Authorization'].blank? 
  end