eletrotupi / tcc/ frontend/app/index.tsxee13593e49f8dd33700f17862fb841e7660653ce
611 B | 26 lines Raw
1
import { Redirect } 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 = "/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
}