flutter firestore role based authentication

Viewed 1569

I'm developing a flutter app with firestore, I want to use the same app for users and administrator, is it possible to use role based authentication like when logging in, if the user is an admin then the app then the app returns the admin page and if the user is a regular user then the app returns a different home screen from the admins'?

2 Answers

It's possible. But you can't do it in Firebase Authentication only. You need to implement Cloud Firestore and develop the database in a a way so that you can query different users. As an example, different collections for different types of users. Make sure you use proper security rules so that users don't access your admin data anyhow. See the Firestore Security Rules Doc

Screenshot Database Example

You can use custom claims feature to set a role to the user. This can be done with admin SDK. I recommend you to check the link below from the Firebase Docs.

https://firebase.google.com/docs/auth/admin/custom-claims

Once you set a role with custom claims, you can write firestore rules and check the role at the client side to show the appropriate UI.

Related