Wednesday, November 29, 2023
HomeiOS DevelopmentMy createContext() wont work with @react-native-firebase/auth

My createContext() wont work with @react-native-firebase/auth


I created a useContext to entry my react-native-firebase/auth gloabally.

Im runnning the app utilizing expo run:ios I’ve carried out pod replace and no errors.

Non of the parts are working correctly anymore it was working high-quality when register however i do not know whats occurred.

My file tree for my AuthProvider is:

AuthProvider File Tree

and My App Screens are like this:

App Screens

I am utilizing expo-router and that is my bundle.json to my major element

"major": "expo-router/entry",

For Some cause my AuthProvider this error:

LOG: Consumer NOT SIGNED IN

I’ve applied this perform in my dashboard.js: ( i’ve imported useAuth() )

  const { consumer } = useAuth();
  const router = useRouter();

  useEffect(() => {
    if (!consumer) {
      console.log("Consumer NOT SIGNED IN");
      router.push("/(dwelling)/login"); // Redirect to login if no consumer
    } else {
      console.log("Consumer SIGNED IN: ", consumer.electronic mail);
    }
  }, [user, router]);

That is my Redirect.js:

import React from "react";
import { Redirect } from "expo-router";
import useAuth from "../src/hooks/useAuth";

const Index = () => {
  const { consumer } = useAuth();
  console.log("Consumer:", consumer);

  if (!consumer) {
    // If there is no consumer, redirect to login
    return <Redirect href="/(dwelling)/login" />;
  }

  // If there's a consumer, redirect to dashboard
  return <Redirect href="/(tabs)/dashboard" />;
};

export default Index;

My index.js:

import React from "react";
import { AuthProvider } from "../src/context/AuthProvider";
import RedirectComponent from "../parts/RedirectComponent";

const Index = () => {
  return (
    <AuthProvider>
      <RedirectComponent />
    </AuthProvider>
  );
};

export default Index;

That is my SignIn perform in my AuthServices.js:

 signIn: async (electronic mail, password) => {
    attempt {
      const response = await auth().signInWithEmailAndPassword(electronic mail, password);
      Alert.alert(electronic mail, "Has efficiently logged in!");
      return response.consumer; // Be sure this returns the consumer object
    } catch (error) {
      Alert.alert("Login Failed", error.message);
      throw error;
    }
  },

That is my _layout.js:

// ./app/(tabs)/_layout.js
import React from "react";
import AuthProvider from "../../src/context/AuthProvider";
import AppRoutes from "./(router)";

const Format = () => {
  return (
    <AuthProvider>
      <AppRoutes />
    </AuthProvider>
  );
};
export default Format;



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments