File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
module4-authentication-and-security/r1.1-defining-authentication-layer Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,16 @@ class User extends Model {
60
60
hashed_password: DataTypes .BLOB , // you can store it as char too
61
61
},
62
62
// options
63
- { sequelize } // Pass the database connection instance
63
+ {
64
+ sequelize, // Pass the database connection instance
65
+ defaultScope: {
66
+ attributes: {
67
+ exclude: [" hashed_password" ], // don't query password by default
68
+ }
69
+ },
70
+ scopes: {
71
+ withPassword: { attributes: {} }
72
+ } }
64
73
);
65
74
}
66
75
@@ -320,7 +329,8 @@ class User extends Model {
320
329
static async login (username , password ) {
321
330
322
331
// attempt to find a user in the database with given username
323
- const user = await User .findOne ({
332
+ // Rememeber to use the withPassword scope so we query the password
333
+ const user = await User .scope (' withPassword' ).findOne ({
324
334
where: {
325
335
username,
326
336
},
You can’t perform that action at this time.
0 commit comments