Angular Firebase第一个参数“email”必须是有效的字符串

时间:2017-10-11 17:53:44

标签: angular firebase authentication firebase-authentication

我的firebase注册组件遇到了一些麻烦。几天前工作顺利,但后来我决定休息几天(可怕的错误),现在我的注册表格不起作用,我收到了这个错误:

{code: "auth/argument-error", message: "signInWithEmailAndPassword failed: First argument "email" must be a valid string.", ngDebugContext: DebugContext_, ngErrorLogger: ƒ}

注册表格很大,所以我尽力让它尽可能短。

HTML:

<form [formGroup]="myForm" (ngSubmit)="onSignup()">
      <div formGroupName="emailPass" class="form-group">
           <md-input-container class="col-md-6 md-icon-left">
               <input formControlName="email" mdInput #email type="email" name="email" class="form-control" placeholder="Email">
           </md-input-container>
           <md-input-container class="col-md-6 md-icon-left no-margin-bottom">
               <input mdInput formControlName="password" type="password" class="form-control" id="password" name="password" placeholder="Contraseña">
           </md-input-container>
           <md-input-container class="col-md-6 md-icon-left no-margin-bottom">
               <input mdInput type="password" formControlName="confirmPassword" class="form-control" name="password" placeholder="Confirmar Contraseña">
           </md-input-container>
           <button type="submit" [disabled]="!myForm.get('emailPass').valid" md-raised-button color="primary">Siguiente</button>
      </div>
</form>

signup.component.ts

import { Component, OnInit } from "@angular/core";
import { FormBuilder, FormGroup, Validators, FormControl, AbstractControl } from "@angular/forms";
import { AuthService } from '../../services/auth.service';
import { RutValidator } from 'ng2-rut';
import { EmailValidator } from '../../shared/validators/email';
import { PasswordValidator } from "../../shared/validators/password-validator";
import { IsEqualPassword } from "../../shared/validators/equal-password";

@Component({
  selector: 'my-page-sign-up',
  styleUrls: ['./sign-up.component.scss'],
  templateUrl: './sign-up.component.html'
})

export class PageSignUpComponent implements OnInit {
    myForm: FormGroup;

    constructor(private fb: FormBuilder,
                private authService: AuthService,
                rv: RutValidator) {
                    this.myForm = this.fb.group({
                      emailPass: this.fb.group({
                        email: ['', Validators.compose([Validators.required,
                          EmailValidator.isValid])],
                        password: ['', Validators.compose([Validators.required, PasswordValidator])],
                        confirmPassword: ['', Validators.required]
                        }, { validator: IsEqualPassword }, 
                      ),
        });
       }

    onSignup() {
        this.authService.signupUser(this.myForm.value);
    }

    ngOnInit(): any {}   

}

auth.service.ts

import { Injectable } from '@angular/core';
import { User } from "./user";
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
import { Observable } from 'rxjs/Observable';
import { Router } from '@angular/router';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';

@Injectable()
export class AuthService {

    user: Observable<firebase.User>;

  constructor(private firebaseAuth: AngularFireAuth,
              private router: Router,
              private afdb: AngularFireDatabase) 
              {
    this.user = firebaseAuth.authState;
  };

  signupUser(user: User) {
    firebase.auth().createUserWithEmailAndPassword(user.email, user.password).catch(function(error) {
      // Handle Errors here.
      var errorMessage = error.message;
      // ...
    }).then(value => {
        console.log('Success!', value);
               let userDetails = {
            firstName: user.firstName,
            lastName: user.lastName,
            email: user.email,
        }
        this.afdb.list('users').update(value.uid, userDetails);
        this.router.navigate(['/app/recibirpago']);
    })
    .catch(err => {
        console.log('Something went wrong:',err.message);
    });
  };

}

我想我得到了这些错误,因为最近更新了firebase模块,但在再次检查文档后,我找不到解决问题的方法。

感谢您的帮助!!

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。尝试将toString添加为:

   email: user.email.toString()

即使使用控制台或窗口警报进行调试也没有将其显示出来,因为我的电子邮件在那里显示。但是当我添加toString()时,它突然起作用了。