Skip to content

Commit

Permalink
adds more impl
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Dec 12, 2023
1 parent 2cf5ac9 commit 0858299
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 3 deletions.
91 changes: 89 additions & 2 deletions supertokens/accountlinkingRecipeImplementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,101 @@ func makeRecipeImplementation(querier Querier) AccountLinkingRecipeInterface {
}

canCreatePrimaryUser := func(recipeUserId RecipeUserID, userContext UserContext) (CanCreatePrimaryUserResponse, error) {
// TODO:..
return CanCreatePrimaryUserResponse{}, nil
requestBody := map[string]string{
"recipeUserId": recipeUserId.GetAsString(),
}
resp, err := querier.SendGetRequest("/recipe/accountlinking/user/primary/check", requestBody, userContext)

if err != nil {
return CanCreatePrimaryUserResponse{}, err
}

if resp["status"].(string) == "OK" {
return CanCreatePrimaryUserResponse{
OK: &struct{ WasAlreadyAPrimaryUser bool }{
WasAlreadyAPrimaryUser: resp["wasAlreadyAPrimaryUser"].(bool),
},
}, nil
} else if resp["status"].(string) == "RECIPE_USER_ID_ALREADY_LINKED_WITH_PRIMARY_USER_ID_ERROR" {
return CanCreatePrimaryUserResponse{
RecipeUserIdAlreadyLinkedWithPrimaryUserIdError: &struct {
PrimaryUserId string
Description string
}{
PrimaryUserId: resp["primaryUserId"].(string),
Description: resp["description"].(string),
},
}, nil
} else {
return CanCreatePrimaryUserResponse{
AccountInfoAlreadyAssociatedWithAnotherPrimaryUserIdError: &struct {
PrimaryUserId string
Description string
}{
PrimaryUserId: resp["primaryUserId"].(string),
Description: resp["description"].(string),
},
}, nil
}
}

createPrimaryUser := func(recipeUserId RecipeUserID, userContext UserContext) (CreatePrimaryUserResponse, error) {
requestBody := map[string]interface{}{
"recipeUserId": recipeUserId.GetAsString(),
}
resp, err := querier.SendPostRequest("/recipe/accountlinking/user/primary", requestBody, userContext)

if err != nil {
return CreatePrimaryUserResponse{}, err
}

if resp["status"].(string) == "OK" {
var user = User{}

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

err = json.Unmarshal(temporaryVariable, &user)
if err != nil {
return CreatePrimaryUserResponse{}, err
}
return CreatePrimaryUserResponse{
OK: &struct {
User User
WasAlreadyAPrimaryUser bool
}{
WasAlreadyAPrimaryUser: resp["wasAlreadyAPrimaryUser"].(bool),
User: user,
},
}, nil
} else if resp["status"].(string) == "RECIPE_USER_ID_ALREADY_LINKED_WITH_PRIMARY_USER_ID_ERROR" {
return CreatePrimaryUserResponse{
RecipeUserIdAlreadyLinkedWithPrimaryUserIdError: &struct {
PrimaryUserId string
}{
PrimaryUserId: resp["primaryUserId"].(string),
},
}, nil
} else {
return CreatePrimaryUserResponse{
AccountInfoAlreadyAssociatedWithAnotherPrimaryUserIdError: &struct {
PrimaryUserId string
Description string
}{
PrimaryUserId: resp["primaryUserId"].(string),
Description: resp["description"].(string),
},
}, nil
}
}

// TODO:...
return AccountLinkingRecipeInterface{
GetUsersWithSearchParams: &getUsers,
GetUser: &getUser,
CanCreatePrimaryUser: &canCreatePrimaryUser,
CreatePrimaryUser: &createPrimaryUser,
}
}
1 change: 0 additions & 1 deletion supertokens/accountlinkingRecipeInterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type CreatePrimaryUserResponse struct {
}
RecipeUserIdAlreadyLinkedWithPrimaryUserIdError *struct {
PrimaryUserId string
Description string
}
AccountInfoAlreadyAssociatedWithAnotherPrimaryUserIdError *struct {
PrimaryUserId string
Expand Down

0 comments on commit 0858299

Please sign in to comment.