mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-02 21:24:20 -04:00
Fix account validity check on android
This commit is contained in:
parent
952beccafc
commit
af422e62e1
@ -19,12 +19,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { ConnectionErrorContext, useAccount } from "@kyoo/models";
|
import { ConnectionErrorContext, useAccount } from "@kyoo/models";
|
||||||
import { CircularProgress } from "@kyoo/primitives";
|
|
||||||
import { NavbarRight, NavbarTitle } from "@kyoo/ui";
|
import { NavbarRight, NavbarTitle } from "@kyoo/ui";
|
||||||
import { useNetInfo } from "@react-native-community/netinfo";
|
import { useNetInfo } from "@react-native-community/netinfo";
|
||||||
import { Redirect, Stack } from "expo-router";
|
import { Redirect, Stack } from "expo-router";
|
||||||
import * as SplashScreen from "expo-splash-screen";
|
import { useContext } from "react";
|
||||||
import { useContext, useEffect } from "react";
|
|
||||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||||
import { useTheme } from "yoshiki/native";
|
import { useTheme } from "yoshiki/native";
|
||||||
|
|
||||||
@ -33,14 +31,9 @@ export default function SignGuard() {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
// TODO: support guest accounts on mobile too.
|
// TODO: support guest accounts on mobile too.
|
||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
const { loading, error } = useContext(ConnectionErrorContext);
|
const { error } = useContext(ConnectionErrorContext);
|
||||||
const netInfo = useNetInfo();
|
const netInfo = useNetInfo();
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!loading) SplashScreen.hideAsync();
|
|
||||||
}, [loading]);
|
|
||||||
|
|
||||||
if (loading) return <CircularProgress />;
|
|
||||||
if (error && netInfo.isConnected) return <Redirect href={"/connection-error"} />;
|
if (error && netInfo.isConnected) return <Redirect href={"/connection-error"} />;
|
||||||
if (!account) return <Redirect href="/login" />;
|
if (!account) return <Redirect href="/login" />;
|
||||||
return (
|
return (
|
||||||
|
@ -36,7 +36,7 @@ import {
|
|||||||
Poppins_400Regular,
|
Poppins_400Regular,
|
||||||
Poppins_900Black,
|
Poppins_900Black,
|
||||||
} from "@expo-google-fonts/poppins";
|
} from "@expo-google-fonts/poppins";
|
||||||
import { ReactNode, useState } from "react";
|
import { ReactNode, useEffect, useState } from "react";
|
||||||
import { useColorScheme } from "react-native";
|
import { useColorScheme } from "react-native";
|
||||||
import { initReactI18next } from "react-i18next";
|
import { initReactI18next } from "react-i18next";
|
||||||
import { ThemeProvider as RNThemeProvider } from "@react-navigation/native";
|
import { ThemeProvider as RNThemeProvider } from "@react-navigation/native";
|
||||||
@ -117,6 +117,10 @@ export default function Root() {
|
|||||||
|
|
||||||
if (theme === "auto") theme = systemTheme ?? "light";
|
if (theme === "auto") theme = systemTheme ?? "light";
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (fontsLoaded) SplashScreen.hideAsync();
|
||||||
|
}, [fontsLoaded]);
|
||||||
|
|
||||||
if (!fontsLoaded) return null;
|
if (!fontsLoaded) return null;
|
||||||
return (
|
return (
|
||||||
<PersistQueryClientProvider
|
<PersistQueryClientProvider
|
||||||
|
@ -115,9 +115,3 @@ export const updateAccount = (id: string, account: Account) => {
|
|||||||
accounts[idx] = account;
|
accounts[idx] = account;
|
||||||
writeAccounts(accounts);
|
writeAccounts(accounts);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const unselectAllAccounts = () => {
|
|
||||||
const accounts = readAccounts();
|
|
||||||
for (const acc of accounts) acc.selected = false;
|
|
||||||
writeAccounts(accounts);
|
|
||||||
};
|
|
||||||
|
@ -136,7 +136,7 @@ export const AccountProvider = ({
|
|||||||
<AccountContext.Provider value={accounts}>
|
<AccountContext.Provider value={accounts}>
|
||||||
<ConnectionErrorContext.Provider
|
<ConnectionErrorContext.Provider
|
||||||
value={{
|
value={{
|
||||||
error: user.error,
|
error: selected ? user.error : null,
|
||||||
loading: user.isLoading,
|
loading: user.isLoading,
|
||||||
retry: () => {
|
retry: () => {
|
||||||
queryClient.invalidateQueries({ queryKey: ["auth", "me"] });
|
queryClient.invalidateQueries({ queryKey: ["auth", "me"] });
|
||||||
|
@ -26,7 +26,6 @@ import {
|
|||||||
addAccount,
|
addAccount,
|
||||||
getCurrentAccount,
|
getCurrentAccount,
|
||||||
removeAccounts,
|
removeAccounts,
|
||||||
unselectAllAccounts,
|
|
||||||
updateAccount,
|
updateAccount,
|
||||||
} from "./account-internal";
|
} from "./account-internal";
|
||||||
import { Platform } from "react-native";
|
import { Platform } from "react-native";
|
||||||
@ -38,7 +37,6 @@ type Result<A, B> =
|
|||||||
export const login = async (
|
export const login = async (
|
||||||
action: "register" | "login",
|
action: "register" | "login",
|
||||||
{ apiUrl, ...body }: { username: string; password: string; email?: string; apiUrl?: string },
|
{ apiUrl, ...body }: { username: string; password: string; email?: string; apiUrl?: string },
|
||||||
timeout?: number,
|
|
||||||
): Promise<Result<Account, string>> => {
|
): Promise<Result<Account, string>> => {
|
||||||
try {
|
try {
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
@ -117,7 +115,6 @@ export const getTokenWJ = async (account?: Account | null): ReturnType<typeof ru
|
|||||||
updateAccount(account.id, { ...account, token });
|
updateAccount(account.id, { ...account, token });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error refreshing token durring ssr:", e);
|
console.error("Error refreshing token durring ssr:", e);
|
||||||
if (Platform.OS !== "web" || typeof window !== "undefined") unselectAllAccounts();
|
|
||||||
return [null, null];
|
return [null, null];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ export const queryFn = async <Parser extends z.ZodTypeAny>(
|
|||||||
type?: Parser,
|
type?: Parser,
|
||||||
token?: string | null,
|
token?: string | null,
|
||||||
): Promise<z.infer<Parser>> => {
|
): Promise<z.infer<Parser>> => {
|
||||||
const url = context.apiUrl ?? (Platform.OS === "web" ? kyooUrl : getCurrentAccount()!.apiUrl);
|
const url = context.apiUrl ?? (Platform.OS === "web" ? kyooUrl : getCurrentAccount()?.apiUrl);
|
||||||
kyooApiUrl = url;
|
kyooApiUrl = url;
|
||||||
|
|
||||||
if (token === undefined && context.authenticated !== false) token = await getToken();
|
if (token === undefined && context.authenticated !== false) token = await getToken();
|
||||||
|
@ -26,6 +26,7 @@ import { useYoshiki } from "yoshiki/native";
|
|||||||
export const ErrorView = ({ error }: { error: KyooErrors }) => {
|
export const ErrorView = ({ error }: { error: KyooErrors }) => {
|
||||||
const { css } = useYoshiki();
|
const { css } = useYoshiki();
|
||||||
|
|
||||||
|
console.log(error)
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
{...css({
|
{...css({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user