Fix authorization tokens usage on android images

This commit is contained in:
Zoe Roux 2024-03-31 23:24:29 +02:00
parent 0008aa95c2
commit e16fdc1036
No known key found for this signature in database
2 changed files with 12 additions and 0 deletions

View File

@ -138,6 +138,11 @@ export const getTokenWJ = async (
export const getToken = async (): Promise<string | null> => (await getTokenWJ())[0];
export const getCurrentToken = () => {
const account = getCurrentAccount();
return account ? `${account.token.token_type} ${account.token.access_token}` : null;
};
export const useToken = () => {
const account = getCurrentAccount();
const refresher = useRef<NodeJS.Timeout | null>(null);

View File

@ -25,6 +25,7 @@ import { Blurhash } from "react-native-blurhash";
import { percent, useYoshiki } from "yoshiki/native";
import { Props, ImageLayout } from "./base-image";
import { Skeleton } from "../skeleton";
import { getCurrentToken } from "@kyoo/models";
export const Image = ({
src,
@ -60,6 +61,7 @@ export const Image = ({
}
quality ??= "high";
const token = getCurrentToken();
return (
<View {...css([layout, border], props)}>
{state !== "finished" && (
@ -72,6 +74,11 @@ export const Image = ({
<FastImage
source={{
uri: src[quality],
headers: token
? {
Authorization: token,
}
: {},
priority: FastImage.priority[quality === "medium" ? "normal" : quality],
}}
accessibilityLabel={alt}