feat: implement centralized access token management for media downloads and user authentication
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user