我有一个离子角度应用程序,我使用电子邮件身份验证。基本上,一旦用户登录,我将它们导航到我的标签页,然后在注销时我将它们导航回登录页面。一切都很好,最近我为我的收藏创建规则如下:
service cloud.firestore {
match /databases/{database}/documents {
match /applications/{document=**} {
allow read,write;
}
match /observations/{document=**} {
allow read,write;
}
match /users/{document=**} {
allow read,write
}
}
}
设置完这些规则后,当我点击FireStore - Missing or insufficient permissions
函数时,我发现此signOut()
错误,而我无法找到解决方法。
这是我的login.ts
文件
import { FetchData } from './../../services/fetchdata.service';
import { Observable } from 'rxjs/Observable';
import { LoaderService } from './../../services/loader.service';
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { TabsPage } from '../tabs/tabs';
import { AngularFireAuth } from 'angularfire2/auth';
import { NgZone } from '@angular/core';
@Component({
selector: 'page-login',
templateUrl: 'login.html'
})
export class LoginPage {
logSwitch: string;
user: object = {};
reguser: any = {};
loaderlogin: any;
alert: any;
authstate: Observable<any>;
topLoader: boolean = false;
emailVerified: boolean = false;
registeredname: string;
constructor(public navCtrl: NavController,
private afAuth: AngularFireAuth,
private loaderService: LoaderService,
private zone: NgZone,
private fetchData: FetchData) {
this.logSwitch = 'switchLog';
this._navigateUser();
}
_navigateUser() {
this.afAuth.auth.onAuthStateChanged((user) => {
if (user) { //&& user.emailVerified
this.emailVerified = false;
this.logSwitch = 'switchLog';
this.topLoader = false;
if (!user.emailVerified) {
user.sendEmailVerification();
}
if (user.displayName === null) {
user.updateProfile({
displayName: this.registeredname,
photoURL: null
}).then(() => {
}).catch((error) => {
console.log(error);
});
}
}
if (user && user.emailVerified) {
this.zone.run(() => {
this.navCtrl.setRoot(TabsPage);
});
}
})
}
loginUser(user: any) {
this.loaderlogin = this.loaderService.showLoader("Logging In!!");
this.afAuth.auth.signInWithEmailAndPassword(user.email, user.password)
.then((data) => {
this.loaderlogin = this.loaderService.dismissLoader();
this.fetchData.setLocalData(data);
if (!data.emailVerified) {
this.alert = this.loaderService.showAlert("Please verify your email to login!!");
}
}).catch((error) => {
this.loaderlogin = this.loaderService.dismissLoader();
if (error.code === "auth/user-not-found") {
this.alert = this.loaderService.showAlert("User does not exist!!");
} else if (error.code === "auth/wrong-password") {
this.alert = this.loaderService.showAlert("Wrong password!!");
}
console.log(error);
});
}
registerUser(regUser: any) {
this.loaderService.showLoader("Registering User!!");
this.registeredname = regUser.name;
this.afAuth.auth.createUserWithEmailAndPassword(regUser.email, regUser.password)
.then((data) => {
this.loaderlogin = this.loaderService.dismissLoader();
this.fetchData.createUser({ uid: data.uid, username: regUser.name, email: regUser.email });
this.alert = this.loaderService.showAlert("User successfully registered!");
this.emailVerified = true;
this.clearValues();
}).catch((error) => {
this.loaderlogin = this.loaderService.dismissLoader();
if (error.code === "auth/email-already-in-use") {
this.alert = this.loaderService.showAlert("User already registered. Please Sign In!");
}
})
}
clearValues() {
this.reguser.name = '';
this.reguser.email = '';
this.reguser.password = '';
this.reguser.confpassword = '';
}
}
这是我的logout.ts
文件
import { LoginPage } from './../login/login';
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AngularFireAuth } from 'angularfire2/auth';
import { LoaderService } from '../../services/loader.service';
import { App } from 'ionic-angular';
import { NgZone } from '@angular/core';
@Component({
selector: 'page-contact',
templateUrl: 'contact.html'
})
export class ContactPage {
alert: any;
username: string;
constructor(public navCtrl: NavController,
private afAuth: AngularFireAuth,
private loaderService: LoaderService,
public appCtrl: App,
private zone: NgZone) {
this.username = localStorage.username;
}
signOut() {
this.afAuth.auth.signOut().then((res) => {
this.zone.run(() => {
this.appCtrl.getRootNav().setRoot(LoginPage);
});
}).catch((error) => {
this.alert = this.loaderService.showAlert("Unable to logout. Try Again!");
})
}
}
提前致谢!!