working on new login sign up flow

This commit is contained in:
jackiettran
2025-07-29 23:48:09 -04:00
parent 6cba15d36a
commit 72d79596ce
10 changed files with 763 additions and 29 deletions

View File

@@ -11,19 +11,19 @@ const User = sequelize.define('User', {
username: {
type: DataTypes.STRING,
unique: true,
allowNull: false
allowNull: true
},
email: {
type: DataTypes.STRING,
unique: true,
allowNull: false,
allowNull: true,
validate: {
isEmail: true
}
},
password: {
type: DataTypes.STRING,
allowNull: false
allowNull: true
},
firstName: {
type: DataTypes.STRING,
@@ -34,10 +34,39 @@ const User = sequelize.define('User', {
allowNull: false
},
phone: {
type: DataTypes.STRING,
unique: true,
allowNull: true
},
phoneVerified: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
authProvider: {
type: DataTypes.ENUM('local', 'phone', 'google', 'apple', 'facebook'),
defaultValue: 'local'
},
providerId: {
type: DataTypes.STRING,
allowNull: true
},
address1: {
type: DataTypes.STRING
},
address: {
type: DataTypes.TEXT
address2: {
type: DataTypes.STRING
},
city: {
type: DataTypes.STRING
},
state: {
type: DataTypes.STRING
},
zipCode: {
type: DataTypes.STRING
},
country: {
type: DataTypes.STRING
},
profileImage: {
type: DataTypes.STRING
@@ -49,10 +78,12 @@ const User = sequelize.define('User', {
}, {
hooks: {
beforeCreate: async (user) => {
user.password = await bcrypt.hash(user.password, 10);
if (user.password) {
user.password = await bcrypt.hash(user.password, 10);
}
},
beforeUpdate: async (user) => {
if (user.changed('password')) {
if (user.changed('password') && user.password) {
user.password = await bcrypt.hash(user.password, 10);
}
}
@@ -60,6 +91,9 @@ const User = sequelize.define('User', {
});
User.prototype.comparePassword = async function(password) {
if (!this.password) {
return false;
}
return bcrypt.compare(password, this.password);
};