Fix auth persistence: web client session timeout + bot cache loss

Web client: trustDevice now defaults to true so a refresh token is always
issued on login, preventing deauth after the 1-hour access token expiry.
Users can still uncheck the box on shared devices.

Bot: cache file path is now env-configurable (BOT_CACHE_FILE) and
defaults to /app/cache/user_cache.pkl. Docker Compose mounts a named
volume at /app/cache so the session cache survives container restarts.
saveCache() now creates the directory if it doesn't exist.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-19 16:32:07 -06:00
parent 95ebae6766
commit 2951382c51
3 changed files with 6 additions and 2 deletions

View File

@@ -34,7 +34,7 @@ user_sessions = {}
login_state = {} login_state = {}
message_history = {} message_history = {}
user_cache = {} user_cache = {}
CACHE_FILE = "/app/user_cache.pkl" CACHE_FILE = os.getenv("BOT_CACHE_FILE", "/app/cache/user_cache.pkl")
intents = discord.Intents.default() intents = discord.Intents.default()
intents.message_content = True intents.message_content = True
@@ -227,6 +227,7 @@ def loadCache():
def saveCache(): def saveCache():
try: try:
os.makedirs(os.path.dirname(CACHE_FILE), exist_ok=True)
with open(CACHE_FILE, "wb") as f: with open(CACHE_FILE, "wb") as f:
pickle.dump(user_cache, f) pickle.dump(user_cache, f)
except Exception as e: except Exception as e:

View File

@@ -42,6 +42,8 @@ services:
depends_on: depends_on:
app: app:
condition: service_started condition: service_started
volumes:
- botcache:/app/cache
client: client:
build: build:
@@ -56,3 +58,4 @@ services:
volumes: volumes:
pgdata: pgdata:
botcache:

View File

@@ -9,7 +9,7 @@ export default function LoginPage() {
const [isLogin, setIsLogin] = useState(true); const [isLogin, setIsLogin] = useState(true);
const [username, setUsername] = useState(''); const [username, setUsername] = useState('');
const [password, setPassword] = useState(''); const [password, setPassword] = useState('');
const [trustDevice, setTrustDevice] = useState(false); const [trustDevice, setTrustDevice] = useState(true);
const [error, setError] = useState(''); const [error, setError] = useState('');
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const { login, register } = useAuth(); const { login, register } = useAuth();