Skip to content

Commit

Permalink
passed userContext to the querier functions
Browse files Browse the repository at this point in the history
  • Loading branch information
IamMayankThakur committed Nov 6, 2023
1 parent c72f26c commit 1937c90
Show file tree
Hide file tree
Showing 22 changed files with 164 additions and 123 deletions.
2 changes: 1 addition & 1 deletion recipe/dashboard/api/analyticsPOST.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func AnalyticsPost(apiInterface dashboardmodels.APIInterface, tenantId string, o
return analyticsPostResponse{}, err
}

response, err := querier.SendGetRequest("/telemetry", nil)
response, err := querier.SendGetRequest("/telemetry", nil, userContext)
if err != nil {
// We don't send telemetry events if this fails
return analyticsPostResponse{
Expand Down
2 changes: 1 addition & 1 deletion recipe/dashboard/api/search/tagsGet.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func SearchTagsGet(apiImplementation dashboardmodels.APIInterface, tenantId stri
return searchTagsResponse{}, querierErr
}

apiResponse, apiErr := querier.SendGetRequest("/user/search/tags", nil)
apiResponse, apiErr := querier.SendGetRequest("/user/search/tags", nil, userContext)
if apiErr != nil {
return searchTagsResponse{}, apiErr
}
Expand Down
2 changes: 1 addition & 1 deletion recipe/dashboard/api/signInPost.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func SignInPost(apiInterface dashboardmodels.APIInterface, options dashboardmode
apiResponse, apiErr := querier.SendPostRequest("/recipe/dashboard/signin", map[string]interface{}{
"email": *readBody.Email,
"password": *readBody.Password,
})
}, userContext)

if apiErr != nil {
return apiErr
Expand Down
2 changes: 1 addition & 1 deletion recipe/dashboard/api/signOutPost.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func SignOutPost(apiInterface dashboardmodels.APIInterface, tenantId string, opt

_, apiError := querier.SendDeleteRequest("/recipe/dashboard/session", map[string]interface{}{}, map[string]string{
"sessionId": sessionIdFromHeader,
})
}, userContext)

if apiError != nil {
return signOutPostResponse{}, apiError
Expand Down
2 changes: 1 addition & 1 deletion recipe/dashboard/recipeimplementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func makeRecipeImplementation(querier supertokens.Querier) dashboardmodels.Recip

verifyResponse, err := querier.SendPostRequest("/recipe/dashboard/session/verify", map[string]interface{}{
"sessionId": authHeaderValue,
})
}, userContext)

