我将我的 Firebase 规则更改为所有经过身份验证的用户。我需要在请求中更改什么 (Flutter)

I changed my Firebase rules to all authenticated users.. What I need to change in requests (Flutter)

我更改了我的规则以允许所有经过身份验证的用户访问:

rules_version = '2';
// Allow read/write access on all documents to any user signed in to the application
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}

这是查询的例子

      await databaseReference
          .collection("lab_${pathSlashless}_url")
          .get()
          .then //......

我需要更改哪些内容以适应新规则?

我每次都需要零钱吗?还是只在一个地方?

嗯...那么您可能还必须登录到 firebase。为此,只需通过 firebase 中的身份验证选项卡。说明对此很清楚。之后,您必须将 firebase_authfirebase_core 包添加到您的 pubspec.yaml.

完成所有这些操作后,您可以继续对用户进行身份验证。

import 'package:firebase_auth/firebase_auth.dart' as auth;

final auth.FirebaseAuth _firebaseAuth;

Future<void> signIn() {
  final String token = yourSignInMethod_s_Token();
  // Basically, any unique String value for each user
    try {
    await _firebaseAuth.signInWithCustomToken(token).catchError(onError);
    // Or you can do authentication with any other method, like email/password
    // phone number, etc. Just read up of the auth error codes for those
    // in case of errors like shown below.
  } on auth.FirebaseAuthException catch (e) {
    if (e.code == 'custom-token-mismatch') {
    } else if (e.code == 'invalid-custom-token') {
    } else {}
  }
}