DEV Community

Discussion on: Building a NodeJS Web App Using PassportJS for Authentication

Collapse
 
modimohini profile image
mohini • Edited

Thank you very much for help. The article is clear to understand.

I am getting this error:
\learningPassportJS\models\index.js:31
db[model.name] = model;
^
TypeError: Cannot read property 'name' of undefined

Not sure what I'm missing :(

Collapse
 
juancodeatatime profile image
Juan Rivera

I got the same error. It took several hours to troubleshoot. The below code worked for me. However, it requires adding "return User" in your js file that contains the User object. In my case, it's in my user.js file.

So, my index.js file code snippet looks like this:

.forEach((file) => {
const model = sequelize.import(path.join(__dirname, file))
console.log("model " + model)
try {
db[model.name] = model
console.log("working")
} catch (err) {
console.error(err)
}

My user.js file contains this important line of code:

return User;