mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-30 19:54:16 -04:00
Fix token refresh resseting the player (#461)
This commit is contained in:
parent
997cc054d4
commit
e9c5e5e627
@ -141,14 +141,20 @@ export const AccountProvider = ({
|
|||||||
}, [selected, user]);
|
}, [selected, user]);
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const oldSelectedToken = useRef<string | undefined>(selected?.token.access_token);
|
const oldSelected = useRef<{ id: string; token: string } | null>(
|
||||||
|
selected ? { id: selected.id, token: selected.token.access_token } : null,
|
||||||
|
);
|
||||||
|
const userIsError = user.isError;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// if the user change account (or connect/disconnect), reset query cache.
|
// if the user change account (or connect/disconnect), reset query cache.
|
||||||
if (selected?.token.access_token !== oldSelectedToken.current) {
|
if (
|
||||||
|
selected?.id != oldSelected.current?.id ||
|
||||||
|
(userIsError && selected?.token.access_token !== oldSelected.current?.token)
|
||||||
|
) {
|
||||||
initialSsrError.current = undefined;
|
initialSsrError.current = undefined;
|
||||||
queryClient.resetQueries();
|
queryClient.resetQueries();
|
||||||
}
|
}
|
||||||
oldSelectedToken.current = selected?.token.access_token;
|
oldSelected.current = selected ? { id: selected.id, token: selected.token.access_token } : null;
|
||||||
|
|
||||||
// update cookies for ssr (needs to contains token, theme, language...)
|
// update cookies for ssr (needs to contains token, theme, language...)
|
||||||
if (Platform.OS === "web") {
|
if (Platform.OS === "web") {
|
||||||
@ -156,7 +162,7 @@ export const AccountProvider = ({
|
|||||||
// cookie used for images and videos since we can't add Authorization headers in img or video tags.
|
// cookie used for images and videos since we can't add Authorization headers in img or video tags.
|
||||||
setCookie("X-Bearer", selected?.token.access_token);
|
setCookie("X-Bearer", selected?.token.access_token);
|
||||||
}
|
}
|
||||||
}, [selected, queryClient]);
|
}, [selected, queryClient, userIsError]);
|
||||||
|
|
||||||
const [permissionError, setPermissionError] = useState<KyooErrors | null>(null);
|
const [permissionError, setPermissionError] = useState<KyooErrors | null>(null);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user