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

The TransferList component in Material UI does not update its state based on props when using the useState

My TransferList component in Material UI receives an array of previously selected items as props.selectedItems. The props.Items contains all available items. I expected to see props.selectedItems in the left panel of TransferList, but the left panel is em ...

Activation of navigation buttons in the Vue Full Calendar control the movement to the next and previous

In my current project, I am utilizing https://www.npmjs.com/package/vue-full-calendar. However, I have encountered an issue when trying to receive callbacks or triggers from the next and previous buttons on the calendar. My backend API is structured aroun ...

What is the ideal amount of data to store in browser cache?

I am facing the challenge of loading thousands of user data records from a REST service, specifically user contacts in a contact-management system, and conducting a search on them. Unfortunately, the existing search functionality provided by the REST servi ...

Integrating Watson Conversation with Oracle Database

Hello everyone, I am currently working on a project where I need Watson to fetch a response manually set from our Oracle Databases. To achieve this, I am using async to access the database sequentially and return the response. Initially, I faced an issue ...

ng-repeat not displaying any content

I am trying to create a form where users can input extra information by adding new rows, but I am struggling with generating the first row <div ng-repeat="row in rows"> <input type="text" placeholder="name"><input type="tel" placeholder="te ...

Encountering an issue while trying to convert a JSON object into an array of a specific class type

When I receive a JSON object from a service, I want to iterate through this object and populate an array of class types. Below is the code used to call the service: public GetMapData(): Observable<Response> { var path = 'http://my.blog.net ...

Tips on maintaining the numerical value while using JSON.stringify()

Having trouble using the JSON.stringify() method to convert some values into JSON format. The variable amount is a string and I want the final value in JSON format to be a number, but it's not working as expected. Even after applying JSON.stringify(), ...

changing the visible style of a div element using JavaScript

I'm having an issue with a link on my webpage that is supposed to show or hide a <div id="po" style="display:none;">some html</div> element. The first time I click the link, the div displays properly. However, after tha ...

Setting state back to default following the conditional rendering of a React component

Whenever the save button is clicked, I aim to display a snackbar component by updating the showSnackbar state to true. To achieve this in React, it's just a simple conditional check in the main render method. The snackbar I'm using here automatic ...

Implementing Express 4: The Correct Way to Serve Routes from External Files

Something about my Express 4 application is causing me frustration. Here's the configuration: routes/profile.js var express = require('express'); var router = express.Router(); router.get('/profile', function(req, res) { res.s ...

Choose Your Price - Price Grids

I need to incorporate two sets of pricing columns into a website. The first set is for regular car cleaning prices, while the second set is for larger cars with slightly higher prices. My idea is to have two buttons at the top – one for regular cars and ...

Capture JavaScript results using PHP

I'm looking for a way to save the output or result of JavaScript code. For example: <script>document.write(navigator.appVersion)</script> When it comes to PHP, I have no issues: $ip = $_SERVER['REMOTE_ADDR']; $file = "log.txt ...

What is the best way to adjust the size of a canvas and then upload the resized information to a

I need to update the user's database table row data with new resized dimensions (changing width and height). For instance: In my online editor, I create a canvas of size 1000x500, add objects, and save -> This data is sent to the database When re ...

Require assistance in accurately assigning a date to a Date[] in Typescript Array without altering current elements

In my current code, I have a loop that verifies if a date is a holiday and then adds it to an array. The issue I'm facing is that whenever I assign a new element to the array, all previous data in the list gets updated to the latest element. Here&apos ...

Experiencing challenges with ng-repeat and the concept of 'distinct'

I'm facing a perplexing issue. When utilizing ng-repeat to iterate through my data and create checkboxes, I encounter unexpected behavior. The result is multiple duplicate items being displayed instead of unique ones. Here's an example: <lab ...

Ways to implement user-specific rate limiting?

In my application, there is a credit-based usage system in place. Unfortunately, the current structure allows users to make multiple requests within a short time frame, leading to a faulty system where they end up with negative credit values due to double ...

"Adding dots" in a slideshow using HTML, CSS, and JS

I'm currently working on a slideshow that includes navigation dots at the bottom. Although the slideshow is functioning properly, I am encountering an issue where only one dot appears instead of the intended three in a row. Despite my research and att ...

Avoid page refreshing when modifying app.js in React

Today is only my second day using React and I started by creating a React app with "npx create-react-app." However, when I tried to make changes to the app.js file, they didn't appear on the page even after refreshing the browser multiple times. (My n ...

Error in hook order occurs when rendering various components

A discrepancy was encountered in React when attempting to render different components Warning: React has detected a change in the order of Hooks called by GenericDialog. This can result in bugs and errors if left unresolved. Previous render Next ren ...

Tips for crafting services using $q and $http requests while avoiding redundancy

Is there an elegant way to write AngularJS services without repetitive $q syntax? I currently write services like this: (function() { function ServiceFactory($q, $timeout, $http) { return { getFoo: function() { va ...