Skip to content

Commit b4b8593

Browse files
committed
fix: default role values
1 parent 46a91fd commit b4b8593

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

server/env/env.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,23 +218,26 @@ func InitEnv() {
218218
constants.DISABLE_MAGIC_LINK_LOGIN = true
219219
}
220220

221-
rolesSplit := strings.Split(os.Getenv("ROLES"), ",")
221+
rolesEnv := strings.TrimSpace(os.Getenv("ROLES"))
222+
rolesSplit := strings.Split(rolesEnv, ",")
222223
roles := []string{}
223-
if len(rolesSplit) == 0 {
224+
if len(rolesEnv) == 0 {
224225
roles = []string{"user"}
225226
}
226227

227-
defaultRoleSplit := strings.Split(os.Getenv("DEFAULT_ROLES"), ",")
228+
defaultRolesEnv := strings.TrimSpace(os.Getenv("DEFAULT_ROLES"))
229+
defaultRoleSplit := strings.Split(defaultRolesEnv, ",")
228230
defaultRoles := []string{}
229231

230-
if len(defaultRoleSplit) == 0 {
232+
if len(defaultRolesEnv) == 0 {
231233
defaultRoles = []string{"user"}
232234
}
233235

234-
protectedRolesSplit := strings.Split(os.Getenv("PROTECTED_ROLES"), ",")
236+
protectedRolesEnv := strings.TrimSpace(os.Getenv("PROTECTED_ROLES"))
237+
protectedRolesSplit := strings.Split(protectedRolesEnv, ",")
235238
protectedRoles := []string{}
236239

237-
if len(protectedRolesSplit) > 0 {
240+
if len(protectedRolesEnv) > 0 {
238241
for _, val := range protectedRolesSplit {
239242
trimVal := strings.TrimSpace(val)
240243
protectedRoles = append(protectedRoles, trimVal)

server/resolvers/signup.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,6 @@ func Signup(ctx context.Context, params model.SignUpInput) (*model.AuthResponse,
3535
return res, fmt.Errorf(`invalid email address`)
3636
}
3737

38-
inputRoles := []string{}
39-
40-
if len(params.Roles) > 0 {
41-
// check if roles exists
42-
if !utils.IsValidRoles(constants.ROLES, params.Roles) {
43-
return res, fmt.Errorf(`invalid roles`)
44-
} else {
45-
inputRoles = params.Roles
46-
}
47-
} else {
48-
inputRoles = constants.DEFAULT_ROLES
49-
}
50-
5138
// find user with email
5239
existingUser, err := db.Mgr.GetUserByEmail(params.Email)
5340
if err != nil {
@@ -61,6 +48,19 @@ func Signup(ctx context.Context, params model.SignUpInput) (*model.AuthResponse,
6148
return res, fmt.Errorf("%s has already signed up. please complete the email verification process or reset the password", params.Email)
6249
}
6350

51+
inputRoles := []string{}
52+
53+
if len(params.Roles) > 0 {
54+
// check if roles exists
55+
if !utils.IsValidRoles(constants.ROLES, params.Roles) {
56+
return res, fmt.Errorf(`invalid roles`)
57+
} else {
58+
inputRoles = params.Roles
59+
}
60+
} else {
61+
inputRoles = constants.DEFAULT_ROLES
62+
}
63+
6464
user := db.User{
6565
Email: params.Email,
6666
}

0 commit comments

Comments
 (0)