From c7b7d505776568e0c01a026f8be00673816589fa Mon Sep 17 00:00:00 2001 From: rishabhpoddar Date: Wed, 13 Dec 2023 23:01:44 +0530 Subject: [PATCH] adds unlink account in recipe impl - tests remaining --- supertokens/accountlinkingRecipeImplementation.go | 15 +++++++++++++++ supertokens/main.go | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/supertokens/accountlinkingRecipeImplementation.go b/supertokens/accountlinkingRecipeImplementation.go index b78befbd..494c084a 100644 --- a/supertokens/accountlinkingRecipeImplementation.go +++ b/supertokens/accountlinkingRecipeImplementation.go @@ -323,6 +323,20 @@ func makeRecipeImplementation(querier Querier, config AccountLinkingTypeNormalis } } + unlinkAccounts := func(recipeUserId RecipeUserID, userContext UserContext) (UnlinkAccountsResponse, error) { + requestBody := map[string]interface{}{ + "recipeUserId": recipeUserId.GetAsString(), + } + resp, err := querier.SendPostRequest("/recipe/accountlinking/user/unlink", requestBody, userContext) + if err != nil { + return UnlinkAccountsResponse{}, err + } + return UnlinkAccountsResponse{ + WasRecipeUserDeleted: resp["wasRecipeUserDeleted"].(bool), + WasLinked: resp["wasLinked"].(bool), + }, nil + } + // TODO:... return AccountLinkingRecipeInterface{ GetUsersWithSearchParams: &getUsers, @@ -331,5 +345,6 @@ func makeRecipeImplementation(querier Querier, config AccountLinkingTypeNormalis CreatePrimaryUser: &createPrimaryUser, LinkAccounts: &linkAccounts, CanLinkAccounts: &canLinkAccounts, + UnlinkAccounts: &unlinkAccounts, } } diff --git a/supertokens/main.go b/supertokens/main.go index 0de28f18..496456d4 100644 --- a/supertokens/main.go +++ b/supertokens/main.go @@ -173,3 +173,16 @@ func CanLinkAccounts(recipeUserId RecipeUserID, primaryUserId string, userContex return (*accountLinkingInstance.RecipeImpl.CanLinkAccounts)(recipeUserId, primaryUserId, userContext[0]) } + +func UnlinkAccounts(recipeUserId RecipeUserID, userContext ...UserContext) (UnlinkAccountsResponse, error) { + accountLinkingInstance, err := getAccountLinkingRecipeInstanceOrThrowError() + if err != nil { + return UnlinkAccountsResponse{}, err + } + + if len(userContext) == 0 { + userContext = append(userContext, &map[string]interface{}{}) + } + + return (*accountLinkingInstance.RecipeImpl.UnlinkAccounts)(recipeUserId, userContext[0]) +}