Sherlock / components / authLoading.tsx
authLoading.tsx
Raw
import React from "react";
import { ActivityIndicator, View } from "react-native";
import { globalStyles } from "../constants/styles";
import { router, SplashScreen } from "expo-router";
import global from "../constants/global";
import { supabase } from "../components/supabase";
import { useAuth } from "./authContext";

export default class AuthLoadingScreen extends React.Component {
  // state = {
  //   userToken: null,
  // };
  async componentDidMount() {
    await this.loadApp();
    SplashScreen.hideAsync();
  }

  
  // Get the logged in users and remember them
  loadApp = async () => {
    const { data: { session }, error } = await supabase.auth.getSession();
    if (error) {
      console.log("Error getting session: ", error);
      throw new Error("Error getting user session.");
    }

    if(!global.link){
      if(session){
        router.replace("/(tabs)/(home)/home");
      }
      
    }
  };
  render() {
    return (
      <View style={[globalStyles.container, {maxHeight:0}]}>
        <ActivityIndicator size="large" color="#fff" />
      </View>
    );
  }
}