所以我想在顫振中對我的應用程式實施基于角色的身份驗證。只有具有權限的用戶才能訪問此站點。我收到錯誤:
The getter 'documents' isn't defined for the type 'QuerySnapshot<Map<String, dynamic>>'.
Try importing the library that defines 'documents', correcting the name to the name of an existing getter, or defining a getter or field named 'documents'.
有人可以在這里幫助我嗎?
代碼:
class AutoLoginHandler extends StatelessWidget {
@override
authorizeAccess(BuildContext context) {
FirebaseAuth.instance.currentUser!().then((user) {
FirebaseFirestore.instance
.collection('/users')
.where('uid', isEqualTo: user.uid)
.get()
.then((docs) {
if (docs.documents[0].data.exists) {
if (docs.documents[0].data['role'] == 'admin') {
Navigator.of(context).push(new MaterialPageRoute(
builder: (BuildContext context) => new LehrerMainPage()));
}
}
});
});
}
}
uj5u.com熱心網友回復:
試試這個。但我建議您用于角色管理訪問始終使用Custom Claims。
.then((results) {
if (results.size > 0) {
if (results.docs[0].data()['role'] == 'admin')
{
Navigator.of(context).push(new
MaterialPageRoute(
builder: (BuildContext context) => new
LehrerMainPage()));
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/408748.html
標籤:
