Skip to content

Commit 9748c94

Browse files
43 - Fixing Registration Bug with Extended Model Data
1 parent 4c7d809 commit 9748c94

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

full_stack_python/auth/state.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,30 @@ def on_load(self):
2828

2929

3030
class MyRegisterState(reflex_local_auth.RegistrationState):
31-
# This event handler must be named something besides `handle_registration`!!!
31+
def handle_registration(
32+
self, form_data
33+
) -> rx.event.EventSpec | list[rx.event.EventSpec]:
34+
"""Handle registration form on_submit.
35+
36+
Set error_message appropriately based on validation results.
37+
38+
Args:
39+
form_data: A dict of form fields and values.
40+
"""
41+
username = form_data["username"]
42+
password = form_data["password"]
43+
validation_errors = self._validate_fields(
44+
username, password, form_data["confirm_password"]
45+
)
46+
if validation_errors:
47+
self.new_user_id = -1
48+
return validation_errors
49+
self._register_user(username, password)
50+
return self.new_user_id
51+
3252
def handle_registration_email(self, form_data):
33-
registration_result = super().handle_registration(form_data)
34-
print(self.new_user_id)
35-
if self.new_user_id >= 0:
53+
new_user_id = self.handle_registration(form_data)
54+
if new_user_id >= 0:
3655
with rx.session() as session:
3756
session.add(
3857
UserInfo(
@@ -41,4 +60,4 @@ def handle_registration_email(self, form_data):
4160
)
4261
)
4362
session.commit()
44-
return registration_result
63+
return type(self).successful_registration

full_stack_python/pages/protected.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import reflex as rx
2-
import reflex_local_auth
32

43
from ..ui.base import base_page
54

6-
# @rx.page(route='/about')
7-
@reflex_local_auth.require_login
85
def protected_page() -> rx.Component:
96
my_child = rx.vstack(
107
rx.heading("Protect Page", size="9"),

0 commit comments

Comments
 (0)