From 23dddf2bc59d6ed7e0fb18907907f6ee232ac657 Mon Sep 17 00:00:00 2001 From: VarshithReddy2006 Date: Fri, 19 Jun 2026 09:36:01 +0530 Subject: [PATCH 1/2] fix(auth): normalize email storage and lookup handling --- .../src/controllers/userAuth.controller.js | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/apps/public-api/src/controllers/userAuth.controller.js b/apps/public-api/src/controllers/userAuth.controller.js index 217a0708c..399e77e8a 100644 --- a/apps/public-api/src/controllers/userAuth.controller.js +++ b/apps/public-api/src/controllers/userAuth.controller.js @@ -534,7 +534,7 @@ const buildSocialAuthUserPayload = async (usersColConfig, profile) => { return buildAuthUserPayload( usersColConfig, { - email: profile.email, + email: String(profile.email).toLowerCase().trim(), password: randomPassword, username: profile.username, name: profile.name, @@ -577,7 +577,13 @@ const findOrCreateSocialUser = async ({ project, usersColConfig, Model, provider throw err; } - user = await Model.findOne({ email: profile.email }); + const normalizedEmail = String(profile.email) + .toLowerCase() + .trim(); + + user = await Model.findOne({ + email: normalizedEmail + }); if (user) { const deletedMsg = checkUserSoftDeleted(user); if (deletedMsg) { @@ -1063,7 +1069,12 @@ module.exports.signup = async (req, res) => { const newUserPayload = buildAuthUserPayload( usersColConfig, - { email, password, username, ...otherData }, + { + email: normalizedEmail, + password, + username, + ...otherData + }, hashedPassword, false ); @@ -1296,6 +1307,7 @@ module.exports.createAdminUser = async (req, res) => { const parsedData = userSignupSchema.parse(req.body); const { email, password, username, ...otherData } = parsedData; + const normalizedEmail = email.toLowerCase().trim(); // Get Mongoose Model const usersColConfig = project.collections.find(c => c.name === 'users'); @@ -1304,7 +1316,9 @@ module.exports.createAdminUser = async (req, res) => { const connection = await getConnection(project._id); const Model = getCompiledModel(connection, usersColConfig, project._id, project.resources.db.isExternal); - const existingUser = await Model.findOne({ email }); + const existingUser = await Model.findOne({ + email: normalizedEmail + }); if (existingUser) { return res.status(400).json({ error: "User already exists with this email." }); } @@ -1314,7 +1328,12 @@ module.exports.createAdminUser = async (req, res) => { const newUserPayload = buildAuthUserPayload( usersColConfig, - { email, password, username, ...otherData }, + { + email: normalizedEmail, + password, + username, + ...otherData + }, hashedPassword, true ); @@ -1323,7 +1342,7 @@ module.exports.createAdminUser = async (req, res) => { res.status(201).json({ message: "User created successfully", - user: { _id: result._id, email, username, createdAt: newUserPayload.createdAt } + user: { _id: result._id, email: normalizedEmail, username, createdAt: newUserPayload.createdAt } }); } catch (err) { From 0999cbf53ca5823353939f7f553601b8cbd081e1 Mon Sep 17 00:00:00 2001 From: VarshithReddy2006 Date: Sat, 20 Jun 2026 21:33:54 +0530 Subject: [PATCH 2/2] fix(auth): use standard response envelope for createAdminUser --- .../src/controllers/userAuth.controller.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/public-api/src/controllers/userAuth.controller.js b/apps/public-api/src/controllers/userAuth.controller.js index 399e77e8a..1728ccf70 100644 --- a/apps/public-api/src/controllers/userAuth.controller.js +++ b/apps/public-api/src/controllers/userAuth.controller.js @@ -1341,8 +1341,16 @@ module.exports.createAdminUser = async (req, res) => { const result = await Model.create(newUserPayload); res.status(201).json({ - message: "User created successfully", - user: { _id: result._id, email: normalizedEmail, username, createdAt: newUserPayload.createdAt } + success: true, + data: { + user: { + _id: result._id, + email: normalizedEmail, + username, + createdAt: newUserPayload.createdAt + } + }, + message: "User created successfully" }); } catch (err) {