diff --git a/server/storage.ts b/server/storage.ts index ec226a3..c0f80c1 100644 --- a/server/storage.ts +++ b/server/storage.ts @@ -142,11 +142,11 @@ export class DatabaseStorage implements IStorage { async createUser(user: InsertUser): Promise { // Hash password before storing - const hashedPassword = await bcrypt.hash(user.password, 12); + const hashedPassword = await bcrypt.hash(user.passwordHash, 12); const result = await db.insert(users).values({ ...user, - password: hashedPassword, + passwordHash: hashedPassword, updatedAt: new Date() }).returning(); return result[0]; @@ -156,8 +156,8 @@ export class DatabaseStorage implements IStorage { const updateData: any = { ...updates, updatedAt: new Date() }; // Hash password if it's being updated - if (updates.password) { - updateData.password = await bcrypt.hash(updates.password, 12); + if (updates.passwordHash) { + updateData.passwordHash = await bcrypt.hash(updates.passwordHash, 12); } const result = await db.update(users) @@ -175,9 +175,9 @@ export class DatabaseStorage implements IStorage { email: userData.email, firstName: userData.firstName, lastName: userData.lastName, - profileImageUrl: userData.profileImageUrl, + avatar: userData.profileImageUrl, username: userData.email || `user_${userData.id}`, - password: '', // No password for OAuth users + passwordHash: '', // No password for OAuth users isAdmin: false, isSuperAdmin: false, }) @@ -187,7 +187,7 @@ export class DatabaseStorage implements IStorage { email: userData.email, firstName: userData.firstName, lastName: userData.lastName, - profileImageUrl: userData.profileImageUrl, + avatar: userData.profileImageUrl, updatedAt: new Date(), }, }) @@ -199,7 +199,7 @@ export class DatabaseStorage implements IStorage { const user = await this.getUserByEmail(email); if (!user) return null; - const isValid = await bcrypt.compare(password, user.password); + const isValid = await bcrypt.compare(password, user.passwordHash); return isValid ? user : null; } @@ -526,15 +526,16 @@ export class MemStorage implements IStorage { async createUser(user: InsertUser): Promise { const id = randomUUID(); - const hashedPassword = await bcrypt.hash(user.password, 12); + const hashedPassword = await bcrypt.hash(user.passwordHash, 12); const fullUser: User = { ...user, id, - password: hashedPassword, + passwordHash: hashedPassword, firstName: user.firstName || null, lastName: user.lastName || null, - profileImageUrl: user.profileImageUrl || null, + avatar: user.avatar || null, + isActive: user.isActive ?? true, isAdmin: user.isAdmin ?? false, isSuperAdmin: user.isSuperAdmin ?? false, createdAt: new Date(), @@ -549,8 +550,8 @@ export class MemStorage implements IStorage { if (!user) return undefined; const updateData: any = { ...updates, updatedAt: new Date() }; - if (updates.password) { - updateData.password = await bcrypt.hash(updates.password, 12); + if (updates.passwordHash) { + updateData.passwordHash = await bcrypt.hash(updates.passwordHash, 12); } const updatedUser: User = { @@ -568,9 +569,10 @@ export class MemStorage implements IStorage { email: userData.email, firstName: userData.firstName, lastName: userData.lastName, - profileImageUrl: userData.profileImageUrl, + avatar: userData.profileImageUrl, username: userData.email || `user_${userData.id}`, - password: '', + passwordHash: '', + isActive: existingUser?.isActive ?? true, isAdmin: existingUser?.isAdmin || false, isSuperAdmin: existingUser?.isSuperAdmin || false, createdAt: existingUser?.createdAt || new Date(), @@ -584,7 +586,7 @@ export class MemStorage implements IStorage { const user = await this.getUserByEmail(email); if (!user) return null; - const isValid = await bcrypt.compare(password, user.password); + const isValid = await bcrypt.compare(password, user.passwordHash); return isValid ? user : null; } diff --git a/shared/schema.ts b/shared/schema.ts index 010244c..790d7c3 100644 --- a/shared/schema.ts +++ b/shared/schema.ts @@ -39,14 +39,15 @@ export const videos = pgTable("videos", { // User table for authentication and video ownership export const users = pgTable("users", { - id: varchar("id").primaryKey().default(sql`gen_random_uuid()`), + id: varchar("id").primaryKey(), username: varchar("username", { length: 50 }).notNull().unique(), email: varchar("email", { length: 255 }).notNull().unique(), - password: varchar("password", { length: 255 }).notNull(), + passwordHash: varchar("password_hash", { length: 255 }).notNull(), firstName: varchar("first_name", { length: 100 }), lastName: varchar("last_name", { length: 100 }), - profileImageUrl: text("profile_image_url"), - isAdmin: boolean("is_admin").default(false).notNull(), + avatar: text("avatar"), + isActive: boolean("is_active").default(true).notNull(), + isAdmin: boolean("is_admin").default(false), isSuperAdmin: boolean("is_super_admin").default(false).notNull(), createdAt: timestamp("created_at").notNull().default(sql`CURRENT_TIMESTAMP`), updatedAt: timestamp("updated_at").notNull().default(sql`CURRENT_TIMESTAMP`),