Ask A Question

Notifications

You’re not receiving notifications from this thread.

I want to use devise gem for normal authentication and api authentication with devise-jwt gem. Is it possible?

Nejdet Kadir Bektaş asked in Rails

Hi huys! I have an problem with devise-jwt gem. I have an default rails application. I want to use devise gem for normal authentication and api authentication with devise-jwt gem. But they can not running at the same time on my application.
this is for normal authentication:

Rails.application.routes.draw do

devise_for :users, controllers: {
sessions: 'users/sessions',
registrations: 'users/registrations',
}

# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
root to:'welcome#index'
end

but i want to use devise gem with API endpoints like this:

Rails.application.routes.draw do
namespace :api do
namespace :v1 do
scope 'users', module: 'users', defaults: { format: :json } do
devise_scope :user do
post '/login', as: :user_session, to: 'sessions#create'
delete '/logout', as: :destroy_user_session, to: 'sessions#destroy'
post '/signup', as: :user_registration, to: 'registrations#create'
end
end
end
end

devise_for :users, controllers: {
sessions: 'users/sessions',
registrations: 'users/registrations',
}

# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
root to:'welcome#index'
end

It is working but Authorization header is not being returned when sign in or sign up process

Reply

Hi Nejdet. I have exactly the same problem. Can you give me some ideas or tell me how you resolve it?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.