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 8194735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:55:26+00:00 2026-06-07T04:55:26+00:00

On a website I’m developing, using Node, Express, and Backbone, I have the user

  • 0

On a website I’m developing, using Node, Express, and Backbone, I have the user login using a regular HTML form that, when successfully logged in, creates a user session. Accessing this session info is easy on the server-side, giving me access to the User ID, Username, etc., but I’m not sure on how to access this information in Backbone.

I want to acquire the UserID such that I can create a URL for a Collection like this:

url: '/api/users/'+ this.userID +'/movies'; 

But I’m not sure how to best go about acquiring the userID based upon the Session data that’s on the server-side. Would this require creating another model — say, a ‘User’ model that fetches the session data from the server, through a particular url/get request?

Thanks!

  • 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-07T04:55:28+00:00Added an answer on June 7, 2026 at 4:55 am

    I came up with something, but would still be open to suggestions:

    First, create a function in Express.js that returns the userId:

    app.get('/api/current-user', middleware.requiresLogin, function(req, res){
      res.send(req.session.user._id);
    });
    

    Second, on the client side, retrieve the ID using either a Backbone model or $.get request:

    var userID = $.get("/api/current-user");
    
    $.when(userID).then(function(data){
        var user = new userCollection(data);
        user.fetch();
    });
    

    With your collection and model doing this:

    window.userModel = Backbone.Model.extend({
        idAttribute: "_id"
    });
    
    var userCollection = Backbone.Collection.extend({
        model: userModel,
        initialize: function(options){
            this.url = "/api/users/"+options+"/movies";
            this.model.urlRoot = "/api/users/"+options+"/movies";
        }
    });
    

    myModel.save(); then works correctly.

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

Sidebar

Related Questions

My website needs to have a form that automatically submits, sending the user (with
My website project includes taking data from the user in the form of two
My website (running on the express framework) suddenly started complaining that it needed a
Website using .NET Framework v3.5, SQL Server 2008, written in C# I have a
My website needs a .htaccess file that will redirect a user to index.php when
A website that I've been working on was originally created using XHTML 1.0 Transitional
My website is built using php files. I use trade secret algorithms in these
my website has a log in by open id feature. When a user logs
Our website has one section which often changes to match the user. (examples are
for website that embed flash to capture camera (red5..etc). may i know is there

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.