get invite role and teamId from invite instead of client

This commit is contained in:
Alex Holliday committed 2025-04-28 10:34:32 -07:00
1 parent d5adf7a2be
commit c2ffdd1d62
1 file changed
+8 -6
+8 -6
View File
@@ -57,9 +57,9 @@ class AuthController {
*/ */
registerUser = async (req, res, next) => { registerUser = async (req, res, next) => {
try { try {
if(req.body?.email){ if (req.body?.email) {
req.body.email = req.body.email?.toLowerCase(); req.body.email = req.body.email?.toLowerCase();
} }
await registrationBodyValidation.validateAsync(req.body); await registrationBodyValidation.validateAsync(req.body);
} catch (error) { } catch (error) {
const validationError = handleValidationError(error, SERVICE_NAME); const validationError = handleValidationError(error, SERVICE_NAME);
@@ -68,11 +68,13 @@ class AuthController {
} }
// Create a new user // Create a new user
try { try {
const { inviteToken } = req.body; const user = req.body;
// If superAdmin exists, a token should be attached to all further register requests // If superAdmin exists, a token should be attached to all further register requests
const superAdminExists = await this.db.checkSuperadmin(req, res); const superAdminExists = await this.db.checkSuperadmin(req, res);
if (superAdminExists) { if (superAdminExists) {
await this.db.getInviteTokenAndDelete(inviteToken); const invitedUser = await this.db.getInviteTokenAndDelete(user.inviteToken);
user.role = invitedUser.role;
user.teamId = invitedUser.teamId;
} else { } else {
// This is the first account, create JWT secret to use if one is not supplied by env // This is the first account, create JWT secret to use if one is not supplied by env
const jwtSecret = crypto.randomBytes(64).toString("hex"); const jwtSecret = crypto.randomBytes(64).toString("hex");
@@ -133,8 +135,8 @@ class AuthController {
*/ */
loginUser = async (req, res, next) => { loginUser = async (req, res, next) => {
try { try {
if(req.body?.email){ if (req.body?.email) {
req.body.email = req.body.email?.toLowerCase(); req.body.email = req.body.email?.toLowerCase();
} }
await loginValidation.validateAsync(req.body); await loginValidation.validateAsync(req.body);
} catch (error) { } catch (error) {