Update components/auth.py
Browse files- components/auth.py +18 -7
components/auth.py
CHANGED
|
@@ -4,19 +4,29 @@ from utils.db import sign_up_user, login_user
|
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
def register(email, password):
|
| 7 |
-
"""Handler for the signup process."""
|
| 8 |
if not email or not password:
|
| 9 |
return "❌ Email and password cannot be empty."
|
| 10 |
|
| 11 |
result = sign_up_user(email, password)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
if result.user and not result.session:
|
| 16 |
return "✅ Signup successful! Please check your email to confirm your account."
|
| 17 |
return "✅ Signup successful! You can now log in."
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
def login(email, password, current_user_state):
|
|
@@ -27,15 +37,16 @@ def login(email, password, current_user_state):
|
|
| 27 |
result = login_user(email, password)
|
| 28 |
|
| 29 |
if result and result.session:
|
| 30 |
-
# Update the user state
|
| 31 |
new_user_state = {"email": email, "logged_in": True}
|
| 32 |
return f"✅ Logged in as {email}", new_user_state
|
| 33 |
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
def logout(current_user_state):
|
| 38 |
"""Handler for the logout process."""
|
| 39 |
-
# Reset the user state
|
| 40 |
new_user_state = {"email": None, "logged_in": False}
|
| 41 |
return "👋 Logged out successfully.", new_user_state
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
def register(email, password):
|
| 7 |
+
"""Handler for the signup process with detailed error reporting."""
|
| 8 |
if not email or not password:
|
| 9 |
return "❌ Email and password cannot be empty."
|
| 10 |
|
| 11 |
result = sign_up_user(email, password)
|
| 12 |
|
| 13 |
+
# --- NEW: DETAILED ERROR CHECKING ---
|
| 14 |
+
if result is None:
|
| 15 |
+
# This happens if there was a major connection error in db.py
|
| 16 |
+
return "❌ Signup failed due to a server connection error. Check logs."
|
| 17 |
+
|
| 18 |
+
if result.user:
|
| 19 |
+
# This is the success path
|
| 20 |
if result.user and not result.session:
|
| 21 |
return "✅ Signup successful! Please check your email to confirm your account."
|
| 22 |
return "✅ Signup successful! You can now log in."
|
| 23 |
|
| 24 |
+
if hasattr(result, 'error') and result.error:
|
| 25 |
+
# If there is an error object from Supabase, display its message
|
| 26 |
+
return f"❌ Signup Failed: {result.error.message}"
|
| 27 |
+
|
| 28 |
+
# Fallback for unknown errors
|
| 29 |
+
return "❌ Signup failed. An unknown error occurred."
|
| 30 |
|
| 31 |
|
| 32 |
def login(email, password, current_user_state):
|
|
|
|
| 37 |
result = login_user(email, password)
|
| 38 |
|
| 39 |
if result and result.session:
|
|
|
|
| 40 |
new_user_state = {"email": email, "logged_in": True}
|
| 41 |
return f"✅ Logged in as {email}", new_user_state
|
| 42 |
|
| 43 |
+
if hasattr(result, 'error') and result.error:
|
| 44 |
+
return f"❌ Login Failed: {result.error.message}", current_user_state
|
| 45 |
+
|
| 46 |
+
return "❌ Login failed. Check credentials or confirm your email.", current_user_state
|
| 47 |
|
| 48 |
|
| 49 |
def logout(current_user_state):
|
| 50 |
"""Handler for the logout process."""
|
|
|
|
| 51 |
new_user_state = {"email": None, "logged_in": False}
|
| 52 |
return "👋 Logged out successfully.", new_user_state
|