Skip to content
Advertisement

AuthenticationController always throws error, TypeError: Cannot read property ‘create’ of undefined

I have an issue with the Authenticati onController used with sequelize and sqlite When I test the POST request using postman, it always gives status 400 with the response { error: ‘Something is wrong’ } enter image description here This is the log

::1 – – [21/Jul/2020:15:40:33 +0000] “POST /register HTTP/1.1” 400 30 “-” “PostmanRuntime/7.26.1”

enter image description here Here is the code of AuthenticationController

JavaScript

User model code

JavaScript

models index code

JavaScript

routes code

JavaScript

Earlier, it was throwing an error of “TypeError: Cannot read property ‘create’ of undefined” But when I restarted the server, that was fixed. But I have no clues as to why the try block fails.

Anyone could throw some light on this? Thank you

Advertisement

Answer

Here is the revised code for /models/index.js

JavaScript

The filter block was updated as shown in the revised, with the help of the link https://www.codota.com/code/javascript/functions/sequelize/Sequelize/import The 2 things that were changed are

  1. Replaced the ‘sequelize.import’ with ‘require’
  2. Updated the ‘filter’ block as shown.

Here is the result: enter image description here

Thanks to crumkev for the insight which led me find the answer.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement