Spaces:
Running
Running
sunheycho
commited on
Commit
ยท
f7e6892
1
Parent(s):
e8e0147
Fix login redirect loop for all browsers
Browse files- Removed @login_required decorator from serve_index_html
- Added manual session validation instead of Flask-Login
- Fixed infinite redirect issue affecting Chrome and Safari
- Direct session checking bypasses Flask-Login authentication issues
api.py
CHANGED
@@ -1516,6 +1516,13 @@ def login():
|
|
1516 |
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
|
1517 |
response.headers['Pragma'] = 'no-cache'
|
1518 |
response.headers['Expires'] = '0'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1519 |
return response
|
1520 |
else:
|
1521 |
error = 'Invalid username or password'
|
@@ -1743,21 +1750,34 @@ def serve_static(filename):
|
|
1743 |
|
1744 |
# ์ธ๋ฑ์ค HTML ์ง์ ์๋น (๋ก๊ทธ์ธ ํ์)
|
1745 |
@app.route('/index.html')
|
1746 |
-
@login_required
|
1747 |
def serve_index_html():
|
1748 |
# ์ธ์
๋ฐ ์ฟ ํค ๋๋ฒ๊ทธ ์ ๋ณด
|
1749 |
print(f"Request to /index.html - Session data: {dict(session)}")
|
1750 |
print(f"Request to /index.html - Cookies: {request.cookies}")
|
1751 |
print(f"Request to /index.html - User authenticated: {current_user.is_authenticated}")
|
1752 |
|
1753 |
-
#
|
1754 |
-
|
1755 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1756 |
return redirect(url_for('login'))
|
1757 |
|
1758 |
-
print(f"Serving index.html for authenticated user: {
|
1759 |
# ์ธ์
์ํ ๋๋ฒ๊ทธ
|
1760 |
-
print(f"Session data: user_id={
|
1761 |
|
1762 |
# ์ธ์
๋ง๋ฃ๋ฅผ ์๋๋๋ก ์ ์งํ๊ธฐ ์ํด ์ฌ๊ธฐ์ ์ธ์
์ ๊ฐฑ์ ํ์ง ์์ต๋๋ค.
|
1763 |
# ์ฃผ์: ์ธ์
์ ์ฐ๊ธฐ(๋๋ session.modified=True)๋ Flask-Session์์ ๋ง๋ฃ์๊ฐ์ ์ฐ์ฅํ ์ ์์ต๋๋ค.
|
|
|
1516 |
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
|
1517 |
response.headers['Pragma'] = 'no-cache'
|
1518 |
response.headers['Expires'] = '0'
|
1519 |
+
|
1520 |
+
# Safari-specific cookie handling - ensure session cookie is properly set
|
1521 |
+
if 'Safari' in request.headers.get('User-Agent', ''):
|
1522 |
+
# Force session cookie to be set with explicit domain
|
1523 |
+
response.set_cookie('session', session.sid if hasattr(session, 'sid') else '',
|
1524 |
+
httponly=True, samesite='Lax', secure=request.is_secure)
|
1525 |
+
|
1526 |
return response
|
1527 |
else:
|
1528 |
error = 'Invalid username or password'
|
|
|
1750 |
|
1751 |
# ์ธ๋ฑ์ค HTML ์ง์ ์๋น (๋ก๊ทธ์ธ ํ์)
|
1752 |
@app.route('/index.html')
|
|
|
1753 |
def serve_index_html():
|
1754 |
# ์ธ์
๋ฐ ์ฟ ํค ๋๋ฒ๊ทธ ์ ๋ณด
|
1755 |
print(f"Request to /index.html - Session data: {dict(session)}")
|
1756 |
print(f"Request to /index.html - Cookies: {request.cookies}")
|
1757 |
print(f"Request to /index.html - User authenticated: {current_user.is_authenticated}")
|
1758 |
|
1759 |
+
# Manual session check instead of @login_required decorator
|
1760 |
+
user_id = session.get('user_id')
|
1761 |
+
username = session.get('username')
|
1762 |
+
|
1763 |
+
if not user_id or not username:
|
1764 |
+
print("No session data found, redirecting to login")
|
1765 |
+
return redirect(url_for('login'))
|
1766 |
+
|
1767 |
+
# Verify user exists
|
1768 |
+
user_found = False
|
1769 |
+
for stored_username, user_data in users.items():
|
1770 |
+
if str(user_data['id']) == str(user_id) and stored_username == username:
|
1771 |
+
user_found = True
|
1772 |
+
break
|
1773 |
+
|
1774 |
+
if not user_found:
|
1775 |
+
print(f"User not found: {username} (ID: {user_id}), redirecting to login")
|
1776 |
return redirect(url_for('login'))
|
1777 |
|
1778 |
+
print(f"Serving index.html for authenticated user: {username} (ID: {user_id})")
|
1779 |
# ์ธ์
์ํ ๋๋ฒ๊ทธ
|
1780 |
+
print(f"Session data: user_id={user_id}, username={username}, is_permanent={session.get('permanent', False)}")
|
1781 |
|
1782 |
# ์ธ์
๋ง๋ฃ๋ฅผ ์๋๋๋ก ์ ์งํ๊ธฐ ์ํด ์ฌ๊ธฐ์ ์ธ์
์ ๊ฐฑ์ ํ์ง ์์ต๋๋ค.
|
1783 |
# ์ฃผ์: ์ธ์
์ ์ฐ๊ธฐ(๋๋ session.modified=True)๋ Flask-Session์์ ๋ง๋ฃ์๊ฐ์ ์ฐ์ฅํ ์ ์์ต๋๋ค.
|