@@ -17,7 +17,9 @@ package dashboard
1717
1818import (
1919 "fmt"
20+ "github.com/supertokens/supertokens-golang/recipe/dashboard/constants"
2021 "github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
22+ "github.com/supertokens/supertokens-golang/recipe/dashboard/errors"
2123 "github.com/supertokens/supertokens-golang/recipe/dashboard/validationUtils"
2224 "github.com/supertokens/supertokens-golang/supertokens"
2325 "net/http"
@@ -47,7 +49,51 @@ func makeRecipeImplementation(querier supertokens.Querier) dashboardmodels.Recip
4749
4850 status , ok := verifyResponse ["status" ]
4951
50- return ok && status .(string ) == "OK" , nil
52+ if ! ok || status != "OK" {
53+ return false , nil
54+ }
55+
56+ // For all non GET requests we also want to check if the user is allowed to perform this operation
57+ if req .Method != http .MethodGet {
58+ // We dont want to block the analytics API
59+ if strings .HasSuffix (req .RequestURI , constants .DashboardAnalyticsAPI ) {
60+ return true , nil
61+ }
62+
63+ // We do not want to block the sign out request
64+ if strings .HasSuffix (req .RequestURI , constants .SignOutAPI ) {
65+ return true , nil
66+ }
67+
68+ admins := config .Admins
69+
70+ if admins == nil {
71+ return true , nil
72+ }
73+
74+ if len (* admins ) == 0 {
75+ supertokens .LogDebugMessage ("User Dashboard: Throwing OPERATION_NOT_ALLOWED because user is not an admin" )
76+ return false , errors.ForbiddenAccessError {
77+ Msg : "You are not permitted to perform this operation" ,
78+ }
79+ }
80+
81+ userEmail , emailOk := verifyResponse ["email" ]
82+
83+ if ! emailOk || userEmail .(string ) == "" {
84+ supertokens .LogDebugMessage ("User Dashboard: Returning Unauthorised because no email was returned from the core. Should never come here" )
85+ return false , nil
86+ }
87+
88+ if ! supertokens .DoesSliceContainString (userEmail .(string ), * admins ) {
89+ supertokens .LogDebugMessage ("User Dashboard: Throwing OPERATION_NOT_ALLOWED because user is not an admin" )
90+ return false , errors.ForbiddenAccessError {
91+ Msg : "You are not permitted to perform this operation" ,
92+ }
93+ }
94+ }
95+
96+ return true , nil
5197 }
5298
5399 validateKeyResponse , err := validationUtils .ValidateApiKey (req , config , userContext )
0 commit comments