i wanted to ask how to make two role based login using Firebase? i have been looking everywhere and tried a lot but i have failed. For my mobile app, i have two different user which is "user" and "client", When they sign up, they can choose whether to be a normal user or client so in the database they have "role" in their collection. Below is my sign in function that been used in my login page and my user state function will be called in the main.dart
void _submitFormOnLogin() async {
final isValid = _loginFormKey.currentState!.validate();
if (isValid) {
setState(() {
_isLoading = true;
});
try {
await _auth.signInWithEmailAndPassword(
email: _emailTextController.text.trim().toLowerCase(),
password: _passwordTextController.text.trim());
Navigator.canPop(context) ? Navigator.pop(context) : null;
} catch (error) {
setState(() {
_isLoading = false;
});
GlobalMethod.showErrorDialog(error: error.toString(), ctx: context);
print('error occured $error');
}
}
setState(() {
_isLoading = false;
});
}
class UserState extends StatelessWidget {
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (ctx, userSnapshot) {
if (userSnapshot.data == null) {
print('User is not Login yet');
return Login();
}
else if (userSnapshot.hasData ) {
print("User is already logged in");
return JobScreen();
}
else if (userSnapshot.hasError) {
return Scaffold(
body: Center(
child: Text ('An error has occured'),
),
);
}
else if (userSnapshot.connectionState == ConnectionState.waiting) {
return Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
);
}
return Scaffold(
body: Center(
child: Text('Something went wrong'),
),
);
}
);
}
}