DEV Community

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

Collapse
 
anunes profile image
anunes

i get this error with your code how do i fix this?

models/users.js:36
User.hook("beforeCreate", function(user) {
TypeError: User.hook is not a function

Collapse
 
lawmaina78 profile image
lawmaina78

How did you solve this, am getting a similar error

Collapse
 
sama profile image
Samaila Bala

I think sequelize modified their doc. I had to do this

Users.beforeCreate(user => {
    user.password = bcrypt.hashSync(
      user.password,
      bcrypt.genSaltSync(10),
      null
    );
  });

before it worked. Check out the doc Hooks

Thread Thread
 
selvaonline profile image
Selvakumar Murugesan

Can we use this authentication for Electron Desktop App too?

Thread Thread
 
sama profile image
Samaila Bala

I have no idea as I haven't used Electron

Collapse
 
gm456742 profile image
Richard Debrah

Hi @anunes . Thank you for taking time to read the article. Can you kindly (if possible) push your work to github and share with me? that will be easy for me to debug what is happening.

But User.hook not being a function basically means you are calling the hook on the wrong model or instance of User. Kindly check your code to make sure you are passing User as the model as your hook is supposed to be bound to it.

Collapse
 
lawmaina78 profile image
lawmaina78

Do you have the code of this app somewhere in Github so I can clone directly from there and study. I am also getting User.hook not a function error.