Login system of MERN stack

Hello, FreeCodeCampers.

I am currently developing a MERN app based on MERN stack course by Brad Traversy. The original app is a social network for developers.

I modified it a bit to be a job portal for developers. I decided to make 2 type of accounts: company and developer/user. Currently I am facing an issue of log in. From designing the database to registering the user, I think I already have no issue, at least compared to original app logic.

The logic of logging in is:

  1. I have a login page for 2 type of accounts for developer and company.
  2. When user click one of the submit buttons, the server side check for any errors and doesn’t continue the logging in process.
  3. When all of the input requirements is met, the server continue the logging in process then redirect the page to dashboard.

When I test the login of user/developer, the app has no error. But when I test the login of company, the app produce errors and can’t redirect to dashboard, but the account is successfully logged in.

If I change the URL to other part of the app beside than the dashboard (currently only create-profile page) the app forgets the error but when I visit back the dashboard, one of the errors (the first error below) shows up again.

Here is the link of the latest code: https://github.com/mrfazry/dev-jobs

First error:

TypeError: Cannot read property 'companyProfile' of undefined at Dashboard.render (Dashboard.js:28)

What is weird is, correct me if I’m wrong, the companyProfile is already defined in one of the reducers from initialState object. When I watched the reducers part of the course, all of them have initialState, so they are all defined right? Of course the Dashboard.js has access to companyProfile from connect thing of react-redux.

Second error:

Uncaught (in promise) TypeError: Cannot read property 'data' of undefined at authActions.js:99

authActions.js has functions that use axios (both register and login, both company and developer). What is weird is when login company function is called, the log in still success but catch is still triggered. The catch is if there are errors.

Sorry if my explanation is so bad but I really don’t have any clue of these two problems. I don’t know what part of code to post because they are really long, so I only provide the link.

1 Like

I think I’ve found the problem. I didn’t import the companyProfileReducer to index.js to combine with other reducers.

Anyone want to contribute or give feedback is welcome.

1 Like

Good job there. I’m Joel and I was also trying to use this as a basis of a real-world project, the thing is I’m currently modelling the database, and I am trying to understand how to do it cos I would be separating the users into 3 models and would have 3 profile models. the issue is how do I have just one login logic and use routing to use it for either 3

Hi @alara_joel_stealth!

Since this is an older post from two years ago I would suggest creating a new topic of your own and campers would be happy to assist you there.

1 Like