我是 Polymer 和 Firebase 的新手(也是一名程序员),我正在尝试使用 Google 进行简单的登录并显示用户已登录。在 Firebase 中启用了Google Auth 。没有用户登录时应该隐藏注销按钮,但是当我单击登录按钮时,什么也没有发生。浏览器的控制台中没有警告。这是我正在使用的代码:
<!DOCTYPE html>
<html>
<head>
<link rel="import" href="bower_components/polymerfire/firebase-app.html">
<link rel="import" href="bower_components/polymerfire/firebase-auth.html">
<link rel="import" href="bower_components/paper-button/paper-button.html">
</head>
<body>
<firebase-app
auth-domain="xxx"
database-url="xxxx"
api-key="xxxxx">
</firebase-app>
<firebase-auth
id="auth"
user="{{user}}"
status-known="{{statusKnown}}"
provider="google">
</firebase-auth>
<template is="dom-if" if="[[user]]">
<h1>Welcome [[user.displayName]]</h1>
</template>
<paper-button raised on-tap="login" hidden$="[[user]]">Sign In</paper-button>
<paper-button raised on-tap="logout" hidden$="[[!user]]">Sign Out</paper-button>
</body>
<script>
Polymer({
is: 'my-login',
properties: {
user: {
type: Object
},
statusKnown: {
type: Object
}
},
login: function() {
return this.$.auth.signInWithPopup();
},
logout: function() {
return this.$.auth.signOut();
},
});
</script>
</html>