Skip to content
This repository was archived by the owner on Feb 9, 2025. It is now read-only.

fix(checkPwd): Error on Model == null#182

Open
FGBxRamel wants to merge 1 commit intoMaRcR11:mainfrom
FGBxRamel:fix/pwd-typeerror
Open

fix(checkPwd): Error on Model == null#182
FGBxRamel wants to merge 1 commit intoMaRcR11:mainfrom
FGBxRamel:fix/pwd-typeerror

Conversation

@FGBxRamel
Copy link
Copy Markdown

Hello again!
I tried to make a fix which I encountered during the attempt to set it up on my own.

Error

When first logging in, everything works. The problem comes when you want to come back (logging in with token). Following error occurs (full path replaced with "."):

TypeError: Cannot read properties of null (reading 'pwd')
    at checkPwd (.\server\src\helpers\checkPwd.helper.js:5:88)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async login (.\server\src\services\schedule.service.js:48:22)
    at async handleRequest (.\server\src\controllers\schedule.controller.js:5:20)
    at async login (.\server\src\controllers\schedule.controller.js:19:36)

Proposed fix

My proposed fix with this PR is to check whether or not the Model is null. I created a helper variable to check instead of the Model.

@MaRcR11
Copy link
Copy Markdown
Owner

MaRcR11 commented Dec 7, 2023

Hi @FGBxRamel,

I can't reproduce your error and in my case it also works with tokens.

There are other similar accesses in the code that are structured like this and don't cause any problems. With a little experimentation I was able to produce the same error, like:

module.exports = mongoose.model("pwd", GeneralModel, "passwrd");

With that typo "passwrd" it would run into that error.

However, this occurs when the model tries to access a non-existent collection. It should be assumed that the database is running, and if not, then the error there is ok too. If the database is running, even a missing field should only trigger an "undefined".

Maybe I'm missing something here or you can tell me exactly how you did it so that I could also get these errors?

@FGBxRamel
Copy link
Copy Markdown
Author

FGBxRamel commented Dec 7, 2023

Hey @MaRcR11 .

I will write a more detailed answer and try reinstalling everything asap, but this roughly is what I did:

  1. Create a MongoDB Server, making sure it's running
  2. Cloning the repo
  3. Installing all packages with npm
  4. Build the project
  5. Create the .env and fill in the MongoDB URL and a token
  6. Run the server (in VSC with a Debugger in my case)
  7. Go to localhost and log in (or register in that case)
  8. Reopen the site
  9. See the error and an endless loading screen (or at least 5 minutes, that's where I cut it)

Maybe it's worth noting that I did disable my Cache, but that shouldn't be a problem?

Like mentioned above, I'm gonna write something more in-depth asap. Besides that I'll try reinstalling everything (again), maybe I just missed something important.

@FGBxRamel
Copy link
Copy Markdown
Author

So @MaRcR11
I tried it again, set it up on another PC, completely reinstalled the DB. The error is still there and comes with every reload of the page, but I can login.
Next problem: The timetable is empty. Doesn't matter which PC, the table and agenda is empty.

Should I make a separate issue for that?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants