Skip to content

Commit

Permalink
adds more function
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Dec 15, 2023
1 parent b23246a commit e7e2217
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
39 changes: 38 additions & 1 deletion supertokens/accountlinkingRecipeImplementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,43 @@ func makeRecipeImplementation(querier Querier, config AccountLinkingTypeNormalis
return err
}

// TODO:...
listUserByAccountInfo := func(tenantID string, accountInfo AccountInfo, doUnionOfAccountInfo bool, userContext UserContext) ([]User, error) {
requestBody := map[string]string{
"doUnionOfAccountInfo": strconv.FormatBool(doUnionOfAccountInfo),
}

if accountInfo.Email != nil {
requestBody["email"] = *accountInfo.Email
}
if accountInfo.PhoneNumber != nil {
requestBody["phoneNumber"] = *accountInfo.PhoneNumber
}
if accountInfo.ThirdParty != nil {
requestBody["thirdPartyId"] = accountInfo.ThirdParty.ID
requestBody["thirdPartyUserId"] = accountInfo.ThirdParty.UserID
}

resp, err := querier.SendGetRequest(tenantID+"/users/by-accountinfo", requestBody, userContext)
if err != nil {
return []User{}, err
}

temporaryVariable, err := json.Marshal(resp)
if err != nil {
return []User{}, err
}

var result = []User{}

err = json.Unmarshal(temporaryVariable, &result)

if err != nil {
return []User{}, err
}

return result, nil
}

return AccountLinkingRecipeInterface{
GetUsersWithSearchParams: &getUsers,
GetUser: &getUser,
Expand All @@ -356,5 +392,6 @@ func makeRecipeImplementation(querier Querier, config AccountLinkingTypeNormalis
CanLinkAccounts: &canLinkAccounts,
UnlinkAccounts: &unlinkAccounts,
DeleteUser: &deleteUser,
ListUsersByAccountInfo: &listUserByAccountInfo,
}
}
13 changes: 13 additions & 0 deletions supertokens/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,16 @@ func UnlinkAccounts(recipeUserId RecipeUserID, userContext ...UserContext) (Unli

return (*accountLinkingInstance.RecipeImpl.UnlinkAccounts)(recipeUserId, userContext[0])
}

func ListUsersByAccountInfo(tenantID string, accountInfo AccountInfo, doUnionOfAccountInfo bool, userContext ...UserContext) ([]User, error) {
accountLinkingInstance, err := getAccountLinkingRecipeInstanceOrThrowError()
if err != nil {
return []User{}, err
}

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

return (*accountLinkingInstance.RecipeImpl.ListUsersByAccountInfo)(tenantID, accountInfo, doUnionOfAccountInfo, userContext[0])
}

0 comments on commit e7e2217

Please sign in to comment.