Skip to content

Commit

Permalink
Cleanup and optimize the code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
deepjyoti30-st committed Sep 24, 2024
1 parent b14a6ff commit f863cbe
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions recipe/emailpassword/api/implementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func MakeAPIImplementation() epmodels.APIInterface {
var email string
for _, formField := range formFields {
if formField.ID == "email" {
// NOTE: This check 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.
valueAsString, parseErr := withValueAsString(formField.Value, "email value needs to be a string")
if parseErr != nil {
return epmodels.GeneratePasswordResetTokenPOSTResponse{
Expand Down Expand Up @@ -108,6 +112,10 @@ func MakeAPIImplementation() epmodels.APIInterface {
var newPassword string
for _, formField := range formFields {
if formField.ID == "password" {
// NOTE: This check 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.
valueAsString, parseErr := withValueAsString(formField.Value, "password value needs to be a string")
if parseErr != nil {
return epmodels.ResetPasswordPOSTResponse{
Expand Down Expand Up @@ -138,22 +146,22 @@ func MakeAPIImplementation() epmodels.APIInterface {
var email string
var password string
for _, formField := range formFields {
if formField.ID == "email" {
valueAsString, parseErr := withValueAsString(formField.Value, "email value needs to be a string")
// 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, parseErr := withValueAsString(formField.Value, fmt.Sprintf("%s value needs to be a string", formField.ID))
if parseErr != nil {
return epmodels.SignInPOSTResponse{
WrongCredentialsError: &struct{}{},
}, nil
}
email = valueAsString
} else if formField.ID == "password" {
valueAsString, parseErr := withValueAsString(formField.Value, "password value needs to be a string")
if parseErr != nil {
return epmodels.SignInPOSTResponse{
WrongCredentialsError: &struct{}{},
}, nil
if formField.ID == "email" {
email = valueAsString
} else {
password = valueAsString
}
password = valueAsString
}
}

Expand Down Expand Up @@ -188,22 +196,22 @@ func MakeAPIImplementation() epmodels.APIInterface {
var email string
var password string
for _, formField := range formFields {
if formField.ID == "email" {
valueAsString, parseErr := withValueAsString(formField.Value, "email value needs to be a string")
// 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, parseErr := withValueAsString(formField.Value, fmt.Sprintf("%s value needs to be a string", formField.ID))
if parseErr != nil {
return epmodels.SignUpPOSTResponse{
GeneralError: &supertokens.GeneralErrorResponse{Message: parseErr.Error()},
}, nil
}
email = valueAsString
} else if formField.ID == "password" {
valueAsString, parseErr := withValueAsString(formField.Value, "password value needs to be a string")
if parseErr != nil {
return epmodels.SignUpPOSTResponse{
GeneralError: &supertokens.GeneralErrorResponse{Message: parseErr.Error()},
}, nil
if formField.ID == "email" {
email = valueAsString
} else {
password = valueAsString
}
password = valueAsString
}
}

Expand Down

0 comments on commit f863cbe

Please sign in to comment.