Skip to content

Commit b93dea0

Browse files
committed
added scoped querying
1 parent b20b181 commit b93dea0

File tree

1 file changed

+12
-2
lines changed
  • module4-authentication-and-security/r1.1-defining-authentication-layer

1 file changed

+12
-2
lines changed

module4-authentication-and-security/r1.1-defining-authentication-layer/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,16 @@ class User extends Model {
6060
hashed_password: DataTypes.BLOB, // you can store it as char too
6161
},
6262
// 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+
} }
6473
);
6574
}
6675

@@ -320,7 +329,8 @@ class User extends Model {
320329
static async login(username, password) {
321330

322331
// 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({
324334
where: {
325335
username,
326336
},

0 commit comments

Comments
 (0)