GWM : removed password scope

This commit is contained in:
Gowtham M 2025-12-04 17:45:29 +05:30
parent 510fc030ec
commit 7613a5f9b7
2 changed files with 34 additions and 46 deletions

View File

@ -65,30 +65,24 @@ module.exports = (sequelize, DataTypes) => {
timestamps: false,
tableName: "establishment_users",
},
{
// 1. EXCLUDE sensitive fields from all queries
defaultScope: {
attributes: { exclude: ["password", "reset_otp", "reset_otp_expires_at"] },
},
// {
// // 1. EXCLUDE sensitive fields from all queries
// defaultScope: {
// attributes: { exclude: ["password", "reset_otp", "reset_otp_expires_at"] },
// },
// 2. Ensure manual selections still hide sensitive fields
scopes: {
withSensitive: {
attributes: { include: ["password", "reset_otp", "reset_otp_expires_at"] },
},
},
// 3. Remove sensitive fields when converting to JSON
instanceMethods: {
toJSON() {
const values = { ...this.get() };
delete values.password;
delete values.reset_otp;
delete values.reset_otp_expires_at;
return values;
},
},
}
// // -------------------------------------------------------------
// // 2. Special scope for login or OTP flows
// // Use: User.scope("withSensitive").findOne(...)
// // -------------------------------------------------------------
// scopes: {
// withSensitive: {
// attributes: {
// include: ["password", "reset_otp", "reset_otp_expires_at"],
// },
// },
// },
// }
);
EstablishmentUser.associate = (models) => {

View File

@ -35,30 +35,24 @@ module.exports = (sequelize, DataTypes) => {
defaultValue: true,
},
},
{
// 1. EXCLUDE sensitive fields from all queries
defaultScope: {
attributes: { exclude: ["password", "reset_otp", "reset_otp_expires_at"] },
},
// {
// // 1. EXCLUDE sensitive fields from all queries
// defaultScope: {
// attributes: { exclude: ["password", "reset_otp", "reset_otp_expires_at"] },
// },
// 2. Ensure manual selections still hide sensitive fields
scopes: {
withSensitive: {
attributes: { include: ["password", "reset_otp", "reset_otp_expires_at"] },
},
},
// 3. Remove sensitive fields when converting to JSON
instanceMethods: {
toJSON() {
const values = { ...this.get() };
delete values.password;
delete values.reset_otp;
delete values.reset_otp_expires_at;
return values;
},
},
}
// // -------------------------------------------------------------
// // 2. Special scope for login or OTP flows
// // Use: User.scope("withSensitive").findOne(...)
// // -------------------------------------------------------------
// scopes: {
// withSensitive: {
// attributes: {
// include: ["password", "reset_otp", "reset_otp_expires_at"],
// },
// },
// },
// }
);
return User;