除了
uid
,成功登录后user
元素中的<firebase-auth>
对象有哪些属性?
如何展示整个对象以供查看? JSON.stringify(user)
会返回null
。
在以下代码中,user.uid
有效。但是,如何查看完整的user
对象(而不只是user.uid
- 请参阅第60行)?我尝试了JSON.stringify(user)
但没有任何作用。
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../../polymer/polymer.html">
<link rel="import" href="../firebase-auth.html">
<dom-module id="x-login">
<template>
<firebase-auth id="firebaseLogin" user="{{user}}" status-known="{{statusKnown}}" location="https://polymer-tests.firebaseio.com" provider="{{provider}}" on-error="errorHandler" on-user-created="userSuccessHandler" on-password-changed="userSuccessHandler" on-password-reset="userSuccessHandler" on-user-removed="userSuccessHandler"></firebase-auth>
Firebase location:
<input value="https://polymer-tests.firebaseio.com" size="40" disabled>
<br>
Provider type:
<select value="{{provider::change}}">
<option>anonymous</option>
<option>facebook</option>
<option>github</option>
<option>google</option>
<option>twitter</option>
<option>password</option>
</select>
<em>Only 'anonymous', 'google', and 'password' are activated for demo Firebase account</em>
<br>
Login params (JSON):
<input value="{{params::input}}" id="params">
<em>Required by some provider types</em>
<br>
<div hidden$="{{computePasswordHidden(provider)}}">
<br><em>Password-specific options:</em><br>
<input placeholder="email" value="{{email::input}}">
<input placeholder="password" value="{{password::input}}">
<button on-tap="createUserHandler" disabled$="{{computeCreateUserDisabled(email, password)}}">Create user</button>
<br>
<input placeholder="new password" value="{{newPassword::input}}">
<button on-tap="changePasswordHandler" disabled$="{{computeChangePasswordDisabled(email, password, newPassword)}}">Change password</button>
<br>
<button on-tap="resetPasswordHandler" disabled$="{{computeResetPasswordDisabled(email, password)}}">Reset password</button>
<button on-tap="removeUserHandler" disabled$="{{computeRemoveUserDisabled(email, password)}}">Remove user</button>
</div>
<br>
<div id="message">[[message]]</div>
<br>
<button on-tap="login" hidden$="{{computeLoginHidden(statusKnown, user)}}">Login</button>
<button on-tap="logout" hidden$="{{computeLogoutHidden(statusKnown, user)}}">Logout</button>
<h3>Login status:</h3>
<p>{{computeLoginStatus(statusKnown, user)}}</p>
<h3>User ID:</h3>
<pre>{{user.uid}}</pre>
</template>
</dom-module>
<script>
Polymer({
is: 'x-login',
properties: {
provider: {
type: String,
value: 'anonymous'
},
message: {
type: String,
value: ''
},
email: {
type: String,
value: ''
},
password: {
type: String,
value: ''
},
user: {
type: Object,
value: null
},
statusKnown: {
type: Boolean
}
},
login: function() {
var params;
try {
params = JSON.parse(this.params);
} catch (e) {
params = null;
}
if (this.provider == 'password') {
params = params || {};
params.email = this.email;
params.password = this.password;
}
this.$.firebaseLogin.login(params);
},
logout: function() {
this.$.firebaseLogin.logout();
},
errorHandler: function(e) {
this.message = 'Error: ' + e.detail.message;
},
userSuccessHandler: function(e) {
this.message = e.type + ' success!';
},
createUserHandler: function(e) {
this.$.firebaseLogin.createUser(this.email, this.password);
},
changePasswordHandler: function(e) {
this.$.firebaseLogin.changePassword(this.email, this.password, this.newPassword);
},
resetPasswordHandler: function(e) {
this.$.firebaseLogin.sendPasswordResetEmail(this.email);
},
computePasswordHidden: function(provider) {
return provider !== 'password';
},
computeCreateUserDisabled: function(email, password) {
return !email || !password;
},
computeChangePasswordDisabled: function(email, password, newPassword) {
return !email || !password || !newPassword;
},
computeResetPasswordDisabled: function(email, password) {
return !email || !password;
},
computeRemoveUserDisabled: function(email, password) {
return !email || !password;
},
computeLoginHidden: function(statusKnown, user) {
return !statusKnown || !!user;
},
computeLogoutHidden: function(statusKnown, user) {
return !statusKnown || !user;
},
computeLoginStatus: function(statusKnown, user) {
if (statusKnown && user) {
return 'Logged in';
}
if (statusKnown) {
return 'Logged out';
}
return 'Unknown (checking status...)';
}
});
</script>
答案 0 :(得分:0)
这取决于提供者。
authData
object:user
(root){
uid: "string",
provider: "string",
token: "string",
auth: {},
expires: "number",
google: {
id: "string",
accessToken: "string",
displayName: "string",
email: "string",
profileImageURL: "string",
cachedUserProfile: "string",
}
}