AuthServiec.dart 752 B

12345678910111213141516171819202122232425262728
  1. import 'package:firebase_auth/firebase_auth.dart';
  2. class AuthenticationServices {
  3. final FirebaseAuth _auth = FirebaseAuth.instance;
  4. //Register a user
  5. Future createNewUser(String name, String email, String password) async {
  6. try {
  7. UserCredential result = await _auth.createUserWithEmailAndPassword(
  8. email: email, password: password);
  9. User? user = result.user;
  10. return user;
  11. } catch (e) {
  12. print(e.toString());
  13. }
  14. }
  15. //LogIn with user
  16. Future loginUser(String email, String password) async {
  17. try {
  18. UserCredential result = await _auth.signInWithEmailAndPassword(
  19. email: email, password: password);
  20. return result.user;
  21. } catch(e) {
  22. print(e.toString());
  23. }
  24. }
  25. }