feat: implement centralized access token management for media downloads and user authentication
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
import { getCurrentAccessToken } from '../utils/auth';
|
||||
|
||||
/**
|
||||
* Fetches media with authentication and returns a blob URL.
|
||||
@@ -40,7 +41,8 @@ export const useAuthenticatedMediaUrl = (
|
||||
|
||||
const fetchMedia = async () => {
|
||||
try {
|
||||
const accessToken = mx.getAccessToken();
|
||||
// Always use current session's token to avoid stale tokens during account switches
|
||||
const accessToken = getCurrentAccessToken();
|
||||
let response = await fetch(src, {
|
||||
method: 'GET',
|
||||
headers: accessToken
|
||||
@@ -104,7 +106,8 @@ export const useAuthenticatedMediaFetch = () => {
|
||||
}
|
||||
|
||||
try {
|
||||
const accessToken = mx.getAccessToken();
|
||||
// Always use current session's token to avoid stale tokens during account switches
|
||||
const accessToken = getCurrentAccessToken();
|
||||
let response = await fetch(src, {
|
||||
method: 'GET',
|
||||
headers: accessToken
|
||||
|
||||
Reference in New Issue
Block a user