Spaces:
Running
Running
David Ko
commited on
Commit
ยท
dfdf7e7
1
Parent(s):
8fdf1e4
Fix login redirect loop with improved session handling and debugging
Browse files
api.py
CHANGED
@@ -83,10 +83,18 @@ users = {
|
|
83 |
@login_manager.user_loader
|
84 |
def load_user(user_id):
|
85 |
print(f"Loading user with ID: {user_id}")
|
86 |
-
#
|
|
|
|
|
|
|
|
|
87 |
for username, user in users.items():
|
88 |
-
if user.id == user_id:
|
89 |
-
print(f"User found: {username}")
|
|
|
|
|
|
|
|
|
90 |
return user
|
91 |
print(f"User not found with ID: {user_id}")
|
92 |
return None
|
@@ -1195,15 +1203,26 @@ def serve_static(filename):
|
|
1195 |
|
1196 |
# ์ธ๋ฑ์ค HTML ์ง์ ์๋น (๋ก๊ทธ์ธ ํ์)
|
1197 |
@app.route('/index.html')
|
1198 |
-
@login_required
|
1199 |
def serve_index_html():
|
|
|
|
|
|
|
|
|
|
|
|
|
1200 |
if not current_user.is_authenticated:
|
1201 |
print("User not authenticated, redirecting to login")
|
1202 |
return redirect(url_for('login'))
|
1203 |
|
1204 |
-
print(f"Serving index.html for authenticated user: {current_user.username}")
|
1205 |
# ์ธ์
์ํ ๋๋ฒ๊ทธ
|
1206 |
print(f"Session data: user_id={session.get('user_id')}, username={session.get('username')}, is_permanent={session.get('permanent', False)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
1207 |
return send_from_directory(app.static_folder, 'index.html')
|
1208 |
|
1209 |
# ๊ธฐ๋ณธ ๊ฒฝ๋ก ๋ฐ ๊ธฐํ ๊ฒฝ๋ก ์ฒ๋ฆฌ (๋ก๊ทธ์ธ ํ์)
|
|
|
83 |
@login_manager.user_loader
|
84 |
def load_user(user_id):
|
85 |
print(f"Loading user with ID: {user_id}")
|
86 |
+
# ์ธ์
๋๋ฒ๊ทธ ์ ๋ณด ์ถ๋ ฅ
|
87 |
+
print(f"Session data in user_loader: {dict(session)}")
|
88 |
+
print(f"Current request cookies: {request.cookies}")
|
89 |
+
|
90 |
+
# user_id๊ฐ ๋ฌธ์์ด๋ก ์ ๋ฌ๋๊ธฐ ๋๋ฌธ์ ์ฌ์ฉ์ ID๋ก ์ฒ๋ฆฌ
|
91 |
for username, user in users.items():
|
92 |
+
if str(user.id) == str(user_id): # ํ์คํ ๋ฌธ์์ด ๋น๊ต
|
93 |
+
print(f"User found: {username}, ID: {user.id}")
|
94 |
+
# ์ธ์
์ ๋ณด ์
๋ฐ์ดํธ
|
95 |
+
session['user_id'] = user.id
|
96 |
+
session['username'] = username
|
97 |
+
session.modified = True
|
98 |
return user
|
99 |
print(f"User not found with ID: {user_id}")
|
100 |
return None
|
|
|
1203 |
|
1204 |
# ์ธ๋ฑ์ค HTML ์ง์ ์๋น (๋ก๊ทธ์ธ ํ์)
|
1205 |
@app.route('/index.html')
|
|
|
1206 |
def serve_index_html():
|
1207 |
+
# ์ธ์
๋ฐ ์ฟ ํค ๋๋ฒ๊ทธ ์ ๋ณด
|
1208 |
+
print(f"Request to /index.html - Session data: {dict(session)}")
|
1209 |
+
print(f"Request to /index.html - Cookies: {request.cookies}")
|
1210 |
+
print(f"Request to /index.html - User authenticated: {current_user.is_authenticated}")
|
1211 |
+
|
1212 |
+
# ์ธ์ฆ ํ์ธ
|
1213 |
if not current_user.is_authenticated:
|
1214 |
print("User not authenticated, redirecting to login")
|
1215 |
return redirect(url_for('login'))
|
1216 |
|
1217 |
+
print(f"Serving index.html for authenticated user: {current_user.username} (ID: {current_user.id})")
|
1218 |
# ์ธ์
์ํ ๋๋ฒ๊ทธ
|
1219 |
print(f"Session data: user_id={session.get('user_id')}, username={session.get('username')}, is_permanent={session.get('permanent', False)}")
|
1220 |
+
|
1221 |
+
# ์ธ์
์ ์ง๋ฅผ ์ํด ์ธ์
์
๋ฐ์ดํธ
|
1222 |
+
session['user_id'] = current_user.id
|
1223 |
+
session['username'] = current_user.username
|
1224 |
+
session.modified = True
|
1225 |
+
|
1226 |
return send_from_directory(app.static_folder, 'index.html')
|
1227 |
|
1228 |
# ๊ธฐ๋ณธ ๊ฒฝ๋ก ๋ฐ ๊ธฐํ ๊ฒฝ๋ก ์ฒ๋ฆฌ (๋ก๊ทธ์ธ ํ์)
|