From 583c86002685bdaf507cf5cea18cec5d74e464ac Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Thu, 26 Sep 2024 12:24:37 +0530 Subject: [PATCH 1/3] Update all go docs with type fixes --- v2/attackprotectionsuite/backend-setup.mdx | 60 +++++++++++----- .../custom-response/general-error.mdx | 12 +++- .../handling-signup-success.mdx | 8 ++- .../emailpassword-changes.mdx | 36 +++++++++- .../ep-migration-without-password-hash.mdx | 68 +++++++++++++++---- v2/src/plugins/codeTypeChecking/goEnv/go.mod | 2 +- v2/src/plugins/codeTypeChecking/goEnv/go.sum | 4 +- .../pythonEnv/requirements.txt | 2 +- .../custom-response/general-error.mdx | 12 +++- .../handling-signinup-success.mdx | 8 ++- .../ep-migration-without-password-hash.mdx | 68 +++++++++++++++---- 11 files changed, 229 insertions(+), 51 deletions(-) diff --git a/v2/attackprotectionsuite/backend-setup.mdx b/v2/attackprotectionsuite/backend-setup.mdx index 746555ddd..255837d86 100644 --- a/v2/attackprotectionsuite/backend-setup.mdx +++ b/v2/attackprotectionsuite/backend-setup.mdx @@ -594,6 +594,7 @@ import ( "encoding/hex" "encoding/json" "net/http" + "fmt" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" @@ -777,13 +778,22 @@ func main() { email := "" password := "" for _, field := range formFields { - if field.ID == "email" { - email = field.Value - break - } - if field.ID == "password" { - password = field.Value - break + // NOTE: The check for type of password/email will never actually + // fail because the parent function already checks for the type + // however in order to read the value as a string, it's safer to + // keep it here in case something changes in the future. + if field.ID == "email" || field.ID == "password" { + valueAsString, asStrOk := field.Value.(string) + if !asStrOk { + return epmodels.SignUpPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: fmt.Sprintf(`%s value needs to be a string`, field.ID)}, + }, nil + } + if field.ID == "email" { + email = valueAsString + } else { + password = valueAsString + } } } bruteForceConfig := getBruteForceConfig(email, ip, actionType) @@ -841,13 +851,22 @@ func main() { email := "" password := "" for _, field := range formFields { - if field.ID == "email" { - email = field.Value - break - } - if field.ID == "password" { - password = field.Value - break + // NOTE: The check for type of password/email will never actually + // fail because the parent function already checks for the type + // however in order to read the value as a string, it's safer to + // keep it here in case something changes in the future. + if field.ID == "email" || field.ID == "password" { + valueAsString, asStrOk := field.Value.(string) + if !asStrOk { + return epmodels.SignInPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: fmt.Sprintf(`%s value needs to be a string`, field.ID)}, + }, nil + } + if field.ID == "email" { + email = valueAsString + } else { + password = valueAsString + } } } bruteForceConfig := getBruteForceConfig(email, ip, actionType) @@ -904,9 +923,18 @@ func main() { ip := getIpFromRequest(options.Req) email := "" for _, field := range formFields { + // NOTE: The check for type of email will never actually + // fail because the parent function already checks for the type + // however in order to read the value as a string, it's safer to + // keep it here in case something changes in the future. if field.ID == "email" { - email = field.Value - break + valueAsString, asStrOk := field.Value.(string) + if !asStrOk { + return epmodels.GeneratePasswordResetTokenPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, + }, nil + } + email = valueAsString } } bruteForceConfig := getBruteForceConfig(email, ip, actionType) diff --git a/v2/emailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx b/v2/emailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx index bbf83347c..2c2536e69 100644 --- a/v2/emailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx +++ b/v2/emailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx @@ -81,8 +81,18 @@ func main() { (*originalImplementation.SignUpPOST) = func(formFields []epmodels.TypeFormField, tenantId string, options epmodels.APIOptions, userContext supertokens.UserContext) (epmodels.SignUpPOSTResponse, error) { email := "" for _, v := range formFields { + // NOTE: The check for type of email will never actually + // fail because the parent function already checks for the type + // however in order to read the value as a string, it's safer to + // keep it here in case something changes in the future. if v.ID == "email" { - email = v.Value + valueAsString, asStrOk := v.Value.(string) + if !asStrOk { + return epmodels.SignUpPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, + }, nil + } + email = valueAsString } } if emailNotAllowed(email) { diff --git a/v2/emailpassword/common-customizations/handling-signup-success.mdx b/v2/emailpassword/common-customizations/handling-signup-success.mdx index 31e8e2db6..68d113282 100644 --- a/v2/emailpassword/common-customizations/handling-signup-success.mdx +++ b/v2/emailpassword/common-customizations/handling-signup-success.mdx @@ -417,7 +417,13 @@ func main() { name := "" for _, field := range formFields { if field.ID == "name" { - name = field.Value + valueAsString, asStrOk := field.Value.(string) + if !asStrOk { + return epmodels.SignUpPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: "name value needs to be a string"}, + }, nil + } + name = valueAsString } } diff --git a/v2/emailpassword/common-customizations/username-password/emailpassword-changes.mdx b/v2/emailpassword/common-customizations/username-password/emailpassword-changes.mdx index 07e984e0b..fac227dae 100644 --- a/v2/emailpassword/common-customizations/username-password/emailpassword-changes.mdx +++ b/v2/emailpassword/common-customizations/username-password/emailpassword-changes.mdx @@ -501,8 +501,18 @@ func main() { // sign up successful actualEmail := "" for _, field := range formFields { + // NOTE: The check for type of email will never actually + // fail because the parent function already checks for the type + // however in order to read the value as a string, it's safer to + // keep it here in case something changes in the future. if field.ID == "email" { - actualEmail = field.Value + valueAsString, asStrOk := field.Value.(string) + if !asStrOk { + return epmodels.SignUpPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, + }, nil + } + actualEmail = valueAsString } } if actualEmail == "" { @@ -1068,8 +1078,18 @@ func main() { (*originalImplementation.GeneratePasswordResetTokenPOST) = func(formFields []epmodels.TypeFormField, tenantId string, options epmodels.APIOptions, userContext supertokens.UserContext) (epmodels.GeneratePasswordResetTokenPOSTResponse, error) { emailOrUsername := "" for _, field := range formFields { + // NOTE: The check for type of email will never actually + // fail because the parent function already checks for the type + // however in order to read the value as a string, it's safer to + // keep it here in case something changes in the future. if field.ID == "email" { - emailOrUsername = field.Value + valueAsString, asStrOk := field.Value.(string) + if !asStrOk { + return epmodels.GeneratePasswordResetTokenPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, + }, nil + } + emailOrUsername = valueAsString } } if isInputEmail(emailOrUsername) { @@ -1103,8 +1123,18 @@ func main() { username := "" for _, field := range formFields { + // NOTE: The check for type of email will never actually + // fail because the parent function already checks for the type + // however in order to read the value as a string, it's safer to + // keep it here in case something changes in the future. if field.ID == "email" { - username = field.Value + valueAsString, asStrOk := field.Value.(string) + if !asStrOk { + return epmodels.GeneratePasswordResetTokenPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, + }, nil + } + username = valueAsString } } supertokensUser, err := emailpassword.GetUserByEmail(tenantId, username) diff --git a/v2/emailpassword/migration/account-creation/ep-migration-without-password-hash.mdx b/v2/emailpassword/migration/account-creation/ep-migration-without-password-hash.mdx index 678b00a4c..b6e745376 100644 --- a/v2/emailpassword/migration/account-creation/ep-migration-without-password-hash.mdx +++ b/v2/emailpassword/migration/account-creation/ep-migration-without-password-hash.mdx @@ -158,8 +158,18 @@ func main() { (*originalImplementation.SignUpPOST) = func(formFields []epmodels.TypeFormField, tenantId string, options epmodels.APIOptions, userContext supertokens.UserContext) (epmodels.SignUpPOSTResponse, error) { email := "" for _, formField := range formFields { + // NOTE: The check for type of email will never actually + // fail because the parent function already checks for the type + // however in order to read the value as a string, it's safer to + // keep it here in case something changes in the future. if formField.ID == "email" { - email = formField.Value + valueAsString, asStrOk := formField.Value.(string) + if !asStrOk { + return epmodels.SignUpPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, + }, nil + } + email = valueAsString } } // Check if the user signing in exists in the external provider @@ -406,6 +416,7 @@ init( ```go import ( "errors" + "fmt" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" @@ -428,11 +439,22 @@ func main() { email := "" password := "" for _, formField := range formFields { - if formField.ID == "email" { - email = formField.Value - } - if formField.ID == "password" { - password = formField.Value + // NOTE: The check for type of password/email will never actually + // fail because the parent function already checks for the type + // however in order to read the value as a string, it's safer to + // keep it here in case something changes in the future. + if formField.ID == "email" || formField.ID == "password" { + valueAsString, asStrOk := formField.Value.(string) + if !asStrOk { + return epmodels.SignInPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: fmt.Sprintf(`%s value needs to be a string`, formField.ID)}, + }, nil + } + if formField.ID == "email" { + email = valueAsString + } else { + password = valueAsString + } } } // Check if an email-password user with the input email exists in SuperTokens @@ -767,8 +789,18 @@ func main() { // Retrieve email from the form fields var email *string = nil for _, field := range formFields { + // NOTE: The check for type of email will never actually + // fail because the parent function already checks for the type + // however in order to read the value as a string, it's safer to + // keep it here in case something changes in the future. if field.ID == "email" { - email = &field.Value + valueAsString, asStrOk := field.Value.(string) + if !asStrOk { + return epmodels.GeneratePasswordResetTokenPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, + }, nil + } + email = &valueAsString } } @@ -1328,6 +1360,7 @@ init( ```go import ( "errors" + "fmt" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" @@ -1351,11 +1384,22 @@ func main() { email := "" password := "" for _, formField := range formFields { - if formField.ID == "email" { - email = formField.Value - } - if formField.ID == "password" { - password = formField.Value + // NOTE: The check for type of password/email will never actually + // fail because the parent function already checks for the type + // however in order to read the value as a string, it's safer to + // keep it here in case something changes in the future. + if formField.ID == "email" || formField.ID == "password" { + valueAsString, asStrOk := formField.Value.(string) + if !asStrOk { + return epmodels.SignInPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: fmt.Sprintf(`%s value needs to be a string`, formField.ID)}, + }, nil + } + if formField.ID == "email" { + email = valueAsString + } else { + password = valueAsString + } } } // Check if an email-password user with the input email exists in SuperTokens diff --git a/v2/src/plugins/codeTypeChecking/goEnv/go.mod b/v2/src/plugins/codeTypeChecking/goEnv/go.mod index 565ce9305..2d12c54f6 100644 --- a/v2/src/plugins/codeTypeChecking/goEnv/go.mod +++ b/v2/src/plugins/codeTypeChecking/goEnv/go.mod @@ -9,7 +9,7 @@ require ( github.com/go-chi/cors v1.2.1 github.com/gorilla/handlers v1.5.1 github.com/gorilla/mux v1.8.0 - github.com/supertokens/supertokens-golang v0.24.0 + github.com/supertokens/supertokens-golang v0.25.0 ) require ( diff --git a/v2/src/plugins/codeTypeChecking/goEnv/go.sum b/v2/src/plugins/codeTypeChecking/goEnv/go.sum index 2008c56b8..e87a83529 100644 --- a/v2/src/plugins/codeTypeChecking/goEnv/go.sum +++ b/v2/src/plugins/codeTypeChecking/goEnv/go.sum @@ -95,8 +95,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/supertokens/supertokens-golang v0.24.0 h1:/Y4PS72K7DHplMSskIsOBnvzpOppzFau/Y6q2X/5VeE= -github.com/supertokens/supertokens-golang v0.24.0/go.mod h1:/n6zQ9461RscnnWB4Y4bWwzhPivnj8w79j/doqkLOs8= +github.com/supertokens/supertokens-golang v0.25.0 h1:yTWBKD8tZFe6sYSQ5h1IYTsH/c3UQlqyqRvSFGVXx/o= +github.com/supertokens/supertokens-golang v0.25.0/go.mod h1:/n6zQ9461RscnnWB4Y4bWwzhPivnj8w79j/doqkLOs8= github.com/twilio/twilio-go v0.26.0 h1:wFW4oTe3/LKt6bvByP7eio8JsjtaLHjMQKOUEzQry7U= github.com/twilio/twilio-go v0.26.0/go.mod h1:lz62Hopu4vicpQ056H5TJ0JE4AP0rS3sQ35/ejmgOwE= github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo= diff --git a/v2/src/plugins/codeTypeChecking/pythonEnv/requirements.txt b/v2/src/plugins/codeTypeChecking/pythonEnv/requirements.txt index 0148110d1..c4fa3e4c4 100644 --- a/v2/src/plugins/codeTypeChecking/pythonEnv/requirements.txt +++ b/v2/src/plugins/codeTypeChecking/pythonEnv/requirements.txt @@ -72,7 +72,7 @@ six==1.16.0 sniffio==1.3.0 sqlparse==0.4.2 starlette==0.14.2 -supertokens-python==0.24.0 +supertokens-python==0.24.3 tldextract==3.1.0 toml==0.10.2 tomli==2.0.1 diff --git a/v2/thirdpartyemailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx b/v2/thirdpartyemailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx index 896ebed93..cc14aec13 100644 --- a/v2/thirdpartyemailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx +++ b/v2/thirdpartyemailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx @@ -81,8 +81,18 @@ func main() { (*originalImplementation.SignUpPOST) = func(formFields []epmodels.TypeFormField, tenantId string, options epmodels.APIOptions, userContext supertokens.UserContext) (epmodels.SignUpPOSTResponse, error) { email := "" for _, v := range formFields { + // NOTE: The check for type of email will never actually + // fail because the parent function already checks for the type + // however in order to read the value as a string, it's safer to + // keep it here in case something changes in the future. if v.ID == "email" { - email = v.Value + valueAsString, asStrOk := v.Value.(string) + if !asStrOk { + return epmodels.SignUpPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, + }, nil + } + email = valueAsString } } if emailNotAllowed(email) { diff --git a/v2/thirdpartyemailpassword/common-customizations/handling-signinup-success.mdx b/v2/thirdpartyemailpassword/common-customizations/handling-signinup-success.mdx index de08042e7..c142d3ebc 100644 --- a/v2/thirdpartyemailpassword/common-customizations/handling-signinup-success.mdx +++ b/v2/thirdpartyemailpassword/common-customizations/handling-signinup-success.mdx @@ -596,7 +596,13 @@ func main() { name := "" for _, field := range formFields { if field.ID == "name" { - name = field.Value + valueAsString, asStrOk := field.Value.(string) + if !asStrOk { + return epmodels.SignUpPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: "name value needs to be a string"}, + }, nil + } + name = valueAsString } } diff --git a/v2/thirdpartyemailpassword/migration/account-creation/ep-migration-without-password-hash.mdx b/v2/thirdpartyemailpassword/migration/account-creation/ep-migration-without-password-hash.mdx index 8e555693d..d59c72d12 100644 --- a/v2/thirdpartyemailpassword/migration/account-creation/ep-migration-without-password-hash.mdx +++ b/v2/thirdpartyemailpassword/migration/account-creation/ep-migration-without-password-hash.mdx @@ -158,8 +158,18 @@ func main() { (*originalImplementation.SignUpPOST) = func(formFields []epmodels.TypeFormField, tenantId string, options epmodels.APIOptions, userContext supertokens.UserContext) (epmodels.SignUpPOSTResponse, error) { email := "" for _, formField := range formFields { + // NOTE: The check for type of email will never actually + // fail because the parent function already checks for the type + // however in order to read the value as a string, it's safer to + // keep it here in case something changes in the future. if formField.ID == "email" { - email = formField.Value + valueAsString, asStrOk := formField.Value.(string) + if !asStrOk { + return epmodels.SignUpPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, + }, nil + } + email = valueAsString } } // Check if the user signing in exists in the external provider @@ -406,6 +416,7 @@ init( ```go import ( "errors" + "fmt" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" @@ -428,11 +439,22 @@ func main() { email := "" password := "" for _, formField := range formFields { - if formField.ID == "email" { - email = formField.Value - } - if formField.ID == "password" { - password = formField.Value + // NOTE: The check for type of password/email will never actually + // fail because the parent function already checks for the type + // however in order to read the value as a string, it's safer to + // keep it here in case something changes in the future. + if formField.ID == "email" || formField.ID == "password" { + valueAsString, asStrOk := formField.Value.(string) + if !asStrOk { + return epmodels.SignInPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: fmt.Sprintf(`%s value needs to be a string`, formField.ID)}, + }, nil + } + if formField.ID == "email" { + email = valueAsString + } else { + password = valueAsString + } } } // Check if an email-password user with the input email exists in SuperTokens @@ -767,8 +789,18 @@ func main() { // Retrieve email from the form fields var email *string = nil for _, field := range formFields { + // NOTE: The check for type of email will never actually + // fail because the parent function already checks for the type + // however in order to read the value as a string, it's safer to + // keep it here in case something changes in the future. if field.ID == "email" { - email = &field.Value + valueAsString, asStrOk := field.Value.(string) + if !asStrOk { + return epmodels.GeneratePasswordResetTokenPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, + }, nil + } + email = &valueAsString } } @@ -1328,6 +1360,7 @@ init( ```go import ( "errors" + "fmt" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" @@ -1351,11 +1384,22 @@ func main() { email := "" password := "" for _, formField := range formFields { - if formField.ID == "email" { - email = formField.Value - } - if formField.ID == "password" { - password = formField.Value + // NOTE: The check for type of password/email will never actually + // fail because the parent function already checks for the type + // however in order to read the value as a string, it's safer to + // keep it here in case something changes in the future. + if formField.ID == "email" || formField.ID == "password" { + valueAsString, asStrOk := formField.Value.(string) + if !asStrOk { + return epmodels.SignInPOSTResponse{ + GeneralError: &supertokens.GeneralErrorResponse{Message: fmt.Sprintf(`%s value needs to be a string`, formField.ID)}, + }, nil + } + if formField.ID == "email" { + email = valueAsString + } else { + password = valueAsString + } } } // Check if an email-password user with the input email exists in SuperTokens From d325781321356e93ba08d1b6babe1529fe4d0b17 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Thu, 26 Sep 2024 19:20:21 +0530 Subject: [PATCH 2/3] Update all go docs to return error instead of GeneralError --- v2/attackprotectionsuite/backend-setup.mdx | 26 +++----------- .../custom-response/general-error.mdx | 10 ++---- .../handling-signup-success.mdx | 5 ++- .../emailpassword-changes.mdx | 27 ++++---------- .../ep-migration-without-password-hash.mdx | 36 ++++--------------- .../custom-response/general-error.mdx | 10 ++---- .../handling-signinup-success.mdx | 5 ++- .../ep-migration-without-password-hash.mdx | 36 ++++--------------- 8 files changed, 32 insertions(+), 123 deletions(-) diff --git a/v2/attackprotectionsuite/backend-setup.mdx b/v2/attackprotectionsuite/backend-setup.mdx index 255837d86..563016a2a 100644 --- a/v2/attackprotectionsuite/backend-setup.mdx +++ b/v2/attackprotectionsuite/backend-setup.mdx @@ -594,7 +594,7 @@ import ( "encoding/hex" "encoding/json" "net/http" - "fmt" + "errors" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" @@ -778,16 +778,10 @@ func main() { email := "" password := "" for _, field := range formFields { - // NOTE: The check for type of password/email will never actually - // fail because the parent function already checks for the type - // however in order to read the value as a string, it's safer to - // keep it here in case something changes in the future. if field.ID == "email" || field.ID == "password" { valueAsString, asStrOk := field.Value.(string) if !asStrOk { - return epmodels.SignUpPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: fmt.Sprintf(`%s value needs to be a string`, field.ID)}, - }, nil + return epmodels.SignUpPOSTResponse{}, errors.New("Should never come here as we check the type during validation") } if field.ID == "email" { email = valueAsString @@ -851,16 +845,10 @@ func main() { email := "" password := "" for _, field := range formFields { - // NOTE: The check for type of password/email will never actually - // fail because the parent function already checks for the type - // however in order to read the value as a string, it's safer to - // keep it here in case something changes in the future. if field.ID == "email" || field.ID == "password" { valueAsString, asStrOk := field.Value.(string) if !asStrOk { - return epmodels.SignInPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: fmt.Sprintf(`%s value needs to be a string`, field.ID)}, - }, nil + return epmodels.SignInPOSTResponse{}, errors.New("Should never come here as we check the type during validation") } if field.ID == "email" { email = valueAsString @@ -923,16 +911,10 @@ func main() { ip := getIpFromRequest(options.Req) email := "" for _, field := range formFields { - // NOTE: The check for type of email will never actually - // fail because the parent function already checks for the type - // however in order to read the value as a string, it's safer to - // keep it here in case something changes in the future. if field.ID == "email" { valueAsString, asStrOk := field.Value.(string) if !asStrOk { - return epmodels.GeneratePasswordResetTokenPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, - }, nil + return epmodels.GeneratePasswordResetTokenPOSTResponse{}, errors.New("Should never come here as we check the type during validation") } email = valueAsString } diff --git a/v2/emailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx b/v2/emailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx index 2c2536e69..7ed597bd6 100644 --- a/v2/emailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx +++ b/v2/emailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx @@ -67,6 +67,8 @@ function emailNotAllowed(email: string) { ```go import ( + "errors" + "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/supertokens" @@ -81,16 +83,10 @@ func main() { (*originalImplementation.SignUpPOST) = func(formFields []epmodels.TypeFormField, tenantId string, options epmodels.APIOptions, userContext supertokens.UserContext) (epmodels.SignUpPOSTResponse, error) { email := "" for _, v := range formFields { - // NOTE: The check for type of email will never actually - // fail because the parent function already checks for the type - // however in order to read the value as a string, it's safer to - // keep it here in case something changes in the future. if v.ID == "email" { valueAsString, asStrOk := v.Value.(string) if !asStrOk { - return epmodels.SignUpPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, - }, nil + return epmodels.SignUpPOSTResponse{}, errors.New("Should never come here as we check the type during validation") } email = valueAsString } diff --git a/v2/emailpassword/common-customizations/handling-signup-success.mdx b/v2/emailpassword/common-customizations/handling-signup-success.mdx index 68d113282..0fb8b6d35 100644 --- a/v2/emailpassword/common-customizations/handling-signup-success.mdx +++ b/v2/emailpassword/common-customizations/handling-signup-success.mdx @@ -382,6 +382,7 @@ SuperTokens.init({ ```go import ( "fmt" + "errors" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" @@ -419,9 +420,7 @@ func main() { if field.ID == "name" { valueAsString, asStrOk := field.Value.(string) if !asStrOk { - return epmodels.SignUpPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: "name value needs to be a string"}, - }, nil + return epmodels.SignUpPOSTResponse{}, errors.New("name should be a string") } name = valueAsString } diff --git a/v2/emailpassword/common-customizations/username-password/emailpassword-changes.mdx b/v2/emailpassword/common-customizations/username-password/emailpassword-changes.mdx index fac227dae..5869e796a 100644 --- a/v2/emailpassword/common-customizations/username-password/emailpassword-changes.mdx +++ b/v2/emailpassword/common-customizations/username-password/emailpassword-changes.mdx @@ -453,6 +453,8 @@ SuperTokens.init({ ```go import ( + "errors" + "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" "github.com/supertokens/supertokens-golang/supertokens" @@ -501,16 +503,10 @@ func main() { // sign up successful actualEmail := "" for _, field := range formFields { - // NOTE: The check for type of email will never actually - // fail because the parent function already checks for the type - // however in order to read the value as a string, it's safer to - // keep it here in case something changes in the future. if field.ID == "email" { valueAsString, asStrOk := field.Value.(string) if !asStrOk { - return epmodels.SignUpPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, - }, nil + return epmodels.SignUpPOSTResponse{}, errors.New("Should never come here as we check the type during validation") } actualEmail = valueAsString } @@ -1013,6 +1009,7 @@ SuperTokens.init({ ```go import ( "regexp" + "errors" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" @@ -1078,16 +1075,10 @@ func main() { (*originalImplementation.GeneratePasswordResetTokenPOST) = func(formFields []epmodels.TypeFormField, tenantId string, options epmodels.APIOptions, userContext supertokens.UserContext) (epmodels.GeneratePasswordResetTokenPOSTResponse, error) { emailOrUsername := "" for _, field := range formFields { - // NOTE: The check for type of email will never actually - // fail because the parent function already checks for the type - // however in order to read the value as a string, it's safer to - // keep it here in case something changes in the future. if field.ID == "email" { valueAsString, asStrOk := field.Value.(string) if !asStrOk { - return epmodels.GeneratePasswordResetTokenPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, - }, nil + return epmodels.GeneratePasswordResetTokenPOSTResponse{}, errors.New("Should never come here as we check the type during validation") } emailOrUsername = valueAsString } @@ -1123,16 +1114,10 @@ func main() { username := "" for _, field := range formFields { - // NOTE: The check for type of email will never actually - // fail because the parent function already checks for the type - // however in order to read the value as a string, it's safer to - // keep it here in case something changes in the future. if field.ID == "email" { valueAsString, asStrOk := field.Value.(string) if !asStrOk { - return epmodels.GeneratePasswordResetTokenPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, - }, nil + return epmodels.GeneratePasswordResetTokenPOSTResponse{}, errors.New("Should never come here as we check the type during validation") } username = valueAsString } diff --git a/v2/emailpassword/migration/account-creation/ep-migration-without-password-hash.mdx b/v2/emailpassword/migration/account-creation/ep-migration-without-password-hash.mdx index b6e745376..b694af292 100644 --- a/v2/emailpassword/migration/account-creation/ep-migration-without-password-hash.mdx +++ b/v2/emailpassword/migration/account-creation/ep-migration-without-password-hash.mdx @@ -139,6 +139,8 @@ init( ```go import ( + "errors" + "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" "github.com/supertokens/supertokens-golang/supertokens" @@ -158,16 +160,10 @@ func main() { (*originalImplementation.SignUpPOST) = func(formFields []epmodels.TypeFormField, tenantId string, options epmodels.APIOptions, userContext supertokens.UserContext) (epmodels.SignUpPOSTResponse, error) { email := "" for _, formField := range formFields { - // NOTE: The check for type of email will never actually - // fail because the parent function already checks for the type - // however in order to read the value as a string, it's safer to - // keep it here in case something changes in the future. if formField.ID == "email" { valueAsString, asStrOk := formField.Value.(string) if !asStrOk { - return epmodels.SignUpPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, - }, nil + return epmodels.SignUpPOSTResponse{}, errors.New("Should never come here as we check the type during validation") } email = valueAsString } @@ -416,7 +412,6 @@ init( ```go import ( "errors" - "fmt" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" @@ -439,16 +434,10 @@ func main() { email := "" password := "" for _, formField := range formFields { - // NOTE: The check for type of password/email will never actually - // fail because the parent function already checks for the type - // however in order to read the value as a string, it's safer to - // keep it here in case something changes in the future. if formField.ID == "email" || formField.ID == "password" { valueAsString, asStrOk := formField.Value.(string) if !asStrOk { - return epmodels.SignInPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: fmt.Sprintf(`%s value needs to be a string`, formField.ID)}, - }, nil + return epmodels.SignInPOSTResponse{}, errors.New("Should never come here as we check the type during validation") } if formField.ID == "email" { email = valueAsString @@ -789,16 +778,10 @@ func main() { // Retrieve email from the form fields var email *string = nil for _, field := range formFields { - // NOTE: The check for type of email will never actually - // fail because the parent function already checks for the type - // however in order to read the value as a string, it's safer to - // keep it here in case something changes in the future. if field.ID == "email" { valueAsString, asStrOk := field.Value.(string) if !asStrOk { - return epmodels.GeneratePasswordResetTokenPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, - }, nil + return epmodels.GeneratePasswordResetTokenPOSTResponse{}, errors.New("Should never come here as we check the type during validation") } email = &valueAsString } @@ -1360,7 +1343,6 @@ init( ```go import ( "errors" - "fmt" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" @@ -1384,16 +1366,10 @@ func main() { email := "" password := "" for _, formField := range formFields { - // NOTE: The check for type of password/email will never actually - // fail because the parent function already checks for the type - // however in order to read the value as a string, it's safer to - // keep it here in case something changes in the future. if formField.ID == "email" || formField.ID == "password" { valueAsString, asStrOk := formField.Value.(string) if !asStrOk { - return epmodels.SignInPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: fmt.Sprintf(`%s value needs to be a string`, formField.ID)}, - }, nil + return epmodels.SignInPOSTResponse{}, errors.New("Should never come here as we check the type during validation") } if formField.ID == "email" { email = valueAsString diff --git a/v2/thirdpartyemailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx b/v2/thirdpartyemailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx index cc14aec13..6233bcf6a 100644 --- a/v2/thirdpartyemailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx +++ b/v2/thirdpartyemailpassword/advanced-customizations/apis-override/custom-response/general-error.mdx @@ -67,6 +67,8 @@ function emailNotAllowed(email: string) { ```go import ( + "errors" + "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/supertokens" @@ -81,16 +83,10 @@ func main() { (*originalImplementation.SignUpPOST) = func(formFields []epmodels.TypeFormField, tenantId string, options epmodels.APIOptions, userContext supertokens.UserContext) (epmodels.SignUpPOSTResponse, error) { email := "" for _, v := range formFields { - // NOTE: The check for type of email will never actually - // fail because the parent function already checks for the type - // however in order to read the value as a string, it's safer to - // keep it here in case something changes in the future. if v.ID == "email" { valueAsString, asStrOk := v.Value.(string) if !asStrOk { - return epmodels.SignUpPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, - }, nil + return epmodels.SignUpPOSTResponse{}, errors.New("Should never come here as we check the type during validation") } email = valueAsString } diff --git a/v2/thirdpartyemailpassword/common-customizations/handling-signinup-success.mdx b/v2/thirdpartyemailpassword/common-customizations/handling-signinup-success.mdx index c142d3ebc..5ba8f271b 100644 --- a/v2/thirdpartyemailpassword/common-customizations/handling-signinup-success.mdx +++ b/v2/thirdpartyemailpassword/common-customizations/handling-signinup-success.mdx @@ -561,6 +561,7 @@ SuperTokens.init({ ```go import ( "fmt" + "errors" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" @@ -598,9 +599,7 @@ func main() { if field.ID == "name" { valueAsString, asStrOk := field.Value.(string) if !asStrOk { - return epmodels.SignUpPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: "name value needs to be a string"}, - }, nil + return epmodels.SignUpPOSTResponse{}, errors.New("Should never come here as we check the type during validation") } name = valueAsString } diff --git a/v2/thirdpartyemailpassword/migration/account-creation/ep-migration-without-password-hash.mdx b/v2/thirdpartyemailpassword/migration/account-creation/ep-migration-without-password-hash.mdx index d59c72d12..6b5a356dd 100644 --- a/v2/thirdpartyemailpassword/migration/account-creation/ep-migration-without-password-hash.mdx +++ b/v2/thirdpartyemailpassword/migration/account-creation/ep-migration-without-password-hash.mdx @@ -139,6 +139,8 @@ init( ```go import ( + "errors" + "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" "github.com/supertokens/supertokens-golang/supertokens" @@ -158,16 +160,10 @@ func main() { (*originalImplementation.SignUpPOST) = func(formFields []epmodels.TypeFormField, tenantId string, options epmodels.APIOptions, userContext supertokens.UserContext) (epmodels.SignUpPOSTResponse, error) { email := "" for _, formField := range formFields { - // NOTE: The check for type of email will never actually - // fail because the parent function already checks for the type - // however in order to read the value as a string, it's safer to - // keep it here in case something changes in the future. if formField.ID == "email" { valueAsString, asStrOk := formField.Value.(string) if !asStrOk { - return epmodels.SignUpPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, - }, nil + return epmodels.SignUpPOSTResponse{}, errors.New("Should never come here as we check the type during validation") } email = valueAsString } @@ -416,7 +412,6 @@ init( ```go import ( "errors" - "fmt" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" @@ -439,16 +434,10 @@ func main() { email := "" password := "" for _, formField := range formFields { - // NOTE: The check for type of password/email will never actually - // fail because the parent function already checks for the type - // however in order to read the value as a string, it's safer to - // keep it here in case something changes in the future. if formField.ID == "email" || formField.ID == "password" { valueAsString, asStrOk := formField.Value.(string) if !asStrOk { - return epmodels.SignInPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: fmt.Sprintf(`%s value needs to be a string`, formField.ID)}, - }, nil + return epmodels.SignInPOSTResponse{}, errors.New("Should never come here as we check the type during validation") } if formField.ID == "email" { email = valueAsString @@ -789,16 +778,10 @@ func main() { // Retrieve email from the form fields var email *string = nil for _, field := range formFields { - // NOTE: The check for type of email will never actually - // fail because the parent function already checks for the type - // however in order to read the value as a string, it's safer to - // keep it here in case something changes in the future. if field.ID == "email" { valueAsString, asStrOk := field.Value.(string) if !asStrOk { - return epmodels.GeneratePasswordResetTokenPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: "email value needs to be a string"}, - }, nil + return epmodels.GeneratePasswordResetTokenPOSTResponse{}, errors.New("Should never come here as we check the type during validation") } email = &valueAsString } @@ -1360,7 +1343,6 @@ init( ```go import ( "errors" - "fmt" "github.com/supertokens/supertokens-golang/recipe/emailpassword" "github.com/supertokens/supertokens-golang/recipe/emailpassword/epmodels" @@ -1384,16 +1366,10 @@ func main() { email := "" password := "" for _, formField := range formFields { - // NOTE: The check for type of password/email will never actually - // fail because the parent function already checks for the type - // however in order to read the value as a string, it's safer to - // keep it here in case something changes in the future. if formField.ID == "email" || formField.ID == "password" { valueAsString, asStrOk := formField.Value.(string) if !asStrOk { - return epmodels.SignInPOSTResponse{ - GeneralError: &supertokens.GeneralErrorResponse{Message: fmt.Sprintf(`%s value needs to be a string`, formField.ID)}, - }, nil + return epmodels.SignInPOSTResponse{}, errors.New("Should never come here as we check the type during validation") } if formField.ID == "email" { email = valueAsString From 5eca9d208fa19b7abbd7933947bc14961edfe312 Mon Sep 17 00:00:00 2001 From: Deepjyoti Barman Date: Thu, 26 Sep 2024 19:25:25 +0530 Subject: [PATCH 3/3] Fix an error message to be more accurate --- .../common-customizations/handling-signinup-success.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v2/thirdpartyemailpassword/common-customizations/handling-signinup-success.mdx b/v2/thirdpartyemailpassword/common-customizations/handling-signinup-success.mdx index 5ba8f271b..ddf3f14f2 100644 --- a/v2/thirdpartyemailpassword/common-customizations/handling-signinup-success.mdx +++ b/v2/thirdpartyemailpassword/common-customizations/handling-signinup-success.mdx @@ -599,7 +599,7 @@ func main() { if field.ID == "name" { valueAsString, asStrOk := field.Value.(string) if !asStrOk { - return epmodels.SignUpPOSTResponse{}, errors.New("Should never come here as we check the type during validation") + return epmodels.SignUpPOSTResponse{}, errors.New("name should be a string") } name = valueAsString }