2
import { StyleSheet, Text, View } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import LoginScreen from "./screens/LoginScreen";
import SignUpScreen from "./screens/SignUpScreen";
import WelcomeScreen from "./screens/WelcomeScreen";
import OnBoard from "./screens/Onboard";
import GetStarted from "./screens/GetStarted";
import { auth } from "./firebase";

const Stack = createNativeStackNavigator();

export default function App() {
  useEffect(() => {
    const unsubscribe = auth.onAuthStateChanged((user) => {
      console.log(user);
      return user;
    });
    return unsubscribe;
  }, []);

  return (
    <NavigationContainer>
      <Stack.Navigator>
        {user ? (
          <>
            <Stack.Screen
              options={{ headerShown: false }}
              name="OnBoard"
              component={OnBoard}
            />
            <Stack.Screen
              options={{ headerShown: false }}
              name="SignUp"
              component={SignUpScreen}
            />
            <Stack.Screen
              options={{ headerShown: false }}
              name="Login"
              component={LoginScreen}
            />
          </>
        ) : (
          <Stack.Screen
            options={{ headerShown: false }}
            name="Welcome"
            component={WelcomeScreen}
          />
        )}
      </Stack.Navigator>
    </NavigationContainer>
  );
}

can't find variable :user, I can't understand also I am new to react-native and react-navigation. I tried returning user but unlined or something.

tried

const isLoggedIn = user;
console.log(isLoggedIn)

It just logs undefined. Anyone can help me with it?

I am using firebase auth and the latest SDK, expo SDK 42, react navigation 6.x.x Using condition rendering for the to hide the onBoarding, logIn and signUp screen when the app loads and the user is authenticated so he directly does to welcomeScreen

Link to the expo snack. Run it in your device not on the web. https://snack.expo.dev/@bishalsaha/a638cf

BISHAL SAHA
  • 159
  • 11

1 Answers1

0

It seems that you are trying to use the 'firebase' package for web and node instead the RN one. (even you also have the RN ones in your package.json)

Try to follow these instructions: https://rnfirebase.io/auth/usage#listening-to-authentication-state

zelda11
  • 425
  • 2
  • 7
  • Tried that to but this error comes `TypeError: (0, _auth.getAuth) is not a function. (In '(0, _auth.getAuth)()', '(0, _auth.getAuth)' is undefined)` – BISHAL SAHA Oct 17 '21 at 14:50
  • Also this error `Invariant Violation: Native module cannot be null. at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException at node_modules/react-native/Libraries/Core/ExceptionsManager.js:171:19 in handleException at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError at node_modules/expo-error-recovery/build/ErrorRecovery.fx.js:12:21 in ErrorUtils.setGlobalHandler$argument_0` – BISHAL SAHA Oct 17 '21 at 14:53