createUser method
Register New User using either EmailAndPassword OR PhoneNumber authentication This method validates the form, creates a new user model, authenticates the user with Firebase, and stores the user data in Firestore.
Implementation
Future<void> createUser() async {
try {
isLoading.value = true;
if (!signupFormKey.currentState!.validate()) {
isLoading.value = false;
return;
}
// Get User and Pass it to Controller
final user = UserModel(
email: email.text.trim(),
password: password.text.trim(),
userName: userName.text.trim(),
fullName: fullName.text.trim(),
createdAt: Timestamp.now(),
updatedAt: Timestamp.now(),
fitnessLevel: "Beginner",
completedExercises: 0,
profilePicture: "",
role: "user",
);
// Authenticate User first
final auth = AuthenticationRepository.instance;
await auth.registerWithEmailAndPassword(user.email, user.password!);
await UserRepository.instance.createUser(user);
// Create user in Supabase??? TODO
// Once the user Signed In, Check if the User Data is already stored in Firestore Collection('Users')
auth.setInitialScreen(auth.firebaseUser);
} catch (e) {
isLoading.value = false;
Get.snackbar("Error", e.toString(), snackPosition: SnackPosition.BOTTOM, duration: const Duration(seconds: 5));
}
}