Skip to content

Commit

Permalink
adds more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Dec 14, 2023
1 parent 061d0bb commit 5f1c20c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 30 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [0.18.0] - TODO

### Added
- Account linking feature

### Breaking changes
- The SDK now supports CDI 4.0 and removed support for older CDIs.
- `supertokens.DeleteUser` function now takes an extra boolean called `removeAllLinkedAccounts`. You can pass in `true` here for most cases.
- Added `supertokens.GetUser` function which can be used instead of recipe level getUser functions.
- Output type of `supertokens.GetUsersNewestFirst` and `supertokens.GetUsersOldestFirst` now return `supertokens.User` object instead of a generic string to interface{} map.
- Third party sign in up recipe function now also marks email as verified directly via a core call instead of relying on the email verification recipe.

## [0.17.3] - 2023-12-12

- CI/CD changes
Expand Down
3 changes: 2 additions & 1 deletion recipe/dashboard/api/userdetails/userDelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func UserDelete(apiInterface dashboardmodels.APIInterface, tenantId string, opti
}
}

deleteError := supertokens.DeleteUser(userId)
// TODO: pass in removeAllLinkedAccounts from the input to the API.
deleteError := supertokens.DeleteUser(userId, true)

if deleteError != nil {
return userDeleteResponse{}, deleteError
Expand Down
10 changes: 10 additions & 0 deletions supertokens/accountlinkingRecipeImplementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,15 @@ func makeRecipeImplementation(querier Querier, config AccountLinkingTypeNormalis
}, nil
}

deleteUser := func(userId string, removeAllLinkedAccounts bool, userContext UserContext) error {
requestBody := map[string]interface{}{
"userId": userId,
"removeAllLinkedAccounts": removeAllLinkedAccounts,
}
_, err := querier.SendPostRequest("/user/remove", requestBody, userContext)
return err
}

// TODO:...
return AccountLinkingRecipeInterface{
GetUsersWithSearchParams: &getUsers,
Expand All @@ -346,5 +355,6 @@ func makeRecipeImplementation(querier Querier, config AccountLinkingTypeNormalis
LinkAccounts: &linkAccounts,
CanLinkAccounts: &canLinkAccounts,
UnlinkAccounts: &unlinkAccounts,
DeleteUser: &deleteUser,
}
}
13 changes: 11 additions & 2 deletions supertokens/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,17 @@ func GetUser(userId string, userContext ...UserContext) (*User, error) {
return (*accountLinkingInstance.RecipeImpl.GetUser)(userId, userContext[0])
}

func DeleteUser(userId string) error {
return deleteUser(userId)
func DeleteUser(userId string, removeAllLinkedAccounts bool, userContext ...UserContext) error {
accountLinkingInstance, err := getAccountLinkingRecipeInstanceOrThrowError()
if err != nil {
return err
}

if len(userContext) == 0 {
userContext = append(userContext, &map[string]interface{}{})
}

return (*accountLinkingInstance.RecipeImpl.DeleteUser)(userId, removeAllLinkedAccounts, userContext[0])
}

func GetRequestFromUserContext(userContext UserContext) *http.Request {
Expand Down
26 changes: 0 additions & 26 deletions supertokens/supertokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,32 +349,6 @@ func getUserCount(includeRecipeIds *[]string, tenantId string, includeAllTenants
return resp["count"].(float64), nil
}

func deleteUser(userId string) error {
querier, err := GetNewQuerierInstanceOrThrowError("")
if err != nil {
return err
}

cdiVersion, err := querier.GetQuerierAPIVersion()
if err != nil {
return err
}

if MaxVersion(cdiVersion, "2.10") == cdiVersion {
_, err = querier.SendPostRequest("/user/remove", map[string]interface{}{
"userId": userId,
}, nil)

if err != nil {
return err
}

return nil
} else {
return errors.New("please upgrade the SuperTokens core to >= 3.7.0")
}
}

func ResetForTest() {
ResetQuerierForTest()
superTokensInstance = nil
Expand Down
2 changes: 1 addition & 1 deletion test/auth-react-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ func callSTInit(passwordlessConfig *plessmodels.TypeInput) {
if err != nil {
return
}
err = supertokens.DeleteUser(user.ID)
err = supertokens.DeleteUser(user.ID, true)
if err != nil {
return
}
Expand Down

0 comments on commit 5f1c20c

Please sign in to comment.