eletrotupi / tcc/ frontend/app/index.tsxde30833f4bea0b7563d9cabe9154e52407683e25
631 B | 26 lines Raw
1
import { Redirect, type Href } from "expo-router";
2
import { useAuth } from "@/context/AuthContext";
3
import { ActivityIndicator, View } from "react-native";
4

5
export default function Index() {
6
  const { isAuthenticated, isLoading, user } = useAuth();
7
  let url: Href = "/auth/login";
8

9
  if (isLoading) {
10
    return (
11
      <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
12
        <ActivityIndicator size="large" />
13
      </View>
14
    );
15
  }
16

17
  if (isAuthenticated) {
18
    if (user?.active) {
19
      url = "/(tabs)/new";
20
    } else {
21
      url = "/auth/activate";
22
    }
23
  }
24

25
  return <Redirect href={url} />;
26
}