Skip to content

Commit

Permalink
removes tpep recipe entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Apr 10, 2024
1 parent 31d2f5d commit 957f7eb
Show file tree
Hide file tree
Showing 24 changed files with 137 additions and 2,913 deletions.
115 changes: 0 additions & 115 deletions recipe/dashboard/api/userdetails/userPut.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
"github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels"
"github.com/supertokens/supertokens-golang/recipe/passwordless"
"github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless"
"github.com/supertokens/supertokens-golang/recipe/usermetadata"
"github.com/supertokens/supertokens-golang/supertokens"
)
Expand Down Expand Up @@ -151,63 +150,6 @@ func updateEmailForRecipeId(recipeId string, userId string, email string, tenant
}, nil
}

if recipeId == "thirdpartypasswordless" {
isValidEmail := true
validationError := ""

passwordlessConfig := thirdpartypasswordless.GetRecipeInstance().Config

if passwordlessConfig.ContactMethodPhone.Enabled {
validationResult := passwordless.DefaultValidateEmailAddress(email, tenantId)

if validationResult != nil {
isValidEmail = false
validationError = *validationResult
}
} else if passwordlessConfig.ContactMethodEmail.Enabled {
validationResult := passwordlessConfig.ContactMethodEmail.ValidateEmailAddress(email, tenantId)

if validationResult != nil {
isValidEmail = false
validationError = *validationResult
}
} else {
validationResult := passwordlessConfig.ContactMethodEmailOrPhone.ValidateEmailAddress(email, tenantId)

if validationResult != nil {
isValidEmail = false
validationError = *validationResult
}
}

if !isValidEmail {
return updateEmailResponse{
Status: "INVALID_EMAIL_ERROR",
Error: validationError,
}, nil
}

updateResponse, updateErr := thirdpartypasswordless.UpdatePasswordlessUser(userId, &email, nil, userContext)

if updateErr != nil {
return updateEmailResponse{}, updateErr
}

if updateResponse.UnknownUserIdError != nil {
return updateEmailResponse{}, errors.New("Should never come here")
}

if updateResponse.EmailAlreadyExistsError != nil {
return updateEmailResponse{
Status: "EMAIL_ALREADY_EXISTS_ERROR",
}, nil
}

return updateEmailResponse{
Status: "OK",
}, nil
}

return updateEmailResponse{}, errors.New("Should never come here")
}

Expand Down Expand Up @@ -269,63 +211,6 @@ func updatePhoneForRecipeId(recipeId string, userId string, phone string, tenant
}, nil
}

if recipeId == "thirdpartypasswordless" {
isValidPhone := true
validationError := ""

passwordlessConfig := thirdpartypasswordless.GetRecipeInstance().Config

if passwordlessConfig.ContactMethodEmail.Enabled {
validationResult := passwordless.DefaultValidatePhoneNumber(phone, tenantId)

if validationResult != nil {
isValidPhone = false
validationError = *validationResult
}
} else if passwordlessConfig.ContactMethodPhone.Enabled {
validationResult := passwordlessConfig.ContactMethodPhone.ValidatePhoneNumber(phone, tenantId)

if validationResult != nil {
isValidPhone = false
validationError = *validationResult
}
} else {
validationResult := passwordlessConfig.ContactMethodEmailOrPhone.ValidatePhoneNumber(phone, tenantId)

if validationResult != nil {
isValidPhone = false
validationError = *validationResult
}
}

if !isValidPhone {
return updatePhoneResponse{
Status: "INVALID_PHONE_ERROR",
Error: validationError,
}, nil
}

updateResponse, updateErr := thirdpartypasswordless.UpdatePasswordlessUser(userId, nil, &phone, userContext)

if updateErr != nil {
return updatePhoneResponse{}, updateErr
}

if updateResponse.UnknownUserIdError != nil {
return updatePhoneResponse{}, errors.New("Should never come here")
}

if updateResponse.EmailAlreadyExistsError != nil {
return updatePhoneResponse{
Status: "PHONE_ALREADY_EXISTS_ERROR",
}, nil
}

return updatePhoneResponse{
Status: "OK",
}, nil
}

/**
* If it comes here then the user is a not a passwordless user in which case the UI should not have allowed this
*/
Expand Down
66 changes: 0 additions & 66 deletions recipe/dashboard/api/utils.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package api

import (
"reflect"

"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
"github.com/supertokens/supertokens-golang/recipe/passwordless"
"github.com/supertokens/supertokens-golang/recipe/thirdparty"
"github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless"
"github.com/supertokens/supertokens-golang/supertokens"
)

