脸书提供商没有使用angularfire对我的离子应用程序中的用户进行身份验证



我正在尝试在我的ionic应用程序中实现(社交和电子邮件密码(登录。。

它对电子邮件通行证很有效。当我尝试添加谷歌和脸书时,我遇到了很多问题,然后是一个非常脏的代码。现在我的代码适用于谷歌认证,但对于facebook,应用程序正在重定向,但返回的结果是{user:null},并且没有任何变化。

错误是什么?为什么facebook身份验证没有改变这个.afAuth.authState

功能在我的auth.service.ts文件中实现。

Facebook登录的功能如下:

loginWithFacebook() {
this.store.dispatch(new UIActions.StartLoading());
alert('facebook login');
try {
let provider = new auth.FacebookAuthProvider();
console.log(provider);
const credential = this.afAuth.auth.signInWithRedirect(provider);
console.log('accomplished sign in with redirect');
} catch (error) {
console.log(error);
alert(error);
}
}

使用谷歌登录(按预期工作(:

webGoogleLogin() {
try {
const provider = new firebase.auth.GoogleAuthProvider();
console.log(provider);
const credential = this.afAuth.auth.signInWithRedirect(provider);
console.log('accomplished sign in with redirect');
} catch (error) {
console.log(error);
alert(error);
}
}

我在initAthListener((中听取了身份验证更改,它是在应用程序初始化时启动的(它在电子邮件通行证登录-注销时按预期工作(:

initAuthListener() {
// this.store.dispatch(new UIActions.StartLoading());
this.afAuth.authState.subscribe(user => {
// if( user && !user.emailVerified) {
//   this.store.dispatch(new UIActions.StopLoading());
//   this.alertService.presentToast(this.translateService.instant("Auth.PLEASE_VALIDATE_YOUR_EMAIL_ADDRESS"), 3000);
// }
console.log(user);
alert(user);
if (user) {
if(user.emailVerified) {
this.isAuthenticated = true;
this.store.dispatch(new AuthActions.SetAuthenticated());
this.afStore.collection('profiles').doc<FullUserProfile>(user.uid).valueChanges().pipe(take(1)).subscribe(
(profile: FullUserProfile) => {
if (profile != null) {
this.store.dispatch(new AuthActions.SetUserProfile(profile));
// this.functionsGeneralDataService.initialize(profile);
this.generalDataService.initialize(profile);
this.store.dispatch(new UIActions.StopLoading());
// this.router.navigate(['/groups']);
this.goToMainPage();
} else {
return;
}
}
);
}
} else {
this.isAuthenticated = false;
this.generalDataService.unsubscribeFromAll();
this.store.dispatch(new AuthActions.SetUnauthenticated());
this.store.dispatch(new AuthActions.RemoveUserProfile());
this.store.dispatch(new GroupsActions.ClearState());
// this.router.navigate(['/login']);
}
this.store.dispatch(new UIActions.StopLoading());
});
// this.listenToRedirectResults();
}

我尝试在inmitAuthListener((的末尾添加以下功能,但没有解决问题:

listenToRedirectResults() {
firebase.auth().getRedirectResult().then((result) => {
console.log(result);
console.log(firebase.auth().currentUser);
alert("THIS IS RESULT");
this.store.dispatch(new UIActions.StartLoading());
if (result.credential) {
alert('result.credentials is not null');
var token = result.user.getIdToken();
var user = result.user;
// if(result == null || result.user == null) {
//   alert('result or user null');
//   this.isAuthenticated = false;
//   this.generalDataService.unsubscribeFromAll();
//   this.store.dispatch(new AuthActions.SetUnauthenticated());
//   this.store.dispatch(new AuthActions.RemoveUserProfile());
//   this.store.dispatch(new GroupsActions.ClearState());
// }
alert('will get data');
this.store.dispatch(new AuthActions.SetAuthenticated());
this.afStore.collection('profiles').doc(user.uid).valueChanges().pipe(take(1)).subscribe(
(profile: FullUserProfile) => {
this.store.dispatch(new UIActions.StartLoading());
this.isAuthenticated = true;
if (profile != null) {
this.store.dispatch(new AuthActions.SetUserProfile(profile));
// this.functionsGeneralDataService.initialize(profile);
this.generalDataService.initialize(profile);
this.store.dispatch(new UIActions.StopLoading());
this.goToMainPage();
} else {
let profile = {} as FullUserProfile;
profile.id = user.uid;
profile.email = user.email;
profile.name = user.displayName;
profile.image = { name: '', url: user.photoURL}
profile.type = 0;
profile.numberOfGroupsAllowed = 2;
this.afStore.collection('profiles').doc(user.uid).set(profile);
this.store.dispatch(new AuthActions.SetUserProfile(profile));
// this.functionsGeneralDataService.initialize(profile);
this.generalDataService.initialize(profile);
this.store.dispatch(new UIActions.StopLoading());
this.goToMainPage();
// this.router.navigate(['/groups']);
}
}
);
// this.router.navigate(['groups'])
} else {
alert('no creadential');
}
})
.catch(function(error) {
console.log(error.message);
this.store.dispatch(new UIActions.StopLoading());
this.alertService.presentToast(error.message);
});
}

注意:如果用户从firebase控制台的用户中删除,并试图登录facebook,那么用户会被添加到那里,但我的应用程序中没有更改。

很抱歉我的脏代码,在问这个问题之前我已经清理了很多。。昨天,在添加谷歌身份验证之前,脸书身份验证是有效的,但注销是无效的。

对不起,我是离子框架的新手。

错误:我正在检查是否为未验证电子邮件的facebook帐户验证了电子邮件。我已经重新构造了代码。

相关内容

最新更新