如何更新NodeJS中Firebase身份验证的电话号码?

时间:2018-05-08 04:21:25

标签: node.js firebase firebase-authentication

我已经实施了Firebase电话身份验证以验证我的项目中的电话号码,但我的问题是如何在auth上更新手机号码。就像用户使用电话号码A登录并且该用户丢失了他的电话号码一样,因此用户需要将电话号码A更新为B.可以从认证或其他任何方式替换电话号码?< / p>

这就是我所做的......基于以下答案。

router.post('/replacenumber', function (req, res) {
    var user_id = 'y7BpNKRdGasd12lIYOsUsg13QZRx1'; //this is the uid of the user
    var phone = '+639507382841'; //this is the 2nd mobile number
    admin.auth().updateUser(user_id, {
              phoneNumber: phone,
    }).then(function(userRecord) {
       // See the UserRecord reference doc for the contents of userRecord.
       console.log(userRecord.toJSON());
       //console.log("Successfully updated user", userRecord.toJSON());
       //callback(userRecord.toJSON());
       console.log(user_id);
    }).catch(function(error) {
       var errorMessage = error.message;
          //console.log("Error updating user:", error);
       console.log(null, errorMessage);
    });
})

1 个答案:

答案 0 :(得分:2)

  

如果您正在使用nodejs在model.js文件上调用此函数,请尝试此操作

  def create
    user = User.find_by(email: params[:session][:email].downcase)
    if user && user.authenticate(params[:session][:password])
      unless user.deleted_at.nil?
        my_user_login_method
        redirect_to user # or redirect to a dashboard/landing page/whatever
      else
        render 'reactivate' # this would be a view for your reactivation page
      end
    else
      flash.now[:danger] = 'Invalid email/password combination'
      render 'new'
    end
  end