Fix authenticated media loading for Tauri/WebKit environments
- Add useAuthenticatedMediaUrl hook that fetches media with auth headers - Add AuthenticatedMedia, AuthenticatedAvatarImage components - Update downloadMedia and downloadEncryptedMedia to accept access token - Update all media components to pass access token for auth media - Fix 401 errors on Matrix servers requiring authenticated media (v1.11+) This fixes media loading in Tauri desktop apps where service workers may not work reliably for cross-origin authenticated requests.
This commit is contained in:
1 parent
94f8466d1c
commit
54f5fa95a6
19 files changed
+330
-38
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import React, { ComponentProps, forwardRef } from 'react';
|
||||
import { AvatarImage } from 'folds';
|
||||
import { useAuthenticatedMediaUrl } from '../../hooks/useAuthenticatedMediaUrl';
|
||||
import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
|
||||
|
||||
export type AuthenticatedAvatarImageProps = ComponentProps<typeof AvatarImage>;
|
||||
|
||||
/**
|
||||
* AvatarImage component that handles Matrix authenticated media.
|
||||
* Automatically fetches authenticated media URLs with the proper Authorization header
|
||||
* and renders them as blob URLs.
|
||||
*/
|
||||
export const AuthenticatedAvatarImage = forwardRef<HTMLImageElement, AuthenticatedAvatarImageProps>(
|
||||
({ src, ...props }, ref) => {
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
const authenticatedSrc = useAuthenticatedMediaUrl(src, useAuthentication);
|
||||
|
||||
return <AvatarImage ref={ref} {...props} src={authenticatedSrc} />;
|
||||
}
|
||||
);
|
||||
|
||||
AuthenticatedAvatarImage.displayName = 'AuthenticatedAvatarImage';
|
||||
Reference in new issue
Block a user