@@ -44,7 +44,10 @@ <h1 class="title">Module <code>supertokens_python.recipe.emailpassword.api.utils
4444from typing import Any, Dict, List, Union
4545
4646from supertokens_python.exceptions import raise_bad_input_exception
47- from supertokens_python.recipe.emailpassword.constants import FORM_FIELD_EMAIL_ID
47+ from supertokens_python.recipe.emailpassword.constants import (
48+ FORM_FIELD_EMAIL_ID,
49+ FORM_FIELD_PASSWORD_ID,
50+ )
4851from supertokens_python.recipe.emailpassword.exceptions import (
4952 raise_form_field_exception,
5053)
@@ -69,7 +72,9 @@ <h1 class="title">Module <code>supertokens_python.recipe.emailpassword.api.utils
6972 input_field: Union[None, FormField] = find_first_occurrence_in_list(
7073 lambda x: x.id == field.id, inputs
7174 )
72- is_invalid_value = input_field is None or input_field.value == ""
75+ is_invalid_value = input_field is None or (
76+ isinstance(input_field.value, str) and input_field.value == ""
77+ )
7378 if not field.optional and is_invalid_value:
7479 validation_errors.append(ErrorFormField(field.id, "Field is not optional"))
7580 continue
@@ -111,7 +116,18 @@ <h1 class="title">Module <code>supertokens_python.recipe.emailpassword.api.utils
111116 raise_bad_input_exception(
112117 "All elements of formFields must contain an 'id' and 'value' field"
113118 )
119+
114120 value = current_form_field["value"]
121+ if current_form_field["id"] in [
122+ FORM_FIELD_EMAIL_ID,
123+ FORM_FIELD_PASSWORD_ID,
124+ ] and not isinstance(value, str):
125+ # Ensure that the type is string else we will throw a bad input
126+ # error.
127+ raise_bad_input_exception(
128+ f"{current_form_field['id']} value must be a string"
129+ )
130+
115131 if current_form_field["id"] == FORM_FIELD_EMAIL_ID and isinstance(value, str):
116132 value = value.strip()
117133 form_fields.append(FormField(current_form_field["id"], value))
@@ -157,7 +173,18 @@ <h2 class="section-title" id="header-functions">Functions</h2>
157173 raise_bad_input_exception(
158174 "All elements of formFields must contain an 'id' and 'value' field"
159175 )
176+
160177 value = current_form_field["value"]
178+ if current_form_field["id"] in [
179+ FORM_FIELD_EMAIL_ID,
180+ FORM_FIELD_PASSWORD_ID,
181+ ] and not isinstance(value, str):
182+ # Ensure that the type is string else we will throw a bad input
183+ # error.
184+ raise_bad_input_exception(
185+ f"{current_form_field['id']} value must be a string"
186+ )
187+
161188 if current_form_field["id"] == FORM_FIELD_EMAIL_ID and isinstance(value, str):
162189 value = value.strip()
163190 form_fields.append(FormField(current_form_field["id"], value))
@@ -188,7 +215,9 @@ <h2 class="section-title" id="header-functions">Functions</h2>
188215 input_field: Union[None, FormField] = find_first_occurrence_in_list(
189216 lambda x: x.id == field.id, inputs
190217 )
191- is_invalid_value = input_field is None or input_field.value == ""
218+ is_invalid_value = input_field is None or (
219+ isinstance(input_field.value, str) and input_field.value == ""
220+ )
192221 if not field.optional and is_invalid_value:
193222 validation_errors.append(ErrorFormField(field.id, "Field is not optional"))
194223 continue
0 commit comments