Skip to content

Commit 1854a0e

Browse files
committed
Refactor token file path handling to use platformdirs for improved cross-platform compatibility
1 parent 144ddf7 commit 1854a0e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/fiscalberry/common/token_manager.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import os
22
import requests
33
import json
4+
import platformdirs
45

5-
FILENAME = "jwt_token.json"
6-
if os.name == 'nt': # Windows
7-
TOKEN_FILE = os.path.join(os.getenv('APPDATA', tempfile.gettempdir()), FILENAME)
8-
elif os.name == 'posix': # Linux, macOS, or Android
9-
if "ANDROID_STORAGE" in os.environ: # Android
10-
TOKEN_FILE = os.path.join(os.getenv('TMPDIR', "/data/local/tmp"), FILENAME)
11-
else: # Linux or macOS
12-
TOKEN_FILE = os.path.join(os.getenv('XDG_CONFIG_HOME', os.path.expanduser("~/.config")), FILENAME)
13-
else:
14-
TOKEN_FILE = os.path.join(tempfile.gettempdir(), FILENAME)
6+
# Define your app name and author for proper directory structure
7+
APP_NAME = "fiscalberry"
8+
APP_AUTHOR = "fiscalberry"
9+
10+
# Use platformdirs to get the correct config directory
11+
TOKEN_FILE = os.path.join(platformdirs.user_config_dir(APP_NAME, APP_AUTHOR), "fiscalberry_jwt_token.json")
12+
13+
# Ensure the directory exists
14+
os.makedirs(os.path.dirname(TOKEN_FILE), exist_ok=True)
1515

1616
def do_login(username, password):
1717
"""Autentica al usuario contra el backend y guarda el token JWT."""

0 commit comments

Comments
 (0)