aboutsummaryrefslogtreecommitdiffstats
path: root/packages/mobile/app/dashboard.tsx
blob: 8be57615139421867e73f9b79dafd3df2b51fe1c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { useRouter } from "expo-router";
import { useEffect } from "react";
import { Text, View } from "react-native";

import Logo from "@/components/Logo";
import { Button } from "@/components/ui/Button";
import useAppSettings from "@/lib/settings";
import { api } from "@/lib/trpc";

export default function Main() {
  const router = useRouter();
  const { settings, setSettings, isLoading } = useAppSettings();

  useEffect(() => {
    if (!isLoading && !settings.apiKey) {
      router.replace("signin");
    }
  }, [settings, isLoading]);

  const onLogout = () => {
    setSettings({ ...settings, apiKey: undefined });
  };

  const { data } = api.users.whoami.useQuery();

  return (
    <View className="flex h-full items-center justify-center gap-4 px-4">
      <Logo />
      <Text className="justify-center">
        Logged in as: {isLoading ? "Loading ..." : data?.email}
      </Text>
      <Button label="Log Out" onPress={onLogout} />
    </View>
  );
}