Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8903479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:52:48+00:00 2026-06-15T01:52:48+00:00

I want to use Devise with two namespaces: an API namespace, and the default

  • 0

I want to use Devise with two namespaces: an API namespace, and the default namespace,
but the two seem to be conflicting when a user tries to sign in.
Meaning, whichever namespace that references Devise first ends up
being the final redirection place. Ex: If I try to create a new session
under the default namespace it will fail on that user session path,
and then attempt to create the session on the API/v1 sessions path.

How do I make the two act independently?

They are both referencing a User object. The user_sessions controller
for the default namespace is ‘user_sessions’. The 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 goes to my custom Devise base controller marked below)

class Api::V1::UserSessionsController < Api::V1::DeviseBaseController
...
end

—- API NAMESPACE CUSTOM DEVISE BASE CONTROLLER —-

class Api::V1::DeviseBaseController < Devise::SessionsController
       respond_to :json
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:52:49+00:00Added an answer on June 15, 2026 at 1:52 am

    I found out that this isn’t possible with Devise, you have to have one sign-in/sign out source.

    Clean solution: Create routes for both your API and Web namespaces that point back to the same Devise controller code (say, /user/sessions). In there, call partials for the appropriate response (JSON, HTML). Those partials can sit in the view directories for each namespace, keeping things clean.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models, user & offline_user, and I want to use a dropdown
I want to use devise's tokens to support logging in/out in multiple clients at
I use Devise in Rails 3. I want to see name of current_user in
I want use BYTE_ORDER macro in my Xcode project but i can't because i
I want use JQuery mobile for the front-end of my mobile application, but I
I want to use sudo to mount two separate network drives on an ad-hoc
So I have two string that were padded, but now I want them show
I want to use java Sockets to connect two Android devices on different networks.
I want to use screen rotation in android device. But I don't want to
I want to use ALAssetsLibrary framework for displaying photos from the photo album.But while

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.