Skip to content

Commit 7c98fee

Browse files
Merge pull request #342 from supertokens/multi-fixes
fix: login methods api and tpless init
2 parents eb760d7 + 3e11dbc commit 7c98fee

File tree

6 files changed

+81
-22
lines changed

6 files changed

+81
-22
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
## [0.13.1] - 2023-08-24
11+
12+
- Fixes login methods API to return empty provider array instead of `null`
13+
- Fixes thirdpartypasswordless initialization when there are no static providers configured
14+
1015
## [0.13.0] - 2023-08-07
1116

1217
### Added

recipe/multitenancy/api/implementation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func MakeAPIImplementation() multitenancymodels.APIInterface {
2727

2828
mergedProviders := tpproviders.MergeProvidersFromCoreAndStatic(providerConfigsFromCore, providerInputsFromStatic)
2929

30-
var finalProviderList []multitenancymodels.TypeThirdPartyProvider
30+
var finalProviderList []multitenancymodels.TypeThirdPartyProvider = []multitenancymodels.TypeThirdPartyProvider{}
3131

3232
for _, providerInput := range mergedProviders {
3333
providerInstance, err := tpproviders.FindAndCreateProviderInstance(mergedProviders, providerInput.Config.ThirdPartyId, clientType, userContext)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package thirdpartyemailpassword
2+
3+
import (
4+
"encoding/json"
5+
"io/ioutil"
6+
"net/http"
7+
"net/http/httptest"
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
"github.com/supertokens/supertokens-golang/supertokens"
12+
"github.com/supertokens/supertokens-golang/test/unittesting"
13+
)
14+
15+
func TestLoginMethodsReturnEmptyProviderArray(t *testing.T) {
16+
configValue := supertokens.TypeInput{
17+
Supertokens: &supertokens.ConnectionInfo{
18+
ConnectionURI: "http://localhost:8080",
19+
},
20+
AppInfo: supertokens.AppInfo{
21+
APIDomain: "api.supertokens.io",
22+
AppName: "SuperTokens",
23+
WebsiteDomain: "supertokens.io",
24+
},
25+
RecipeList: []supertokens.Recipe{
26+
Init(nil),
27+
},
28+
}
29+
30+
BeforeEach()
31+
unittesting.StartUpST("localhost", "8080")
32+
defer AfterEach()
33+
err := supertokens.Init(configValue)
34+
if err != nil {
35+
t.Error(err.Error())
36+
}
37+
mux := http.NewServeMux()
38+
testServer := httptest.NewServer(supertokens.Middleware(mux))
39+
defer testServer.Close()
40+
41+
resp, err := http.Get(testServer.URL + "/auth/loginmethods")
42+
if err != nil {
43+
t.Error(err.Error())
44+
}
45+
assert.Equal(t, http.StatusOK, resp.StatusCode)
46+
47+
respObj := map[string]interface{}{}
48+
respBytes, err := ioutil.ReadAll(resp.Body)
49+
assert.Nil(t, err)
50+
err = json.Unmarshal(respBytes, &respObj)
51+
assert.Nil(t, err)
52+
providersArr, ok := respObj["thirdParty"].(map[string]interface{})["providers"]
53+
assert.True(t, ok)
54+
assert.NotNil(t, providersArr)
55+
}

recipe/thirdpartypasswordless/config_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func TestMinimumConfigForThirdPartyPasswordlessWithEmailOrPhoneContactMethod(t *
8383
thirdPartyPasswordlessRecipe, err := GetRecipeInstanceOrThrowError()
8484
assert.NoError(t, err)
8585
assert.Equal(t, "USER_INPUT_CODE_AND_MAGIC_LINK", thirdPartyPasswordlessRecipe.Config.FlowType)
86+
assert.NotNil(t, thirdPartyPasswordlessRecipe.thirdPartyRecipe) // thirdPartyRecipe must be created always
8687
}
8788

8889
func TestForThirdPartyPasswordLessCreateAndSendCustomTextMessageWithFlowTypeMagicLinkAndPhoneContactMethod(t *testing.T) {

recipe/thirdpartypasswordless/recipe.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,29 +107,27 @@ func MakeRecipe(recipeId string, appInfo supertokens.NormalisedAppinfo, config t
107107
r.passwordlessRecipe = passwordlessInstance
108108
}
109109

110-
if len(verifiedConfig.Providers) > 0 {
111-
if thirdPartyInstance == nil {
112-
thirdPartyConfig := &tpmodels.TypeInput{
113-
SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{
114-
Providers: verifiedConfig.Providers,
110+
if thirdPartyInstance == nil {
111+
thirdPartyConfig := &tpmodels.TypeInput{
112+
SignInAndUpFeature: tpmodels.TypeInputSignInAndUp{
113+
Providers: verifiedConfig.Providers,
114+
},
115+
Override: &tpmodels.OverrideStruct{
116+
Functions: func(_ tpmodels.RecipeInterface) tpmodels.RecipeInterface {
117+
return recipeimplementation.MakeThirdPartyRecipeImplementation(r.RecipeImpl)
115118
},
116-
Override: &tpmodels.OverrideStruct{
117-
Functions: func(_ tpmodels.RecipeInterface) tpmodels.RecipeInterface {
118-
return recipeimplementation.MakeThirdPartyRecipeImplementation(r.RecipeImpl)
119-
},
120-
APIs: func(_ tpmodels.APIInterface) tpmodels.APIInterface {
121-
return api.GetThirdPartyIterfaceImpl(r.APIImpl)
122-
},
119+
APIs: func(_ tpmodels.APIInterface) tpmodels.APIInterface {
120+
return api.GetThirdPartyIterfaceImpl(r.APIImpl)
123121
},
124-
}
125-
thirdPartyRecipeinstance, err := thirdparty.MakeRecipe(recipeId, appInfo, thirdPartyConfig, &r.EmailDelivery, onSuperTokensAPIError)
126-
if err != nil {
127-
return Recipe{}, err
128-
}
129-
r.thirdPartyRecipe = &thirdPartyRecipeinstance
130-
} else {
131-
r.thirdPartyRecipe = thirdPartyInstance
122+
},
132123
}
124+
thirdPartyRecipeinstance, err := thirdparty.MakeRecipe(recipeId, appInfo, thirdPartyConfig, &r.EmailDelivery, onSuperTokensAPIError)
125+
if err != nil {
126+
return Recipe{}, err
127+
}
128+
r.thirdPartyRecipe = &thirdPartyRecipeinstance
129+
} else {
130+
r.thirdPartyRecipe = thirdPartyInstance
133131
}
134132

135133
return *r, nil

supertokens/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
)
2222

2323
// VERSION current version of the lib
24-
const VERSION = "0.13.0"
24+
const VERSION = "0.13.1"
2525

2626
var (
2727
cdiSupported = []string{"3.0"}

0 commit comments

Comments
 (0)