Utilize the power of Facebook login in your Parse client side application by integrating it with the user object

Currently, I am in the process of implementing a login system using both the Parse and Facebook Javascript SDK. While I have successfully implemented authentication on the client side, I am now facing the challenge of accessing the user object (generated by the Parse SDK) on the server side as well. I am considering whether setting a cookie when logging in via Facebook through Parse would allow me to access the user object from the server, or if I should handle the login process exclusively on the server side. I would greatly appreciate any suggestions or recommendations on the best approach to take.

Answer №1

Encountering the same issue led me to discover that you have the option of utilizing either server-side authentication or client-side authentication, but it's important not to mix the two. For more information, check out their official blog post about sessions.

var parseExpressCookieSession = require('parse-express-cookie-session');

// Setting up middleware...
app.use(express.cookieParser('YOUR_SIGNING_SECRET'));
app.use(parseExpressCookieSession({ cookie: { maxAge: 3600000 } }));

// Creating a "login" endpoint is incredibly straightforward.
app.post("/login", function(req, res) {
  Parse.User.logIn(req.body.username, req.body.password).then(function() {
    // Successfully logged in, redirecting to homepage.
    // parseExpressCookieSession will handle setting the cookie.
    res.redirect('/');
  },
  function(error) {
    // Login failed, redirect back to login form.
    res.redirect("/login");
  });
});  

Additionally, while delving into the documentation, I stumbled upon this valuable insight:

To implement Parse.User authentication and session management in your Express app, simply integrate the parseExpressCookieSession middleware. All you need to do is invoke Parse.User.logIn() in Cloud Code, and this middleware will autonomously manage the user session for you.

You can utilize a web form to collect the user's login details and log them in via Cloud Code after data submission from the form. Upon invoking Parse.User.logIn(), this middleware automatically establishes a cookie in the user’s browser. Subsequent HTTP requests made from the same browser will enable this middleware to automatically define the current user in Cloud Code.
...

It is highly recommended to use HTTPS when handling user data as a security measure. The parseExpressCookieSession middleware mandates the use of HTTPS to safeguard both your app and its users. Additionally, we offer a parseExpressHttpsRedirect middleware for seamlessly redirecting all HTTP requests to HTTPS.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Assign the DatePicker Object to an HTML Element

I am currently using a SyncFusion date picker in my project and the implementation looks like this: var datepicker = null; $("#datepicker").hide(); $("#click").click(function(){ $("#datepicker").show(); datepicker = new ej.calendars.DatePi ...

Automatic switching between Bootstrap 5 tab panes at precise time intervals

Is there a way to have the Bootstrap 5 tab-pane automatically switch between tabs at set intervals, similar to a Carousel? I found a code snippet on this link, but it appears to be outdated and only works for Bootstrap 3. Could someone assist me in updati ...

Certain CSS styles for components are missing from the current build

After building my Vue/Nuxt app, I noticed that certain component styles are not being applied. In the DEVELOPMENT environment, the styles appear as expected. However, once deployed, they seem to disappear. All other component styles render properly. Dev ...

Leveraging periods within a MySQL database: Node.js for seamless updates

I am currently facing a challenge in updating a column name that contains a period in node using node-mysql. I appreciate the convenience of being able to update multiple columns by providing an object with keys, but the string escaping process with node-m ...

Getting information from MongoDB using Node.js and Angular

Currently, I am facing difficulty in retrieving data from MongoDB (I'm also using Mongoose) and sending it to Angular in order to populate the ng-repeat list with the retrieved data. I have managed to either display the data on a blank page directly f ...

A Guide to Listing Private JavaScript Class Properties

What is the best approach to iterate through private class fields? class Person { #isFoo = true; #isBar = false; constructor(first, last) { this.firstName = first; this.lastName = last; } enumerateSelf() { console.log(this); ...

Unable to execute Protractor using Node.js command line

Hi there! Currently, I am in the process of setting up protractor for the very first time using Node.js. I found detailed instructions on how to do this on the AngularJS website under the section "Running E2E Tests": https://docs.angularjs.org/tutorial Ho ...

Implementing associations with ES6 syntax and utilizing a default created Model (ensuring it is not associated with another Model

What am I doing? I am attempting to establish an association with my Folder model, using the default model created by CLI. It's worth noting that I am trying to associate the model with itself, so Folder.hasMany.Folder. What am I trying to achieve? ...

Retrieving JavaScript array data following a page reload

I am facing an issue with updating an array dynamically in my C# server-side code and then utilizing the updated data in a JQuery function on my webpage. When the page first loads, the array is filled with some default values by C#. However, when a user ma ...

Having trouble retrieving the desired data from the JSON file

My current code is not giving me the expected results while trying to access JSON values with jQuery. Any suggestions on how I can resolve this issue? // JSON response: [{ "private": "8044553.0" }, { "governmentdocs": "98952.0" }, { "officiald ...

Developing an interactive selector within the on() event handler

My goal is to utilize the on() event for managing dynamically created code. It functions properly when the selector is hardcoded in the on() event. However, I aim to enable it to select different elements depending on which box they choose. $("body").on( ...

Running express in your Electron application: A simplified guide

Running express within an electron app has been a success with the help of various repositories that I found, including: https://github.com/theallmightyjohnmanning/electron-express https://github.com/frankhale/electron-with-express However, I have been ...

Unable to get spacing correct on loading page

My attempt at creating a loading page using CSS and HTML has hit a roadblock. I'm trying to show a loading bar that ranges from 0% to 100%. Despite my use of justify-content: space-between, I can't seem to get it right. I've searched through ...

Hiding rows in a Datatable

Assistance needed to conceal specific rows in the datatable, If the User opts for "Show All" from the dropdown menu, the entire datatable should be displayed, However, if the User chooses "Hide USA", I wish to hide the rows with the Country value set ...

How can JavaScript be used to make an AJAX request to a server-side function?

I am diving into the world of AJAX and feeling a bit uncertain about how to structure my AJAX call. $.ajax({ type: "POST", url: "Default.aspx/function", data: '{ searchBy: id }', contentType: "application/json; charset=utf-8" }). ...

Fetching Dependencies with NPM from the package.json file

I am feeling a bit puzzled. While working on my laptop, dependencies were automatically added to my package.json file as I installed them for my project. This is how it appears: "main": "webpack.config.js", "dependencies": { "immutable": "^3.7.6", ...

Is there a way to reach my vue instance while inside a v-for iteration?

When using a v-for loop, I encounter an error: <div v-for="index in 6" :key="index"> <div class="card h-100" style="margin-top: 200px;"> <a href="#"> <img ...

Create a substitute for Object.seal, Object.freeze, and Object.preventExtensions applications

Is there a way to freeze an object's existing properties while still allowing new ones to be added? I can't seem to find any built-in functionality for Object.freezeExisting(), so maybe it's worth considering implementing it, possibly even w ...

Discovering Angular 2 Service Change Detection

Exploring the Angular 2 beta has led me to some challenges with understanding the change detection mechanism. I have put together a simple Plunker example that demonstrates an issue I am encountering. //our root app component import {Component, Injectab ...

Cannot get Firebase's set() method to work when called within onAuthStateChanged() function

As I embark on developing my first significant web application using ReactJS with Firebase as the backend database, everything was progressing smoothly until a troublesome issue surfaced. The hurdle I encountered involves saving user information upon thei ...