File tree Expand file tree Collapse file tree 2 files changed +10
-11
lines changed Expand file tree Collapse file tree 2 files changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -43,8 +43,8 @@ async function login(req, res) {
43
43
} ) ;
44
44
}
45
45
46
- return user . comparePassword ( req . body . password , ( err , isMatch ) => {
47
- if ( isMatch && ! err ) {
46
+ return user . comparePassword ( req . body . password , ( match ) => {
47
+ if ( match ) {
48
48
const token = jwt . sign ( JSON . parse ( JSON . stringify (
49
49
{ userId : user . id , username : user . username } ,
50
50
) ) , secretKey , { expiresIn : 86400 * 30 } ) ;
Original file line number Diff line number Diff line change @@ -13,19 +13,18 @@ module.exports = (sequelize, DataTypes) => {
13
13
} ,
14
14
} ) ;
15
15
16
- User . beforeSave ( ( user ) => {
16
+ User . beforeSave ( async ( user ) => {
17
17
if ( user . changed ( 'password' ) ) {
18
- user . password = bcrypt . hashSync ( user . password , bcrypt . genSaltSync ( 10 ) , null ) ;
18
+ user . password = await bcrypt . hash ( user . password , 10 ) ;
19
19
}
20
20
} ) ;
21
21
22
- function comparePassword ( passw , cb ) {
23
- bcrypt . compare ( passw , this . password , ( err , isMatch ) => {
24
- if ( err ) {
25
- return cb ( err ) ;
26
- }
27
- return cb ( null , isMatch ) ;
28
- } ) ;
22
+ async function comparePassword ( password , cb ) {
23
+ const match = await bcrypt . compare ( password , this . password ) ;
24
+ if ( match ) {
25
+ return cb ( match ) ;
26
+ }
27
+ return cb ( false ) ;
29
28
}
30
29
31
30
User . prototype . comparePassword = comparePassword ;
You can’t perform that action at this time.
0 commit comments