fix validation, derrive teamID and Roles from tokens
This commit is contained in:
1 parent
78b920aaf6
commit
5152336591
6 files changed
+45
-15
No files matched your search
@@ -87,10 +87,10 @@ class UserService {
|
||||
const superAdminExists = await this.usersRepository.findSuperAdmin();
|
||||
if (superAdminExists) {
|
||||
const invite = await this.invitesRepository.findByTokenAndDelete(inviteToken);
|
||||
user.role = invite.role;
|
||||
user.role = invite.role ?? ["user"];
|
||||
user.teamId = invite.teamId;
|
||||
user.email = invite.email;
|
||||
} else {
|
||||
console.log("WHITFUSKALG");
|
||||
// This is the first account, create JWT secret to use if one is not supplied by env
|
||||
const jwtSecret = this.crypto.randomBytes(64).toString("hex");
|
||||
await this.settingsRepository.update({ jwtSecret });
|
||||
@@ -100,6 +100,7 @@ class UserService {
|
||||
}
|
||||
const team = await this.teamsRepository.create(user.email);
|
||||
user.teamId = team.id;
|
||||
user.role = ["superadmin"];
|
||||
}
|
||||
|
||||
const newUser = await this.usersRepository.create({ ...user }, file);
|
||||
|
||||
@@ -51,9 +51,7 @@ const registrationBodyValidation = joi.object({
|
||||
}),
|
||||
password: joi.string().min(8).required().pattern(passwordPattern),
|
||||
profileImage: joi.any(),
|
||||
role: joi.array().items(joi.string().valid("superadmin", "admin", "user", "demo")),
|
||||
teamId: joi.string().allow("").required(),
|
||||
inviteToken: joi.string().allow("").required(),
|
||||
inviteToken: joi.string().allow("").optional(),
|
||||
});
|
||||
|
||||
const editUserBodyValidation = joi.object({
|
||||
|
||||
Reference in new issue
Block a user