Reputation: 27
I have enabledPersistence() as indicated in the documentation on my app.ts.
import { AngularFirestoreModule } from '@angular/fire/firestore';
imports: [ AngularFirestoreModule.enablePersistence()]
Once i login and disconnect my network the application works well in offline mode and it uodates when network is reconnected.
My login function is:
async login() {
await this.presentLoadings();
const { email, password } = this
try {
const res = await this.afAuth.auth.signInWithEmailAndPassword(email , password)
if(res.user) {
this.user.setUser({
email,
password,
uid: res.user.uid
})
this.router.navigate(['/tabs/dashboard'])
}
} catch(err) {
this.presentToast(err.message);
}
finally
{
this.loading.dismiss();
}
}
Upvotes: 0
Views: 339
Reputation: 598857
There is no way to sign in a new user without an internet connection.
That said, if the user was signed in before, Firebase Authentication will restore their authentication state automatically when the app is restarted, and that will work when there is no network connection.
To detect this automatic sign-in, use an onAuthStateChange
listener:
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in, so set the state, and navigate to the dashboard.
} else {
// No user is signed in.
}
});
Upvotes: 1