Javascript 如何在firestore离线时登录
如我的app.ts上的文档所示,我已启用持久性()Javascript 如何在firestore离线时登录,javascript,angular,ionic-framework,google-cloud-firestore,firebase-authentication,Javascript,Angular,Ionic Framework,Google Cloud Firestore,Firebase Authentication,如我的app.ts上的文档所示,我已启用持久性() import { AngularFirestoreModule } from '@angular/fire/firestore'; imports: [ AngularFirestoreModule.enablePersistence()] 一旦我登录并断开网络连接,应用程序就可以在脱机模式下正常工作,并在网络重新连接时停止运行 我的登录功能是: async login() { await this.presentL
import { AngularFirestoreModule } from '@angular/fire/firestore';
imports: [ AngularFirestoreModule.enablePersistence()]
一旦我登录并断开网络连接,应用程序就可以在脱机模式下正常工作,并在网络重新连接时停止运行
我的登录功能是:
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();
}
}
没有internet连接,无法登录新用户 这就是说,如果用户之前已登录,Firebase身份验证将在应用程序重新启动时自动恢复其身份验证状态,并且在没有网络连接的情况下,这将起作用 要检测此自动登录,请执行以下操作:
非常感谢你
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.
}
});