if err != nil {
return false, err
Expand Down
41 changes: 41 additions & 0 deletions recipe/emailpassword/network_interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,44 @@ func TestNetworkInterceptorDuringSignIn(t *testing.T) {
assert.Equal(t, 200, res.StatusCode)
assert.Equal(t, true, isNetworkIntercepted)
}

func TestNetworkInterceptorNotSet(t *testing.T) {
isNetworkIntercepted = false
configValue := supertokens.TypeInput{
Supertokens: &supertokens.ConnectionInfo{
ConnectionURI: "http://localhost:8080",
},
AppInfo: supertokens.AppInfo{
AppName: "SuperTokens",
APIDomain: "api.supertokens.io",
WebsiteDomain: "supertokens.io",
},
RecipeList: []supertokens.Recipe{
Init(nil),
},
}
BeforeEach()

unittesting.StartUpST("localhost", "8080")

defer AfterEach()

err := supertokens.Init(configValue)

if err != nil {
t.Error(err.Error())
}

mux := http.NewServeMux()
testServer := httptest.NewServer(supertokens.Middleware(mux))
defer testServer.Close()

res, err := unittesting.SignInRequest("[email protected]", "validpass123", testServer.URL)

if err != nil {
t.Error(err.Error())
}

assert.Equal(t, 200, res.StatusCode)
assert.Equal(t, false, isNetworkIntercepted)
}
14 changes: 7 additions & 7 deletions recipe/emailpassword/recipeImplementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, getEmailPasswordConfi
response, err := querier.SendPostRequest(tenantId+"/recipe/signup", map[string]interface{}{
"email": email,
"password": password,
})
}, userContext)
if err != nil {
return epmodels.SignUpResponse{}, err
}
Expand All @@ -48,7 +48,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, getEmailPasswordConfi
response, err := querier.SendPostRequest(tenantId+"/recipe/signin", map[string]interface{}{
"email": email,
"password": password,
})
}, userContext)
if err != nil {
return epmodels.SignInResponse{}, err
}
Expand All @@ -70,7 +70,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, getEmailPasswordConfi
getUserByID := func(userID string, userContext supertokens.UserContext) (*epmodels.User, error) {
response, err := querier.SendGetRequest("/recipe/user", map[string]string{
"userId": userID,
})
}, userContext)
if err != nil {
return nil, err
}
Expand All @@ -88,7 +88,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, getEmailPasswordConfi
getUserByEmail := func(email string, tenantId string, userContext supertokens.UserContext) (*epmodels.User, error) {
response, err := querier.SendGetRequest(tenantId+"/recipe/user", map[string]string{
"email": email,
})
}, userContext)
if err != nil {
return nil, err
}
Expand All @@ -106,7 +106,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, getEmailPasswordConfi
createResetPasswordToken := func(userID string, tenantId string, userContext supertokens.UserContext) (epmodels.CreateResetPasswordTokenResponse, error) {
response, err := querier.SendPostRequest(tenantId+"/recipe/user/password/reset/token", map[string]interface{}{
"userId": userID,
})
}, userContext)
if err != nil {
return epmodels.CreateResetPasswordTokenResponse{}, err
}
Expand All @@ -126,7 +126,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, getEmailPasswordConfi
"method": "token",
"token": token,
"newPassword": newPassword,
})
}, userContext)
if err != nil {
return epmodels.ResetPasswordUsingTokenResponse{}, nil
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func MakeRecipeImplementation(querier supertokens.Querier, getEmailPasswordConfi
}
requestBody["password"] = password
}
response, err := querier.SendPutRequest("/recipe/user", requestBody)
response, err := querier.SendPutRequest("/recipe/user", requestBody, userContext)
if err != nil {
return epmodels.UpdateEmailOrPasswordResponse{}, nil
}
Expand Down
10 changes: 5 additions & 5 deletions recipe/emailverification/recipeimplementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func makeRecipeImplementation(querier supertokens.Querier) evmodels.RecipeInterf
response, err := querier.SendPostRequest(tenantId+"/recipe/user/email/verify/token", map[string]interface{}{
"userId": userID,
"email": email,
})
}, userContext)
if err != nil {
return evmodels.CreateEmailVerificationTokenResponse{}, err
}
Expand All @@ -45,7 +45,7 @@ func makeRecipeImplementation(querier supertokens.Querier) evmodels.RecipeInterf
response, err := querier.SendPostRequest(tenantId+"/recipe/user/email/verify", map[string]interface{}{
"method": "token",
"token": token,
})
}, userContext)
if err != nil {
return evmodels.VerifyEmailUsingTokenResponse{}, err
}
Expand All @@ -67,7 +67,7 @@ func makeRecipeImplementation(querier supertokens.Querier) evmodels.RecipeInterf
response, err := querier.SendGetRequest("/recipe/user/email/verify", map[string]string{
"userId": userID,
"email": email,
})
}, userContext)
if err != nil {
return false, err
}
Expand All @@ -78,7 +78,7 @@ func makeRecipeImplementation(querier supertokens.Querier) evmodels.RecipeInterf
_, err := querier.SendPostRequest(tenantId+"/recipe/user/email/verify/token/remove", map[string]interface{}{
"userId": userId,
"email": email,
})
}, userContext)
if err != nil {
return evmodels.RevokeEmailVerificationTokensResponse{}, err
}
Expand All @@ -91,7 +91,7 @@ func makeRecipeImplementation(querier supertokens.Querier) evmodels.RecipeInterf
_, err := querier.SendPostRequest("/recipe/user/email/verify/remove", map[string]interface{}{
"userId": userId,
"email": email,
})
}, userContext)
if err != nil {
return evmodels.UnverifyEmailResponse{}, err
}
Expand Down
4 changes: 2 additions & 2 deletions recipe/jwt/recipeimplementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config jwtmodels.Type
"algorithm": "RS256",
"jwksDomain": appInfo.APIDomain.GetAsStringDangerous(),
"useStaticSigningKey": shouldUseStaticSigningKey,
})
}, userContext)
if err != nil {
return jwtmodels.CreateJWTResponse{}, err
}
Expand All @@ -65,7 +65,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config jwtmodels.Type
}
}
getJWKS := func(userContext supertokens.UserContext) (jwtmodels.GetJWKSResponse, error) {
response, headers, err := querier.SendGetRequestWithResponseHeaders("/.well-known/jwks.json", map[string]string{})
response, headers, err := querier.SendGetRequestWithResponseHeaders("/.well-known/jwks.json", map[string]string{}, userContext)
if err != nil {
return jwtmodels.GetJWKSResponse{}, err
}
Expand Down
16 changes: 8 additions & 8 deletions recipe/multitenancy/recipeimplementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config multitenancymo
if config.CoreConfig != nil {
requestBody["coreConfig"] = config.CoreConfig
}
createOrUpdateResponse, err := querier.SendPutRequest("/recipe/multitenancy/tenant", requestBody)
createOrUpdateResponse, err := querier.SendPutRequest("/recipe/multitenancy/tenant", requestBody, userContext)
if err != nil {
return multitenancymodels.CreateOrUpdateTenantResponse{}, err
}
Expand All @@ -65,7 +65,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config multitenancymo
deleteTenant := func(tenantId string, userContext supertokens.UserContext) (multitenancymodels.DeleteTenantResponse, error) {
deleteTenantResponse, err := querier.SendPostRequest("/recipe/multitenancy/tenant/remove", map[string]interface{}{
"tenantId": tenantId,
})
}, userContext)
if err != nil {
return multitenancymodels.DeleteTenantResponse{}, err
}
Expand All @@ -82,7 +82,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config multitenancymo
}

