I want to use Devise with two namespaces: the API namespace and the default namespace, but they seem inconsistent when the user tries to log in. Meaning, whatever namespace referencing Devise does not end first being the endpoint of the redirect. Example: if I try to create a new session in the default namespace, it will fail on this user session path, and then try to create a session on the API / v1 session path.
How to do two actions independently?
They both reference the User object. The user_sessions controller for the default namespace uses "user_sessions". The user user_sessions controller for the API / V1 namespace is "/ api / v1 / user_sessions"
---- ROUTES.RB ------- MySite::Application.routes.draw do namespace :api do namespace :v1 do devise_for :users,:controllers => { :sessions => "api/v1/ user_sessions",:registrations=>"users" } ...... end end devise_for :users,:controllers => { :sessions =>"user_sessions",:registrations=>"users" } do post 'users/sign_in' => 'user_sessions#create', :as => :user_session get 'users/sign_in' => 'user_sessions#new', :as => :new_user_session get 'users/sign_up' => 'user_sessions#new', :as => :new_user_session match 'users/sign_out' => 'user_sessions#destroy', :as => :destroy_user_session <.....> end
----- DEFAULT NAMESPACE USER_SESSIONS_CONTROLLER -----
class UserSessionsController < Devise::SessionsController .... end ----
API NAMESPACE USER_SESSIONS_CONTROLLER ---- (this applies to my custom Devise base controller noted below)
class Api::V1::UserSessionsController < Api::V1::DeviseBaseController ... end
---- CONTROLLER OF BASIC CONTROLLERS FOR PURPOSE OF THE BEST INDICATORS ----
class Api::V1::DeviseBaseController < Devise::SessionsController respond_to :json end
source share