devise-api icon indicating copy to clipboard operation
devise-api copied to clipboard

Support for both Api and webapp

Open ausangshukla opened this issue 2 years ago • 1 comments

  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 avatar Apr 16 '24 07:04 ausangshukla

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

ausangshukla avatar Apr 16 '24 09:04 ausangshukla

Does this gem support both simultaneously?

yes you can use this gem with your existing web app. Just you need to create some helpers like already sent. 🙌

nejdetkadir avatar Sep 27 '24 17:09 nejdetkadir