Spaces:
Sleeping
fix: Save session after OAuth callback before redirect
Browse filesLOGIN LOOP FIXED! Session data now persists from callback to profile.
PROBLEM: Callback redirect was losing session data
- Callback sets session['user_id'] = 'qnib' β
- Redirects to /profile/ β‘οΈ
- Profile checks session['user_id'] β MISSING
- Redirects to /login β infinite loop π
ROOT CAUSE: redirect() bypasses Flask's automatic session save
Same issue as login endpoint - manual save needed
SOLUTION: session_interface.save_session() before redirect
Now user_id persists across redirect
BEFORE:
/callback β sets user_id β redirect (session lost)
/profile/ β no user_id β redirect /login
/login β new OAuth flow β loop
AFTER:
/callback β sets user_id β manual save β redirect
/profile/ β user_id present β show profile β
- src/routes/auth.py +8 -1
|
@@ -138,7 +138,14 @@ def callback():
|
|
| 138 |
session["access_token"] = token.get("access_token")
|
| 139 |
|
| 140 |
flash(f"Welcome back, {display_name}!", "success")
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
except Exception as e:
|
| 144 |
# Log the full error for debugging
|
|
|
|
| 138 |
session["access_token"] = token.get("access_token")
|
| 139 |
|
| 140 |
flash(f"Welcome back, {display_name}!", "success")
|
| 141 |
+
|
| 142 |
+
# CRITICAL: Manually save session before redirect
|
| 143 |
+
# Same issue as login - redirect response bypasses automatic session save
|
| 144 |
+
response = redirect(url_for("profile.view_profile"))
|
| 145 |
+
from flask import current_app
|
| 146 |
+
current_app.session_interface.save_session(current_app, session, response)
|
| 147 |
+
logger.info(f"[OAUTH] Session saved with user_id={user_id}, redirecting to profile")
|
| 148 |
+
return response
|
| 149 |
|
| 150 |
except Exception as e:
|
| 151 |
# Log the full error for debugging
|