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

  • Home
  • SEARCH
  • 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 6202679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:46:52+00:00 2026-05-24T04:46:52+00:00

I use Devise and Basic HTTP Authentication to access user areas from a mobile

  • 0

I use Devise and Basic HTTP Authentication to access user areas from a mobile app. When the user enters its details in the app and it tries to “login” (you don’t actually login with basic auth as you send the credentials with each request) I want to get a response back with the user info, like user ID and email.

When I try to get a resource I get a response like this:

[
 -
 {
    email: "em...@example.com"
    username: "Example"
 }
 -
  [
  -
  {
     created_at: "2011-07-26T11:30:55Z"
     id: 1
     title: "Test"
     updated_at: "2011-07-26T11:30:55Z"
     user_id: 1
  }
  -
  {
     created_at: "2011-07-26T16:53:26Z"
     id: 2
     title: "Test2"
     updated_at: "2011-07-26T16:53:26Z"
     user_id: 1
  }
 ]
]

So I get the user object at the beginning. However, I need to add the user ID as well. I can’t use the user_id in the items because that won’t be rendered if the user has no items.

Any tips?

  • 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-05-24T04:46:53+00:00Added an answer on May 24, 2026 at 4:46 am

    You probably need to extend Devise::SessionsConroller. In your controllers folder, add a users folder and then add a file called sessions_controller.rbthat contains this:

    class Users::SessionsController < Devise::SessionsController
      def new
        super
        render :json => {:id => current_user.id}.to_json
      end
    end
    

    In your routes.rb:

      devise_for  :users, 
                  :controllers => {:sessions => 'users/sessions'}
    

    EDIT

    Try this. Take that line out of your routes.rb. In application_controller.rb add this:

      # Devise override
      def after_sign_in_path_for(resource) 
        render :json => {:id => resource.id}.to_json
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use Devise for authentication on a model that heavily relies on caching. Because
I am in the process updating my app so I use the Devise gem
in my rails 3 app I use devise. For the password reset form I
We use a data acquisition card to take readings from a device that increases
When you use visual studio to deploy to a windows mobile device it automatically
I have an app that uses Devise to do account creation, etc. But I
I am writing a component to parse data collected from various devices. Basic purpose
I would like to stream video from an iPhone camera to an app running
I've written a fairly basic app for the iPhone, which I would like to
Hey guys, I am trying to build an app that will use a compass

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.