Skip to content

Commit

Permalink
Update to consume email from core response
Browse files Browse the repository at this point in the history
  • Loading branch information
nkshah2 committed Sep 11, 2023
1 parent bbd09e4 commit 95629ec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion recipe/dashboard/dashboardmodels/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (

type TypeNormalisedInput struct {
ApiKey string
Admins []string
Admins *[]string
AuthMode TypeAuthMode
Override OverrideStruct
}
Expand Down
12 changes: 8 additions & 4 deletions recipe/dashboard/recipeimplementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,23 @@ func makeRecipeImplementation(querier supertokens.Querier) dashboardmodels.Recip

admins := config.Admins

if admins == nil {
return false, nil
}

// If the user has provided no admins, allow
if len(admins) == 0 {
if len(*admins) == 0 {
return true, nil
}

emailInHeaders := req.Header.Get("email")
userEmail, emailOk := verifyResponse["email"]

if emailInHeaders == "" {
if !emailOk || userEmail.(string) == "" {
supertokens.LogDebugMessage("User Dashboard: Returning Unauthorised because no email was provided in headers")
return false, nil
}

if !supertokens.DoesSliceContainString(emailInHeaders, admins) {
if !supertokens.DoesSliceContainString(userEmail.(string), *admins) {
supertokens.LogDebugMessage("User Dashboard: Throwing OPERATION_NOT_ALLOWED because user is not an admin")
return false, errors.ForbiddenAccessError{
Msg: "You are not permitted to perform this operation",
Expand Down
4 changes: 2 additions & 2 deletions recipe/dashboard/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func validateAndNormaliseUserInput(appInfo supertokens.NormalisedAppinfo, config
supertokens.LogDebugMessage("User Dashboard: Providing 'Admins' has no effect when using an apiKey.")
}

admins := []string{}
var admins *[]string
if _config.Admins != nil {
admins = *_config.Admins
admins = _config.Admins
}

typeNormalisedInput.Admins = admins
Expand Down

0 comments on commit 95629ec

Please sign in to comment.