java—如何使用typescript处理云函数(functions.https.httpserror)在客户端(android)中的错误

cetgtptt  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(197)

首先,我使用typescript编写云函数来创建具有firebase身份验证的帐户。创建新帐户后,尝试将自定义声明添加到帐户并将用户信息添加到firebase实时数据库这些步骤成功完成。
添加现有帐户时出现问题。这个错误打印在函数日志中,但我不能把它扔到android上
我的firebase云功能日志
云功能code:.

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import { User } from './model/User';

admin.initializeApp();

const db = admin.database();

exports.createSellerAccount = functions.https.onCall((data, context) => {
  const userEmail = data.email;
  const userPassword = data.password;
  const user: User = new User();
  const newUserData = JSON.parse(data.newUser);

  user.setFirstName(newUserData.firstName);
  user.setLastName(newUserData.lastName);
  user.setMobileNumber(newUserData.mobileNumber);

  admin.auth().createUser({
    email: userEmail,
    password: userPassword
  }).then(function (userRecord) {
    // See the UserRecord reference doc for the contents of userRecord.
    const additionalClaims = {
      sellerAccount: true
    };

    admin.auth().setCustomUserClaims(userRecord.uid, additionalClaims)
      .then(function (customToken) {
        // Send token back to client
        console.log("Successfully token created new user:", userRecord.uid);
      })
      .catch((error) => {
        console.log("Error creating custom token:", error);
      });

    db.ref("Users/" + userRecord.uid).set(user)
      .then(() => {
        console.log("seller info inserted successfully");
      })
      .catch(function (error) {
        console.log("Error while inserting seller info:", error);
      });

  }).catch(function(error) {
    // console.log("Error creating new user:", error);
    throw new functions.https.HttpsError('already-exists',error);
  });

})

安卓code:.

private void createAccount() {
    ekhtarSeller.showProgressDialog(this);
    newUser.setFirstName(tietFirstName.getText().toString().trim());
    newUser.setLastName(tietLastName.getText().toString().trim());
    newUser.setMobileNumber(tietMobileNumber.getText().toString().trim());

    HashMap<String, Object> data = new HashMap<String, Object>();
    data.put("email", tietEmail.getText().toString().trim());
    data.put("password", tietPassword.getText().toString().trim());
    data.put("newUser", new Gson().toJson(newUser));

    mFunctions
            .getHttpsCallable("createSellerAccount")
            .call(data)
            .continueWith(new Continuation<HttpsCallableResult, String>() {
                @Override
                public String then(@NonNull Task<HttpsCallableResult> task) throws Exception {
                    // This continuation runs on either success or failure, but if the task
                    // has failed then getResult() will throw an Exception which will be
                    // propagated down.
                    ekhtarSeller.getProgressDialog().cancel();
                    String result = (String) task.getResult().getData();
                    Toast.makeText(CreateAccountActivity.this, result, Toast.LENGTH_SHORT).show();
                    return result;
                }
            });
}
pbwdgjma

pbwdgjma1#

碰巧你没有使用firebase中链接文档中列出的值作为代码参数,你会得到googleapi的错误代码 "failed-auth" 或者 "invalid-email" 请访问functions.https.httpserror

相关问题