簡體   English   中英

電話驗證后的 Cloud Firestore 文檔檢查

[英]Cloud Firestore Document Check after Phone Authentication

我會盡量解釋清楚

我想在驗證完成時添加一個檢查。 因為檢查應該是這樣的:檢查是否有一個文檔 ID 為已驗證的用戶 UID 的文檔。 如果它在那里,那么 go 到家里。 如果它不存在,則使用我已經創建的 updateData class 創建一個文檔,然后使用 go 到主頁

這是我的電話身份驗證代碼

  Future phoneAuthentication(
    String fullName,
    String phoneNumber,
    String phoneIsoCode,
    String nonInternationalNumber,
    String profilePicture,
    String verificationCode,
    BuildContext context,
  ) async {
    _auth.verifyPhoneNumber(
      phoneNumber: phoneNumber,
      timeout: Duration(seconds: 0),
      verificationCompleted: (AuthCredential authCredential) async {
        _auth.signInWithCredential(authCredential).then(
          (UserCredential result) async {
            User user = result.user;
            await DatabaseService(uid: user.uid).updateUserData(
              fullName,
              phoneNumber,
              phoneIsoCode,
              nonInternationalNumber,
              profilePicture,
            );
            Navigator.pushAndRemoveUntil(
              context,
              MaterialPageRoute(
                builder: (context) => CustomerDashboard(),
              ),
              (route) => false,
            );
          },
        ).catchError(
          (e) {
            return null;
          },
        );
      },
      verificationFailed: (FirebaseAuthException exception) {
        return "Error";
      },
      codeSent: (String verificationId, [int forceResendingToken]) {
        var _credential = PhoneAuthProvider.credential(
          verificationId: verificationId,
          smsCode: verificationCode,
        );
        _auth.signInWithCredential(_credential).then(
          (UserCredential result) async {
            User user = result.user;
            await DatabaseService(uid: user.uid).updateUserData(
              fullName,
              phoneNumber,
              phoneIsoCode,
              nonInternationalNumber,
              profilePicture,
            );
            Navigator.pushAndRemoveUntil(
              context,
              MaterialPageRoute(
                builder: (context) => CustomerDashboard(),
              ),
              (route) => false,
            );
          },
        ).catchError(
          (e) {},
        );
      },
      codeAutoRetrievalTimeout: (String verificationId) {
        verificationId = verificationId;
      },
    );
  }

請幫助我應該如何添加此檢查。

我從這個 Stack Overflow Question復制並修改了這段代碼

DocumentSnapshot ds = await YOUR_DB_REFERENCE_IDENTIFIER.collection("YOUR_COLLECTION_NAME").document(user.uid).get();
return ds.exists;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM