【问题标题】:Password reset: First argument "email" must be a valid string密码重置:第一个参数“电子邮件”必须是有效字符串
【发布时间】:2018-03-04 02:49:38
【问题描述】:

我正在尝试向用户的电子邮件发送密码重置链接,并收到此问题标题中的错误。

这是我的 resetpassword.ts 文件

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { AngularFireAuth } from "angularfire2/auth";
import { User } from "../../models/user";

/**
 * Generated class for the ResetpasswordPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-resetpassword',
  templateUrl: 'resetpassword.html',
  providers: [AngularFireAuth]
})
export class ResetpasswordPage {
  resetMsg: string="Reset"
  user = {} as User

  constructor(private afauth: AngularFireAuth, public navCtrl: 
NavController, public navParams: NavParams) {
  }

  async reset(user: User) {
    try{
      const result = 
this.afauth.auth.sendPasswordResetEmail(this.user.email);
      if(result) {
        console.log(result);
      }
    }
    catch(e) {
      console.error(e);
    }

}
}

这是models文件夹中user.ts文件中的代码:

export interface User {

    email: string;
    password: string;

}

下面这段代码是html文件的一部分:

<ion-item>
     <ion-label color="primary" floating>Email</ion-label>
     <ion-input type="email" [(ngModel)]="user.email"></ion-input>
    </ion-item>
      <button class="reset" (click)="reset(user)" ion-button round medium icon-end color="primary">
        {{ resetMsg }}
        <ion-icon name="arrow-forward"></ion-icon>
      </button>

创建用户,登录一切正常但无法发送重置密码邮件。请帮忙!谢谢。

【问题讨论】:

  • console.log(this.user.email) 输出什么?
  • 代码:“auth/argument-error”,消息:“sendPasswordResetEmail 失败:第一个参数“email”必须是有效字符串。”是它作为输出抛出的内容。不知道为什么电子邮件不被视为有效字符串
  • 如果您在控制台日志中收到正确的电子邮件,请尝试类似this.user.email.toString 或将其包装为字符串。
  • 我不是在问你遇到了什么错误,我想知道你是否确实在发送一个字符串。 :-) 为此,我想知道console.log(this.user.email) 在控制台中输出什么。将该行放在try 的顶部。
  • @camden_kid 当我在“try”之前输入您提供的代码时,控制台中的输出是 testaccount@gmail.com,这是我正在使用的电子邮件,并且是此 Ionic 应用程序中的注册帐户。

标签: html typescript firebase ionic-framework angularfire2


【解决方案1】:

不知道根本问题。但是我需要再次编译代码并在新实例中运行 ionic serve 命令才能解决问题。 @camden_kid 您的回答帮助我确认电子邮件是否实际上被视为字符串。谢谢!!!

【讨论】:

    猜你喜欢
    • 2018-03-23
    • 2020-09-24
    • 1970-01-01
    • 2019-02-26
    • 2018-08-29
    • 1970-01-01
    • 2021-02-10
    • 2018-04-06
    • 2020-04-21
    相关资源
    最近更新 更多