Expand Down Expand Up @@ -44,7 +41,6 @@ func GetUserForRecipeId(userId string, recipeId string, userContext supertokens.
}
} else if recipeId == thirdparty.RECIPE_ID {
response, error := thirdparty.GetUserByID(userId, userContext)

if error == nil && response != nil {
userToReturn.Id = response.ID
userToReturn.TimeJoined = response.TimeJoined
Expand All @@ -57,31 +53,6 @@ func GetUserForRecipeId(userId string, recipeId string, userContext supertokens.
}
userToReturn.TenantIds = response.TenantIds
}

if reflect.DeepEqual(userToReturn, dashboardmodels.UserType{}) {
tpplessResponse, tpplessError := thirdpartypasswordless.GetUserById(userId, userContext)

if tpplessError == nil && tpplessResponse != nil {
userToReturn.Id = tpplessResponse.ID
userToReturn.TimeJoined = tpplessResponse.TimeJoined
userToReturn.FirstName = ""
userToReturn.LastName = ""

if tpplessResponse.Email != nil {
userToReturn.Email = *tpplessResponse.Email
}

if tpplessResponse.PhoneNumber != nil {
userToReturn.Phone = *tpplessResponse.PhoneNumber
}

userToReturn.ThirdParty = &dashboardmodels.ThirdParty{
Id: tpplessResponse.ThirdParty.ID,
UserId: tpplessResponse.ThirdParty.UserID,
}
userToReturn.TenantIds = tpplessResponse.TenantIds
}
}
} else if recipeId == passwordless.RECIPE_ID {
response, error := passwordless.GetUserByID(userId, userContext)

Expand All @@ -101,27 +72,6 @@ func GetUserForRecipeId(userId string, recipeId string, userContext supertokens.

userToReturn.TenantIds = response.TenantIds
}

if reflect.DeepEqual(userToReturn, dashboardmodels.UserType{}) {
tppResponse, tppError := thirdpartypasswordless.GetUserByID(userId, userContext)

if tppError == nil && tppResponse != nil {
userToReturn.Id = tppResponse.ID
userToReturn.TimeJoined = tppResponse.TimeJoined
userToReturn.FirstName = ""
userToReturn.LastName = ""

if tppResponse.Email != nil {
userToReturn.Email = *tppResponse.Email
}

if tppResponse.PhoneNumber != nil {
userToReturn.Phone = *tppResponse.PhoneNumber
}

userToReturn.TenantIds = tppResponse.TenantIds
}
}
}

return userToReturn, recipeToReturn
Expand All @@ -142,28 +92,12 @@ func IsRecipeInitialised(recipeId string) bool {
if err == nil {
isRecipeInitialised = true
}

if !isRecipeInitialised {
_, err := thirdpartypasswordless.GetRecipeInstanceOrThrowError()

if err == nil {
isRecipeInitialised = true
}
}
} else if recipeId == thirdparty.RECIPE_ID {
_, err := thirdparty.GetRecipeInstanceOrThrowError()

if err == nil {
isRecipeInitialised = true
}

if !isRecipeInitialised {
_, err := thirdpartypasswordless.GetRecipeInstanceOrThrowError()

if err == nil {
isRecipeInitialised = true
}
}
}

return isRecipeInitialised
Expand Down
43 changes: 37 additions & 6 deletions recipe/dashboard/userGet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
"github.com/supertokens/supertokens-golang/recipe/dashboard/api"
"github.com/supertokens/supertokens-golang/recipe/dashboard/api/userdetails"
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
"github.com/supertokens/supertokens-golang/recipe/passwordless"
"github.com/supertokens/supertokens-golang/recipe/passwordless/plessmodels"
"github.com/supertokens/supertokens-golang/recipe/session"
"github.com/supertokens/supertokens-golang/recipe/thirdparty"
"github.com/supertokens/supertokens-golang/recipe/thirdparty/tpmodels"
"github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless"
"github.com/supertokens/supertokens-golang/recipe/thirdpartypasswordless/tplmodels"

"github.com/stretchr/testify/assert"
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
Expand Down Expand Up @@ -85,6 +85,33 @@ func TestThatUserGetReturnsTenantIDsCorrectly(t *testing.T) {
assert.Equal(t, response.User.TenantIds[0], "public")
}

var customProvider1 = tpmodels.ProviderInput{
Config: tpmodels.ProviderConfig{
ThirdPartyId: "custom",
AuthorizationEndpoint: "https://test.com/oauth/auth",
TokenEndpoint: "https://test.com/oauth/token",

Clients: []tpmodels.ProviderClientConfig{
{
ClientID: "supertokens",
},
},
},

Override: func(originalImplementation *tpmodels.TypeProvider) *tpmodels.TypeProvider {
originalImplementation.GetUserInfo = func(oAuthTokens tpmodels.TypeOAuthTokens, userContext supertokens.UserContext) (tpmodels.TypeUserInfo, error) {
return tpmodels.TypeUserInfo{
ThirdPartyUserId: "user",
Email: &tpmodels.EmailStruct{
ID: "[email protected]",
IsVerified: true,
},
}, nil
}
return originalImplementation
},
}

func TestThatUserGetReturnsValidUserForThirdPartyUserWhenUsingThirdPartyPasswordless(t *testing.T) {
config := supertokens.TypeInput{
Supertokens: &supertokens.ConnectionInfo{
Expand All @@ -96,14 +123,18 @@ func TestThatUserGetReturnsValidUserForThirdPartyUserWhenUsingThirdPartyPassword
WebsiteDomain: "supertokens.io",
},
RecipeList: []supertokens.Recipe{
thirdpartypasswordless.Init(tplmodels.TypeInput{
thirdparty.Init(&tpmodels.TypeInput{
SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{
Providers: []tpmodels.ProviderInput{
customProvider1,
},
},
}),
passwordless.Init(plessmodels.TypeInput{
FlowType: "USER_INPUT_CODE_AND_MAGIC_LINK",
ContactMethodEmailOrPhone: plessmodels.ContactMethodEmailOrPhoneConfig{
Enabled: true,
},
Providers: []tpmodels.ProviderInput{
thirdpartypasswordless.SigninupCustomProvider1,
},
}),
Init(&dashboardmodels.TypeInput{
ApiKey: "testapikey",
Expand Down
Loading

0 comments on commit 957f7eb

Please sign in to comment.