Hello, so I am running into an issue and I cannot understand what seems to be the problem.
I have integrated Firebase into my application and it is working great.
const App: React.FC = () => {
const [authValue, setAuthValue] = useState(false)
useEffect(() => {
onAuthStateChanged(auth, (currentUser) => {
if (currentUser) {
setAuthValue(true)
}
else {
setAuthValue(false)
}
});
}, []);
return (
<IonApp>
<IonReactRouter>
<Switch>
{authValue? <TabRoot /> : <LoginRoot />}
</Switch>
</IonReactRouter>
</IonApp>
)
};
export default App
As you can see above, I have set up two different route roots, one if a user is logged in (TabRoot) and another if a user is not (LoginRoot)
Using Firebase’s Auth State, when a user is logged in they have access to the TabRoot. Everything is working great on Web and IOS Simulator.
However, on my physical IOS device when I attempt to switch roots by logging in, nothing happens. The page remains stuck on the Login Page. See code below for the login page:
const Login: React.FC = () => {
const [loginEmail, SetLoginEmail] = useState("")
const [loginPassword, SetLoginPassword] = useState("")
const [error, SetError] = useState("")
const [signingIn, setSigningIn] = useState(false)
const history = useHistory()
function SignIn() {
if (error !== '') SetError('');
setSigningIn(true)
signInWithEmailAndPassword(auth, loginEmail, loginPassword)
.then((userCredential) => {
history.replace("../d.Home")
})
.catch((error) => {
setSigningIn(false)
SetError('Unable to sign in. Please try again.')
});
}
return (
<IonPage>
<IonHeader>
<IonToolbar>
<IonTitle className="notif--header--name">Login</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent>
<IonList>
<IonItem>
<IonLabel position="floating">Email</IonLabel>
<IonInput onIonChange={e => SetLoginEmail(e.detail.value!)} />
</IonItem>
<IonItem>
<IonLabel position="floating">Password</IonLabel>
<IonInput onIonChange={e => SetLoginPassword(e.detail.value!)} />
</IonItem>
</IonList>
<div className="error--text">
<ErrorText error={error} />
</div>
<a className="login--forgot--password" href='/forgotpasswordpage'>Forgot Password?</a>
<div className='page--container'>
<IonButton className="login--button page" onClick={SignIn} fill='clear'>Login</IonButton>
<div className='small--container page'>
<p>or</p>
<a className="login--button--small" href='/register'>Register</a>
</div>
</div>
</IonContent>
</IonPage>
);
};
export default Login
I am not sure why on the IOS physical device it does nothing. History.replace is working fine on web on the IOS simulator.
Please help me out if you have any ideas, thanks!