The process of logging in with Parse.User encounters a glitch

I developed a user login feature:

export const userLogin = (email, password) => (dispatch) => {
    console.log(email, password);
  dispatch({ type: actionTypes.AUTH_LOGIN_STARTED });
  console.log("after dispatch");
  Parse.User.logIn(email, password, {
    success(user) {
        console.log("in success");
      dispatch({
        type: actionTypes.AUTH_LOGIN_SUCCESS,
        user: user.toJSON(),
      });
     window.location.replace('/');
    },
    error(user, error) {
        console.log("in error")
      console.log({ error });
      // The login failed. Check error to see why.
      dispatch({
        type: actionTypes.AUTH_LOGIN_ERROR,
        error,
      });
    },
  });
};

However, it seems to get stuck after the Parse.User.logIn function and does not trigger either the success or error callback. I've verified that the email and password are correct.

What could be causing this issue?

Answer №1

Parse.User.Login does not have a third parameter available. It is recommended to utilize promise functions:

Parse.User.logIn(email, password)
  .then((user) => {
    console.log("in success");
    dispatch({
      type: actionTypes.AUTH_LOGIN_SUCCESS,
      user: user.toJSON(),
    });
    window.location.replace('/');
  })
  .error((user, error) => {
    console.log("in error")
    console.log({ error });
    // The login failed. Check error to see why.
    dispatch({
      type: actionTypes.AUTH_LOGIN_ERROR,
      error,
    });
  });

Alternatively, you can opt for the modern await syntax (which may provide cleaner code):

export const userLogin = (email, password) => async (dispatch) => {
  console.log(email, password);
  dispatch({ type: actionTypes.AUTH_LOGIN_STARTED });
  console.log("after dispatch");

  try {
    const user = await Parse.User.logIn(email, password);
    console.log("in success");
    dispatch({
      type: actionTypes.AUTH_LOGIN_SUCCESS,
      user: user.toJSON(),
    });
    window.location.replace('/');
  } catch (error) {
    console.log("in error")
    console.log({ error });
    // The login failed. Check error to see why.
    dispatch({
      type: actionTypes.AUTH_LOGIN_ERROR,
      error,
    });
  }
};

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

How can I code a div to automatically scroll to the top of the page?

I'm attempting to implement something similar in WordPress - I want a div containing an advertisement to initially start 300px down the page, then scroll up with the page until it reaches the top, and finally stay there if the user continues to scroll ...

What is the best way to update just the image path in the source using jQuery?

I am currently working on implementing a dark mode function for my website, and I have successfully adjusted the divs and other elements. However, I am facing an issue with changing the paths of images. In order to enable dark mode, I have created two sep ...

The name 'withStyles' is nowhere to be found

import * as React from "react"; import Button from "@material-ui/core/Button"; import * as PropTypes from "prop-types"; import {WithStyles} from '@material-ui/core'; import "./App.css"; import PageTwo from "./components/PageTwo"; ...

Error: Attempting to call vector.subSelf method, which does not exist

Currently, I am experimenting with creating a tank game inspired by Isaac Sukin's "Nemesis" game for AngelHack. The specific change I want to make involves using a model of a tank ("Tank.obj") instead of the default cube used as an enemy. However, I ...

React: When state is updated and a console.log is used, the console displays the previous state instead of the updated

Upon clicking the button, a peculiar sequence unfolds - the console displays 0 and the page refreshes to show 1 function App() { const [count, setCount] = useState(0); const addOne = () => { setCount(count + 1) console.log(count) } ...

Vue event manager, accessible for all components

I have created a new Vue instance and assigned it to the window object, thinking that it would be accessible throughout all components. I expected this setup to allow me access to events emitted anywhere within my application. However, it seems like this ...

Angular's window.onload event occurs when the page has finished

How can I achieve the equivalent of window.onload event in Angular? I am looking to fade out and remove my preloader, but only after all resources such as images are fully loaded. Using $viewContentLoaded alone does not cover this scenario since it indica ...

Encountered an Error: The JSON response body is malformed in a NextJS application using the fetch

Running my NextJS app locally along with a Flask api, I confirmed that the Flask is returning proper json data through Postman. You can see the results from the get request below: { "results": [ [ { "d ...

knockout, loop within a loop

Imagine I have a group of Humans who own Cats, and those Cats have Kittens class Person { String name; Cat[] cats; } class Cat { String name; Kitten[] kittens; } class Kitten { String name; } Now I want to display all my Kittens with ...

Issue with React-Route not displaying components

Below is the code snippet from my app.js file: <Router> <Header title="My Todos List" /> <Routes> <Route path="/about" element={<About />} /> <Route path="/" ...

The images that have been uploaded display only a few thumbnails

My goal is to display thumbnail images along with an input field next to them after they are uploaded to the server. The issue I'm facing is that my function attempts to display the images before they are actually uploaded. I believe the problem lies ...

Discover information about the client using the node.js net library

I have implemented a nodejs cluster with socket.io, where the master thread uses the net library to listen on a port and pass connections to workers based on the client's IP address. Everything is functioning properly, but I am interested in testing b ...

I keep encountering the error message "ReferenceError: window is not defined" in Next.js whenever I refresh the page with Agora imported. Can someone explain why this is happening?

Whenever I refresh my Next.js page with Agora SDK imported, I keep encountering the error "ReferenceError: window is not defined". It seems like the issue is related to the Agora import. I attempted to use next/dynamic for non-SSR imports but ended up with ...

Retrieve the HTML contents of a cell that contains a checkbox with the value of "jquery"

Here is an example of a table row: <tr> <td><input type='checkbox' name='post[]' value="1"></td> <td>08-Apr-2014</td> <td>injj team</td> <td>merchant.testyy.com</ ...

The exceljs function for downloading an Excel workbook is not activated by using the Post method

Presently, I am engaged in the development of a React and Node application. This app is designed to store data entries in a database, with the capability for users to download all stored data in an Excel workbook. To make this possible, I have integrated ...

What is the significance of the double exclamation mark operator in determining the truthiness or falsiness of an object's values?

Trying to determine the truthiness or falsiness of an object is proving to be a challenge for me. If an object contains all truthy values, I want one outcome; if it contains falsy values such as 0, an empty string, or undefined, I want a different outcom ...

Enhancing the smoothness of parallax scrolling

My header is going to be twice the height of the viewport. I added a simple parallax effect so that when you scroll down, it reveals the content below. However, I'm experiencing flickering in the content as I scroll, possibly due to the CSS style adju ...

Creating a stylish look for a selection of multiple menu options

option:active { color: red; } option:focus { color: green; background: green; } option:checked { color: yellow; background: yellow; } <select multiple> <option>One</option> <option>Two</option> <option&g ...

ESLint flagging "Unexpected tab character" error with "tab" indentation rule enabled

Currently, my ESLint setup includes the Airbnb plugin (eslint-config-airbnb) along with the Babel parser. I recently decided to enforce the rule of using Tab characters for indentation instead of spaces. This is how my .eslintrc file looks like: { "p ...

Issues with jQuery Ajax functionality in Rails application not achieving successful completion

When a card is moved onto another stack, an Ajax call is triggered twice. This only happens when there are multiple stacks. However, if the cards are rearranged within the same stack, the call is triggered only once. The Ajax call sends an array of IDs fo ...