Created
March 22, 2019 07:24
-
-
Save hypeJunction/01ad254fc2c06714293c276322c3f18e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import BaseModel from '../db/BaseModel'; | |
export default class User extends BaseModel { | |
static registerHooks () { | |
this.beforeSave((user) => { | |
if (user.changed('password') && user.password) { | |
if (user.password.substr(0, 7) === 'bcrypt$') { | |
throw new Error('Do not bcrypt passwords before setting them'); | |
} | |
const hash = this.services.password.hash(user.password); | |
user.dataValues.password = `bcrypt$${hash}`; | |
} | |
}); | |
return this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment