Skip to content

Commit 243aa17

Browse files
Merge pull request #852 from supertokens/feat/add-golang-and-python-type-changes-for-form-fields
feat: Update all go/python docs with type fixes regarding form field values
2 parents e12ed0e + 5eca9d2 commit 243aa17

File tree

11 files changed

+138
-51
lines changed

11 files changed

+138
-51
lines changed

v2/attackprotectionsuite/backend-setup.mdx

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ import (
594594
"encoding/hex"
595595
"encoding/json"
596596
"net/http"
597+
"errors"
597598

598599
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
599600
"github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels"
@@ -777,13 +778,16 @@ func main() {
777778
email := ""
778779
password := ""
779780
for _, field := range formFields {
780-
if field.ID == "email" {
781-
email = field.Value
782-
break
783-
}
784-
if field.ID == "password" {
785-
password = field.Value
786-
break
781+
if field.ID == "email" || field.ID == "password" {
782+
valueAsString, asStrOk := field.Value.(string)
783+
if !asStrOk {
784+
return epmodels.SignUpPOSTResponse{}, errors.New("Should never come here as we check the type during validation")
785+
}
786+
if field.ID == "email" {
787+
email = valueAsString
788+
} else {
789+
password = valueAsString
790+
}
787791
}
788792
}
789793
bruteForceConfig := getBruteForceConfig(email, ip, actionType)
@@ -841,13 +845,16 @@ func main() {
841845
email := ""
842846
password := ""
843847
for _, field := range formFields {
844-
if field.ID == "email" {
845-
email = field.Value
846-
break
847-
}
848-
if field.ID == "password" {
849-
password = field.Value
850-
break
848+
if field.ID == "email" || field.ID == "password" {
849+
valueAsString, asStrOk := field.Value.(string)
850+
if !asStrOk {
851+
return epmodels.SignInPOSTResponse{}, errors.New("Should never come here as we check the type during validation")
852+
}
853+
if field.ID == "email" {
854+
email = valueAsString
855+
} else {
856+
password = valueAsString
857+
}
851858
}
852859
}
853860
bruteForceConfig := getBruteForceConfig(email, ip, actionType)
@@ -905,8 +912,11 @@ func main() {
905912
email := ""
906913
for _, field := range formFields {
907914
if field.ID == "email" {
908-
email = field.Value
909-
break
915+
valueAsString, asStrOk := field.Value.(string)
916+
if !asStrOk {
917+
return epmodels.GeneratePasswordResetTokenPOSTResponse{}, errors.New("Should never come here as we check the type during validation")
918+
}
919+
email = valueAsString
910920
}
911921
}
912922
bruteForceConfig := getBruteForceConfig(email, ip, actionType)

v2/emailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ function emailNotAllowed(email: string) {
6767

6868
```go
6969
import (
70+
"errors"
71+
7072
"github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels"
7173
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
7274
"github.com/supertokens/supertokens-golang/supertokens"
@@ -82,7 +84,11 @@ func main() {
8284
email := ""
8385
for _, v := range formFields {
8486
if v.ID == "email" {
85-
email = v.Value
87+
valueAsString, asStrOk := v.Value.(string)
88+
if !asStrOk {
89+
return epmodels.SignUpPOSTResponse{}, errors.New("Should never come here as we check the type during validation")
90+
}
91+
email = valueAsString
8692
}
8793
}
8894
if emailNotAllowed(email) {

v2/emailpassword/common-customizations/handling-signup-success.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ SuperTokens.init({
382382
```go
383383
import (
384384
"fmt"
385+
"errors"
385386

386387
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
387388
"github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels"
@@ -417,7 +418,11 @@ func main() {
417418
name := ""
418419
for _, field := range formFields {
419420
if field.ID == "name" {
420-
name = field.Value
421+
valueAsString, asStrOk := field.Value.(string)
422+
if !asStrOk {
423+
return epmodels.SignUpPOSTResponse{}, errors.New("name should be a string")
424+
}
425+
name = valueAsString
421426
}
422427
}
423428

v2/emailpassword/common-customizations/username-password/emailpassword-changes.mdx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ SuperTokens.init({
453453

454454
```go
455455
import (
456+
"errors"
457+
456458
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
457459
"github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels"
458460
"github.com/supertokens/supertokens-golang/supertokens"
@@ -502,7 +504,11 @@ func main() {
502504
actualEmail := ""
503505
for _, field := range formFields {
504506
if field.ID == "email" {
505-
actualEmail = field.Value
507+
valueAsString, asStrOk := field.Value.(string)
508+
if !asStrOk {
509+
return epmodels.SignUpPOSTResponse{}, errors.New("Should never come here as we check the type during validation")
510+
}
511+
actualEmail = valueAsString
506512
}
507513
}
508514
if actualEmail == "" {
@@ -1003,6 +1009,7 @@ SuperTokens.init({
10031009
```go
10041010
import (
10051011
"regexp"
1012+
"errors"
10061013

10071014
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
10081015
"github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels"
@@ -1069,7 +1076,11 @@ func main() {
10691076
emailOrUsername := ""
10701077
for _, field := range formFields {
10711078
if field.ID == "email" {
1072-
emailOrUsername = field.Value
1079+
valueAsString, asStrOk := field.Value.(string)
1080+
if !asStrOk {
1081+
return epmodels.GeneratePasswordResetTokenPOSTResponse{}, errors.New("Should never come here as we check the type during validation")
1082+
}
1083+
emailOrUsername = valueAsString
10731084
}
10741085
}
10751086
if isInputEmail(emailOrUsername) {
@@ -1104,7 +1115,11 @@ func main() {
11041115
username := ""
11051116
for _, field := range formFields {
11061117
if field.ID == "email" {
1107-
username = field.Value
1118+
valueAsString, asStrOk := field.Value.(string)
1119+
if !asStrOk {
1120+
return epmodels.GeneratePasswordResetTokenPOSTResponse{}, errors.New("Should never come here as we check the type during validation")
1121+
}
1122+
username = valueAsString
11081123
}
11091124
}
11101125
supertokensUser, err := emailpassword.GetUserByEmail(tenantId, username)

v2/emailpassword/migration/account-creation/ep-migration-without-password-hash.mdx

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ init(
139139

140140
```go
141141
import (
142+
"errors"
143+
142144
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
143145
"github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels"
144146
"github.com/supertokens/supertokens-golang/supertokens"
@@ -159,7 +161,11 @@ func main() {
159161
email := ""
160162
for _, formField := range formFields {
161163
if formField.ID == "email" {
162-
email = formField.Value
164+
valueAsString, asStrOk := formField.Value.(string)
165+
if !asStrOk {
166+
return epmodels.SignUpPOSTResponse{}, errors.New("Should never come here as we check the type during validation")
167+
}
168+
email = valueAsString
163169
}
164170
}
165171
// Check if the user signing in exists in the external provider
@@ -428,11 +434,16 @@ func main() {
428434
email := ""
429435
password := ""
430436
for _, formField := range formFields {
431-
if formField.ID == "email" {
432-
email = formField.Value
433-
}
434-
if formField.ID == "password" {
435-
password = formField.Value
437+
if formField.ID == "email" || formField.ID == "password" {
438+
valueAsString, asStrOk := formField.Value.(string)
439+
if !asStrOk {
440+
return epmodels.SignInPOSTResponse{}, errors.New("Should never come here as we check the type during validation")
441+
}
442+
if formField.ID == "email" {
443+
email = valueAsString
444+
} else {
445+
password = valueAsString
446+
}
436447
}
437448
}
438449
// Check if an email-password user with the input email exists in SuperTokens
@@ -768,7 +779,11 @@ func main() {
768779
var email *string = nil
769780
for _, field := range formFields {
770781
if field.ID == "email" {
771-
email = &field.Value
782+
valueAsString, asStrOk := field.Value.(string)
783+
if !asStrOk {
784+
return epmodels.GeneratePasswordResetTokenPOSTResponse{}, errors.New("Should never come here as we check the type during validation")
785+
}
786+
email = &valueAsString
772787
}
773788
}
774789

@@ -1351,11 +1366,16 @@ func main() {
13511366
email := ""
13521367
password := ""
13531368
for _, formField := range formFields {
1354-
if formField.ID == "email" {
1355-
email = formField.Value
1356-
}
1357-
if formField.ID == "password" {
1358-
password = formField.Value
1369+
if formField.ID == "email" || formField.ID == "password" {
1370+
valueAsString, asStrOk := formField.Value.(string)
1371+
if !asStrOk {
1372+
return epmodels.SignInPOSTResponse{}, errors.New("Should never come here as we check the type during validation")
1373+
}
1374+
if formField.ID == "email" {
1375+
email = valueAsString
1376+
} else {
1377+
password = valueAsString
1378+
}
13591379
}
13601380
}
13611381
// Check if an email-password user with the input email exists in SuperTokens

v2/src/plugins/codeTypeChecking/goEnv/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/go-chi/cors v1.2.1
1010
github.com/gorilla/handlers v1.5.1
1111
github.com/gorilla/mux v1.8.0
12-
github.com/supertokens/supertokens-golang v0.24.0
12+
github.com/supertokens/supertokens-golang v0.25.0
1313
)
1414

1515
require (

v2/src/plugins/codeTypeChecking/goEnv/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
9595
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
9696
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
9797
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
98-
github.com/supertokens/supertokens-golang v0.24.0 h1:/Y4PS72K7DHplMSskIsOBnvzpOppzFau/Y6q2X/5VeE=
99-
github.com/supertokens/supertokens-golang v0.24.0/go.mod h1:/n6zQ9461RscnnWB4Y4bWwzhPivnj8w79j/doqkLOs8=
98+
github.com/supertokens/supertokens-golang v0.25.0 h1:yTWBKD8tZFe6sYSQ5h1IYTsH/c3UQlqyqRvSFGVXx/o=
99+
github.com/supertokens/supertokens-golang v0.25.0/go.mod h1:/n6zQ9461RscnnWB4Y4bWwzhPivnj8w79j/doqkLOs8=
100100
github.com/twilio/twilio-go v0.26.0 h1:wFW4oTe3/LKt6bvByP7eio8JsjtaLHjMQKOUEzQry7U=
101101
github.com/twilio/twilio-go v0.26.0/go.mod h1:lz62Hopu4vicpQ056H5TJ0JE4AP0rS3sQ35/ejmgOwE=
102102
github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=

v2/src/plugins/codeTypeChecking/pythonEnv/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ six==1.16.0
7272
sniffio==1.3.0
7373
sqlparse==0.4.2
7474
starlette==0.14.2
75-
supertokens-python==0.24.0
75+
supertokens-python==0.24.3
7676
tldextract==3.1.0
7777
toml==0.10.2
7878
tomli==2.0.1

v2/thirdpartyemailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ function emailNotAllowed(email: string) {
6767

6868
```go
6969
import (
70+
"errors"
71+
7072
"github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels"
7173
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
7274
"github.com/supertokens/supertokens-golang/supertokens"
@@ -82,7 +84,11 @@ func main() {
8284
email := ""
8385
for _, v := range formFields {
8486
if v.ID == "email" {
85-
email = v.Value
87+
valueAsString, asStrOk := v.Value.(string)
88+
if !asStrOk {
89+
return epmodels.SignUpPOSTResponse{}, errors.New("Should never come here as we check the type during validation")
90+
}
91+
email = valueAsString
8692
}
8793
}
8894
if emailNotAllowed(email) {

v2/thirdpartyemailpassword/common-customizations/handling-signinup-success.mdx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ SuperTokens.init({
561561
```go
562562
import (
563563
"fmt"
564+
"errors"
564565

565566
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
566567
"github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels"
@@ -596,7 +597,11 @@ func main() {
596597
name := ""
597598
for _, field := range formFields {
598599
if field.ID == "name" {
599-
name = field.Value
600+
valueAsString, asStrOk := field.Value.(string)
601+
if !asStrOk {
602+
return epmodels.SignUpPOSTResponse{}, errors.New("name should be a string")
603+
}
604+
name = valueAsString
600605
}
601606
}
602607

v2/thirdpartyemailpassword/migration/account-creation/ep-migration-without-password-hash.mdx

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ init(
139139

140140
```go
141141
import (
142+
"errors"
143+
142144
"github.com/supertokens/supertokens-golang/recipe/emailpassword"
143145
"github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels"
144146
"github.com/supertokens/supertokens-golang/supertokens"
@@ -159,7 +161,11 @@ func main() {
159161
email := ""
160162
for _, formField := range formFields {
161163
if formField.ID == "email" {
162-
email = formField.Value
164+
valueAsString, asStrOk := formField.Value.(string)
165+
if !asStrOk {
166+
return epmodels.SignUpPOSTResponse{}, errors.New("Should never come here as we check the type during validation")
167+
}
168+
email = valueAsString
163169
}
164170
}
165171
// Check if the user signing in exists in the external provider
@@ -428,11 +434,16 @@ func main() {
428434
email := ""
429435
password := ""
430436
for _, formField := range formFields {
431-
if formField.ID == "email" {
432-
email = formField.Value
433-
}
434-
if formField.ID == "password" {
435-
password = formField.Value
437+
if formField.ID == "email" || formField.ID == "password" {
438+
valueAsString, asStrOk := formField.Value.(string)
439+
if !asStrOk {
440+
return epmodels.SignInPOSTResponse{}, errors.New("Should never come here as we check the type during validation")
441+
}
442+
if formField.ID == "email" {
443+
email = valueAsString
444+
} else {
445+
password = valueAsString
446+
}
436447
}
437448
}
438449
// Check if an email-password user with the input email exists in SuperTokens
@@ -768,7 +779,11 @@ func main() {
768779
var email *string = nil
769780
for _, field := range formFields {
770781
if field.ID == "email" {
771-
email = &field.Value
782+
valueAsString, asStrOk := field.Value.(string)
783+
if !asStrOk {
784+
return epmodels.GeneratePasswordResetTokenPOSTResponse{}, errors.New("Should never come here as we check the type during validation")
785+
}
786+
email = &valueAsString
772787
}
773788
}
774789

@@ -1351,11 +1366,16 @@ func main() {
13511366
email := ""
13521367
password := ""
13531368
for _, formField := range formFields {
1354-
if formField.ID == "email" {
1355-
email = formField.Value
1356-
}
1357-
if formField.ID == "password" {
1358-
password = formField.Value
1369+
if formField.ID == "email" || formField.ID == "password" {
1370+
valueAsString, asStrOk := formField.Value.(string)
1371+
if !asStrOk {
1372+
return epmodels.SignInPOSTResponse{}, errors.New("Should never come here as we check the type during validation")
1373+
}
1374+
if formField.ID == "email" {
1375+
email = valueAsString
1376+
} else {
1377+
password = valueAsString
1378+
}
13591379
}
13601380
}
13611381
// Check if an email-password user with the input email exists in SuperTokens

0 commit comments

Comments
 (0)