feat: implement centralized access token management for media downloads and user authentication

This commit is contained in:
2026-03-23 21:53:27 +11:00
parent f76fee23bf
commit 75a9b4ca1e
16 changed files with 183 additions and 54 deletions
+10
View File
@@ -279,6 +279,11 @@ export const initClient = async (session: Session): Promise<MatrixClient> => {
// Setup handler to detect and auto-fix one-time key conflicts
setupKeyConflictHandler(mx, session);
// Register this as the global MatrixClient so auth utils can access the latest token
const { setGlobalMatrixClient } = await import('../app/utils/auth');
setGlobalMatrixClient(mx);
console.log('[initMatrix] Registered global MatrixClient for auth utils');
return mx;
} catch (error: any) {
// Handle crypto store account mismatch error
@@ -361,6 +366,11 @@ export const fixKeyConflict = async (mx: MatrixClient): Promise<void> => {
export const logoutClient = async (mx: MatrixClient) => {
mx.stopClient();
// Clear the global MatrixClient reference
const { setGlobalMatrixClient } = await import('../app/utils/auth');
setGlobalMatrixClient(null);
try {
await mx.logout();
} catch {