Home > Software engineering >  Login Component Error on React.js (codesandbox attached)
Login Component Error on React.js (codesandbox attached)

Time:05-01

I am a new programmer and I recently started following a Login Form tutorial, and I am experiencing a couple of issues with it.

Project Overview:

As previously described, it is a login form made with create-react-app. The objective is for the user to be able to login, if it is successful, it will log "Logged In" on the console. If there are errors or if its unsuccessful, it will log "Details Do Not Match".

The Problem:

Though I followed this tutorial line-by-line, there is an unseen error in my code that causes the console to log "Details Do Not Match". I am curious to see where I might have written the code incorrectly.

Below I've attached a working Codesandbox link of my code:

https://codesandbox.io/s/project-zi3un5

Thank You! Let me know what you think

Best,

Zpo

CodePudding user response:

You had a minor typo on line 17. You were comparing details.email to adminUser instead of adminUser.email

It should read:

if (details.email === adminUser.email && details.password === adminUser.password) {
  console.log("Logged In");
  setUser({
    name: details.name,
    email: details.email
});

Here's a fixed version: https://codesandbox.io/s/project-forked-nvmmyn

demo

  • Related