Spaces:
Running
Running
sunheycho
commited on
Commit
ยท
157125d
1
Parent(s):
f7e6892
Force session cookie persistence for login
Browse files- Added explicit session save using session_interface
- Enhanced session debugging to track data persistence
- Removed Safari-specific cookie handling that may interfere
- Force session save before redirect to ensure data persists
api.py
CHANGED
@@ -1503,7 +1503,12 @@ def login():
|
|
1503 |
session.permanent = True
|
1504 |
session.modified = True # ์ธ์
๋ณ๊ฒฝ ์ฌํญ ์ฆ์ ์ ์ฉ
|
1505 |
|
|
|
1506 |
print(f"Login successful for user: {username}, ID: {user.id}")
|
|
|
|
|
|
|
|
|
1507 |
|
1508 |
# ๋ฆฌ๋๋ ์
์ฒ๋ฆฌ
|
1509 |
next_page = request.args.get('next')
|
@@ -1511,18 +1516,20 @@ def login():
|
|
1511 |
print(f"Redirecting to: {next_page}")
|
1512 |
return redirect(next_page)
|
1513 |
print("Redirecting to index.html")
|
|
|
|
|
1514 |
response = make_response(redirect(url_for('serve_index_html')))
|
|
|
|
|
|
|
|
|
|
|
|
|
1515 |
# Set additional headers for HF Spaces compatibility
|
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'
|
|
|
1503 |
session.permanent = True
|
1504 |
session.modified = True # ์ธ์
๋ณ๊ฒฝ ์ฌํญ ์ฆ์ ์ ์ฉ
|
1505 |
|
1506 |
+
# Debug session data after setting
|
1507 |
print(f"Login successful for user: {username}, ID: {user.id}")
|
1508 |
+
print(f"Session data after login: {dict(session)}")
|
1509 |
+
|
1510 |
+
# Force session save by accessing it
|
1511 |
+
_ = session.get('user_id')
|
1512 |
|
1513 |
# ๋ฆฌ๋๋ ์
์ฒ๋ฆฌ
|
1514 |
next_page = request.args.get('next')
|
|
|
1516 |
print(f"Redirecting to: {next_page}")
|
1517 |
return redirect(next_page)
|
1518 |
print("Redirecting to index.html")
|
1519 |
+
|
1520 |
+
# Create response with session cookie explicitly set
|
1521 |
response = make_response(redirect(url_for('serve_index_html')))
|
1522 |
+
|
1523 |
+
# Force session cookie to be set for all browsers
|
1524 |
+
from flask import current_app
|
1525 |
+
session_interface = current_app.session_interface
|
1526 |
+
session_interface.save_session(current_app, session, response)
|
1527 |
+
|
1528 |
# Set additional headers for HF Spaces compatibility
|
1529 |
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
|
1530 |
response.headers['Pragma'] = 'no-cache'
|
1531 |
response.headers['Expires'] = '0'
|
1532 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1533 |
return response
|
1534 |
else:
|
1535 |
error = 'Invalid username or password'
|