| import json | |
| import os | |
| from datetime import datetime | |
| def save_session(user_id: str, session_file: str = "session.json"): | |
| """ | |
| Save the current user session to a file. | |
| Args: | |
| user_id: The ID of the authenticated user. | |
| session_file: The path to the session file. | |
| """ | |
| try: | |
| session_data = { | |
| "user_id": user_id, | |
| "last_login": datetime.now().isoformat() | |
| } | |
| with open(session_file, 'w') as f: | |
| json.dump(session_data, f, indent=2) | |
| except Exception as e: | |
| print(f"Error saving session: {e}") | |