#MERN App Project

1 messages · Page 1 of 1 (latest)

obtuse moss
#

Hi everyone, I am working on a MERN app tutorial, and have gotten stuck working on the log in feature. When trying to sign in, I get an error- Failed to load resource: the server responded with a status of 400 (Bad Request)

I've been through the code several times and cannot find where the error is coming from. If anyone can help, it would be greatly appreciated!!

Repo - https://github.com/patricksperanza/memories-project-2

GitHub

Contribute to patricksperanza/memories-project-2 development by creating an account on GitHub.

south imp
#

@obtuse moss Could be a number of different reasons, but I'll check through the code for you. One thing though, you shouldn't include the .env files in your repo. Those contain sensitive confidential information that hackers could use to access your database. That's why we use .env files in the first place, to separate the confidential information from the rest of the source code

#

Oh and you also included the node_modules folder from your server code in the repo too. Easy way to fix this is to move the .gitignore file from the client folder to the root, that way it will cover both the client and server folders

south imp
#

@obtuse moss Well, I found some of the issues. In your src/actions/auth.js file, line 9 you have this:

const { data } = await api.signIn(formData)

This is the destructuring syntax, but there isn't a property called data inside the formData object. You need to take out the {} from both the Signin and Signup functions, like this:

const data = await api.signIn(formData);

const data = await api.signUp(formData);
#

After that, there are more issues. When I try to sign up as a new user, the user is successfully being entered into the database, but there's something wrong with the server response, resulting in the "profile" item in localstorage being set to Undefined. This of course breaks the entire app

#

The same thing happens when I try to login

obtuse moss
#

Thank you! I’ll take a look at those. For the .env folder, do I add that to .gitignore, so that it doesn’t push to the repo?

south imp
obtuse moss
#

I got it! You were right about the profile in localStorage being set to undefined. Once I fixed that , it is working now. Thank you so much for your help!! I will make the fixes to the .env and node_modules folder, as well.

south imp
#

👍