Мой ответ не связан с angular, но я немного искал, чтобы узнать, как это сделать, используя Polymer и Polymerfire, поэтому я добавляю этот ответ, чтобы помочь людям сделать это быстрее, чем я.
Мне пришлось добавить отдельный узел в db, как упомянул Франк ван Пуффелен.
Импорт:
<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/polymerfire/firebase-document.html">
Затем поместите в любое место вашего приложения <firebase-app>
компонент:
<firebase-app
name="yourAppName"
api-key= "{{yourApi}}"
auth-domain= "{{yourAuthDomain}}"
database-url= "{{yourDbUrl}}"
>
</firebase-app>
После этого вам нужно будет использовать <firebase-auth>
и ‹firebase-document>
:
Шаблон :
<firebase-auth
id="auth"
app-name="yourAppName"
signed-in="{{signedIn}}"
user="{{user}}">
</firebase-auth>
<firebase-document
id="document"
app-name="yourAppName"
path="{{usersPath}}" // e.g "/users"
data="{{userDocument}}">
</firebase-document>
Сценарий:
this._register = function(){
var formValid = this.querySelector('#register-form').validate();
var auth = this.querySelector('#auth');
if(formValid && this.passWordsIdentic){
//The actual registration
auth.createUserWithEmailAndPassword(this.email, this.password).then(function(user){
console.log('auth user registration succes');
//Example values
this.userDocument.uid = user.uid;
this.userDocument.email = user.email;
this.userDocument.firstName = this.firstName;
this.userDocument.lastName = this.lastName;
this.userDocument.userName = this.userName;
this.$.document.save(this.usersPath).then(() => {
console.log("custom user registration succes");
this.$.document.reset();
});
}.bind(this)).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
console.log('error: ', errorCode);
);
}
}
Вот и все, вы можете взглянуть на этот отличный google codelab, который является хорошим введением в использование firebase с полимером.
person
Olivier Krull
schedule
22.09.2016