I am trying to use Firebase authentication offline on my React-Native App. But I get:
auth/network-request-failed [auth/network-request-failed] A network error (such as timeout, interrupted connection or unreachable host) has occurred.
When I try this answer using Typescript: const initFirebase = firebase.initializeApp({persistence: true});
I get:
No overload matches this call.Overload 1 of 2, '(options: FirebaseAppOptions, config?: FirebaseAppConfig | undefined): Promise', gave the following error.Argument of type '{ persistence: boolean; }' is not assignable to parameter of type 'FirebaseAppOptions'.Type '{ persistence: boolean; }' is missing the following properties from type 'FirebaseAppOptions': appId, projectIdOverload 2 of 2, '(options: FirebaseAppOptions, name?: string | undefined): Promise', gave the following error.Argument of type '{ persistence: boolean; }' is not assignable to parameter of type 'FirebaseAppOptions'.
This is my signIn
method:
import firebase from '@react-native-firebase/app';import '@react-native-firebase/auth';const auth = firebase.auth();const signIn = async (email: string, pass: string, setUser: any) => { await auth .signInWithEmailAndPassword(email, pass) .then(userCredential => { var e = userCredential.user; setUser(e); }) .catch(error => { var errorCode = error.code; var errorMessage = error.message; console.log(errorCode, errorMessage); });};
How can I authenticate the user offline using Firebase in React-Native?
Note: online works fine. Code available here: https://gitlab.com/programandoconro/kanjiholic
UPDATE:
I avoided the later problem using:
const init = () => { firebase.initializeApp({ appId: '****AppID****', projectId: '***ProjectID***', persistence: true, });};
And called this function in my App.tsx
:
useEffect(() => { init(); }, []);
But still getting the unreachable host
problem.