我正在使用firebaseui-angular库在我的角度应用程序中进行身份验证。成功登录后,我正在尝试重定向用户,
众所周知的硬编码方式如下所示,
const firebaseUiAuthConfig: firebaseui.auth.Config = {
callbacks: {
signInSuccessWithAuthResult: function(authResult,redirectUrl) {
// User successfully signed in.
// Return type determines whether we continue the redirect automatically
// or whether we leave that to developer to handle.
console.log('Father Callback!');
return true;
}
},signInSuccessUrl: '/',signInFlow: 'popup',signInOptions: [
firebase.auth.GoogleAuthProvider.PROVIDER_ID,{
requireDisplayName: false,provider: firebase.auth.EmailAuthProvider.PROVIDER_ID
},firebaseui.auth.AnonymousAuthProvider.PROVIDER_ID
],tosUrl: '<your-tos-link>',privacyPolicyUrl: '<your-privacyPolicyUrl-link>',credentialHelper: firebaseui.auth.CredentialHelper.NONE
};
但这是硬编码的,可在登录后重定向到/
,而我希望用户在登录后登陆到所选页面,因此我试图按以下方式在组件中调用signInSuccessWithAuthResult
//HTML
<firebase-ui
(signInSuccessWithAuthResult)="successCallback($event)"
(signInFailure)="errorCallback($event)">
</firebase-ui>
//TS
returnUrl: string;
constructor(
public auth: AuthService,private router: Router,private route: activatedRoute,public afAuth: AngularFireAuth) {}
ngOnInit() {
this.route.queryParams.subscribe(
retUrl => {
this.returnUrl = retUrl.returnUrl || '/';
console.log("You are set to redirected to "+this.returnUrl);
}
);
this.afAuth.authState.subscribe(this.firebaseAuthchangelistener);
}
private firebaseAuthchangelistener(response) {
// if needed,do a redirect in here
if (response) {
console.log('Logged in :)');
} else {
console.log('Logged out :(');
}
}
successCallback(signInSuccessData: FirebaseUISignInSuccessWithAuthResult) {
console.log("Logged in! Redirecting to "+this.returnUrl);
this.router.navigateByUrl(this.returnUrl);
}
errorCallback(errordata: FirebaseUISignInFailure) {
console.log("Login failure!");
}
如here所述。但是,仅当从Google登录时才调用来自组件的(signInSuccessWithAuthResult)="successCallback($event)"
方法,而不是通过电子邮件或匿名登录!
我想念什么?
EDIT
Gmail登录与电子邮件和匿名登录之间的唯一区别是,Gmail打开了一个弹出窗口,其中那些可怜的匿名和电子邮件没有显示。