如何与多个提供商设置 AngularFire Auth?身份验证提供者的材质按钮?
有没有办法通过视图中的单个 Login
按钮和组件中的单个 login()
函数来设置多个提供程序的 AngularFire Auth?或者我是否在视图中设置单独的按钮,并在组件中设置单独的 loginGoogle()
、loginFacebook()
、loginTwitter()
等函数对于每个提供商?
这有效:
login() {
this.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider())
.then((result) => {
this.loggedIn = true;
console.log("Logged in!");
console.log(result);
this.userFullName = result.user?.displayName;
this.userPhotoUrl = result.user?.photoURL;
this.router.navigate(['/', 'home']);
})
.catch((error) => {
console.error(error);
});
}
这不起作用:
login() {
this.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider()) // √
this.auth.signInWithPopup(new firebase.auth.TwitterAuthProvider()) // √
this.auth.signInWithPopup(new firebase.auth.GithubAuthProvider()) // √
this.auth.signInWithPopup(new firebase.auth.FacebookAuthProvider()) // "Facebook Login is currently unavailable for this app."
this.auth.signInWithPopup(new firebase.auth.EmailAuthProvider()) // "FirebaseError: Firebase: Error (auth/argument-error)."
this.auth.signInWithPopup(new firebase.auth.PhoneAuthProvider()) // "FirebaseError: Firebase: Error (auth/argument-error)."
this.auth.signInWithPopup(new firebase.auth.YahooAuthProvider()) // Property 'YahooAuthProvider' does not exist on type 'typeof auth'.
this.auth.signInWithPopup(new firebase.auth.MicrosoftAuthProvider()) // Property 'MicrosoftAuthProvider' does not exist on type 'typeof auth'.
.then((result) => {
this.loggedIn = true;
console.log("Logged in!");
console.log(result);
this.userFullName = result.user?.displayName;
this.userPhotoUrl = result.user?.photoURL;
this.router.navigate(['/', 'home']);
})
.catch((error) => {
console.error(error);
});
}
以下内容应该有效,但代码很多。我问有没有更干燥的方法。 HTML 将有一个用于 loginGoogle()
的按钮、一个用于 loginFacebook()
的按钮、一个用于 loginTwitter()
的按钮,等等。
loginGoogle() {
this.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider())
.then((result) => {
this.loggedIn = true;
console.log("Logged in!");
console.log(result);
this.userFullName = result.user?.displayName;
this.userPhotoUrl = result.user?.photoURL;
this.router.navigate(['/', 'home']);
})
.catch((error) => {
console.error(error);
});
}
loginFacebook() {
this.auth.signInWithPopup(new firebase.auth.FaceAuthProvider())
.then((result) => {
this.loggedIn = true;
console.log("Logged in!");
console.log(result);
this.userFullName = result.user?.displayName;
this.userPhotoUrl = result.user?.photoURL;
this.router.navigate(['/', 'home']);
})
.catch((error) => {
console.error(error);
});
}
loginTwitter() {
this.auth.signInWithPopup(new firebase.auth.TwitterAuthProvider())
.then((result) => {
this.loggedIn = true;
console.log("Logged in!");
console.log(result);
this.userFullName = result.user?.displayName;
this.userPhotoUrl = result.user?.photoURL;
this.router.navigate(['/', 'home']);
})
.catch((error) => {
console.error(error);
});
}
另外三个问题。
- 某处是否有用于身份验证提供者的 Angular Material 按钮集?我做了这个,但看起来不太好:
- 为什么
EmailAuthProvider()
和PhoneAuthProvider()
不起作用?错误消息是
FirebaseError: Firebase: Error (auth/argument-error).
- 为什么
YahooAuthProvider()
和MicrosoftAuthProvider()
不起作用?错误消息是:
Property 'YahooAuthProvider' does not exist on type 'typeof auth'.
AngularFire 不支持雅虎和微软吗?
Google、Twitter 和 GitHub 都可以使用(一次一个)。我的 Facebook 凭据似乎有问题,我会进行调查。这是我的 Firebase 控制台身份验证页面:
Is there a way to set up AngularFire Auth with multiple providers from a single Login
button in the view and a single login()
function in the component? Or do I set up separate buttons in the view and separate loginGoogle()
, loginFacebook()
, loginTwitter()
etc. functions in the component for each provider?
This works:
login() {
this.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider())
.then((result) => {
this.loggedIn = true;
console.log("Logged in!");
console.log(result);
this.userFullName = result.user?.displayName;
this.userPhotoUrl = result.user?.photoURL;
this.router.navigate(['/', 'home']);
})
.catch((error) => {
console.error(error);
});
}
This doesn't work:
login() {
this.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider()) // √
this.auth.signInWithPopup(new firebase.auth.TwitterAuthProvider()) // √
this.auth.signInWithPopup(new firebase.auth.GithubAuthProvider()) // √
this.auth.signInWithPopup(new firebase.auth.FacebookAuthProvider()) // "Facebook Login is currently unavailable for this app."
this.auth.signInWithPopup(new firebase.auth.EmailAuthProvider()) // "FirebaseError: Firebase: Error (auth/argument-error)."
this.auth.signInWithPopup(new firebase.auth.PhoneAuthProvider()) // "FirebaseError: Firebase: Error (auth/argument-error)."
this.auth.signInWithPopup(new firebase.auth.YahooAuthProvider()) // Property 'YahooAuthProvider' does not exist on type 'typeof auth'.
this.auth.signInWithPopup(new firebase.auth.MicrosoftAuthProvider()) // Property 'MicrosoftAuthProvider' does not exist on type 'typeof auth'.
.then((result) => {
this.loggedIn = true;
console.log("Logged in!");
console.log(result);
this.userFullName = result.user?.displayName;
this.userPhotoUrl = result.user?.photoURL;
this.router.navigate(['/', 'home']);
})
.catch((error) => {
console.error(error);
});
}
The following should work but is a lot of code. I'm asking if there's DRYer way. The HTML would have a button for loginGoogle()
, a button for loginFacebook()
, a button for loginTwitter()
, etc.
loginGoogle() {
this.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider())
.then((result) => {
this.loggedIn = true;
console.log("Logged in!");
console.log(result);
this.userFullName = result.user?.displayName;
this.userPhotoUrl = result.user?.photoURL;
this.router.navigate(['/', 'home']);
})
.catch((error) => {
console.error(error);
});
}
loginFacebook() {
this.auth.signInWithPopup(new firebase.auth.FaceAuthProvider())
.then((result) => {
this.loggedIn = true;
console.log("Logged in!");
console.log(result);
this.userFullName = result.user?.displayName;
this.userPhotoUrl = result.user?.photoURL;
this.router.navigate(['/', 'home']);
})
.catch((error) => {
console.error(error);
});
}
loginTwitter() {
this.auth.signInWithPopup(new firebase.auth.TwitterAuthProvider())
.then((result) => {
this.loggedIn = true;
console.log("Logged in!");
console.log(result);
this.userFullName = result.user?.displayName;
this.userPhotoUrl = result.user?.photoURL;
this.router.navigate(['/', 'home']);
})
.catch((error) => {
console.error(error);
});
}
Three more questions.
- Is there an Angular Material set of buttons for auth providers available somewhere? I made this but it doesn't look great:
- Why are
EmailAuthProvider()
andPhoneAuthProvider()
not working? The error message is
FirebaseError: Firebase: Error (auth/argument-error).
- Why are
YahooAuthProvider()
andMicrosoftAuthProvider()
not working? The error message is:
Property 'YahooAuthProvider' does not exist on type 'typeof auth'.
Does AngularFire not support Yahoo and Microsoft?
Google, Twitter, and GitHub all worked (one at a time). My Facebook credentials appear to have something wrong, I'll look into that. Here's my Firebase Console Auth page:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Google 仅为网页提供
.png
,不提供.svg
https://developers.google.com/identity/branding-guidelinesFacebook 提供了
index.html
代码,该代码为您提供了一个从互联网调用图形的类。我无法让代码正常工作,因此我截取了 Facebook 按钮的屏幕截图并将其转换为.png
。 https://developers.facebook.com/docs/facebook-login /web/login-button/Twitter 提供了
.png
。https://developer.twitter.com/en/ docs/authentication/guides/log-in-with-twitter
Github 提供了一个
.png
:https://blog.oauth.io/how-to -add-github-social-login-button/
我为按钮制作了一个下拉菜单。看起来没有我想要的那么好。我更喜欢使用
.svg
文件。控制器中的功能很简单。
Google provides
.png
only for web, no.svg
https://developers.google.com/identity/branding-guidelinesFacebook provides code for
index.html
that gives you a class that calls the graphic from the Internet. I couldn't get the code to work so I took a screenshot of the Facebook button and converted it to.png
. https://developers.facebook.com/docs/facebook-login/web/login-button/Twitter provides a
.png
.https://developer.twitter.com/en/docs/authentication/guides/log-in-with-twitter
Github provides a
.png
:https://blog.oauth.io/how-to-add-github-social-login-button/
I made a dropdown menu for the buttons. It doesn't look as good as I wanted. I'd prefer to use
.svg
files.The functions in the controller were easy.