getTenant := func(tenantId string, userContext supertokens.UserContext) (*multitenancymodels.Tenant, error) {
tenantResponse, err := querier.SendGetRequest(fmt.Sprintf("/%s/recipe/multitenancy/tenant", tenantId), map[string]string{})
tenantResponse, err := querier.SendGetRequest(fmt.Sprintf("/%s/recipe/multitenancy/tenant", tenantId), map[string]string{}, userContext)
if err != nil {
return nil, err
}
Expand All @@ -107,7 +107,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config multitenancymo
}

listAllTenants := func(userContext supertokens.UserContext) (multitenancymodels.ListAllTenantsResponse, error) {
tenantsResponse, err := querier.SendGetRequest("/recipe/multitenancy/tenant/list", map[string]string{})
tenantsResponse, err := querier.SendGetRequest("/recipe/multitenancy/tenant/list", map[string]string{}, userContext)
if err != nil {
return multitenancymodels.ListAllTenantsResponse{}, err
}
Expand Down Expand Up @@ -135,7 +135,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config multitenancymo
if skipValidation != nil {
requestBody["skipValidation"] = *skipValidation
}
response, err := querier.SendPutRequest(fmt.Sprintf("/%s/recipe/multitenancy/config/thirdparty", tenantId), requestBody)
response, err := querier.SendPutRequest(fmt.Sprintf("/%s/recipe/multitenancy/config/thirdparty", tenantId), requestBody, userContext)
if err != nil {
return multitenancymodels.CreateOrUpdateThirdPartyConfigResponse{}, err
}
Expand All @@ -151,7 +151,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config multitenancymo
deleteThirdPartyConfig := func(tenantId string, thirdPartyId string, userContext supertokens.UserContext) (multitenancymodels.DeleteThirdPartyConfigResponse, error) {
response, err := querier.SendPostRequest(fmt.Sprintf("/%s/recipe/multitenancy/config/thirdparty/remove", tenantId), map[string]interface{}{
"thirdPartyId": thirdPartyId,
})
}, userContext)
if err != nil {
return multitenancymodels.DeleteThirdPartyConfigResponse{}, err
}
Expand All @@ -166,7 +166,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config multitenancymo
associateUserToTenant := func(tenantId string, userId string, userContext supertokens.UserContext) (multitenancymodels.AssociateUserToTenantResponse, error) {
response, err := querier.SendPostRequest(fmt.Sprintf("/%s/recipe/multitenancy/tenant/user", tenantId), map[string]interface{}{
"userId": userId,
})
}, userContext)
if err != nil {
return multitenancymodels.AssociateUserToTenantResponse{}, err
}
Expand All @@ -180,7 +180,7 @@ func makeRecipeImplementation(querier supertokens.Querier, config multitenancymo
disassociateUserFromTenant := func(tenantId string, userId string, userContext supertokens.UserContext) (multitenancymodels.DisassociateUserFromTenantResponse, error) {
response, err := querier.SendPostRequest(fmt.Sprintf("/%s/recipe/multitenancy/tenant/user/remove", tenantId), map[string]interface{}{
"userId": userId,
})
}, userContext)
if err != nil {
return multitenancymodels.DisassociateUserFromTenantResponse{}, err
}
Expand Down
Loading

0 comments on commit 1937c90

Please sign in to comment.