Page MenuHomec4science

FirebaseAuthService.dart
No OneTemporary

File Metadata

Created
Sat, Nov 9, 05:31

FirebaseAuthService.dart

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
class FlutterFireAuthService {
final FirebaseAuth _firebaseAuth;
FlutterFireAuthService(this._firebaseAuth);
Stream<User?> get authStateChanges => _firebaseAuth.idTokenChanges();
Future<void> signOut({required BuildContext context}) async {
await _firebaseAuth.signOut();
Navigator.pushReplacementNamed(context, '/');
}
Future<String> signIn(
{required String email, required String password, required BuildContext context}) async {
try {
await _firebaseAuth.signInWithEmailAndPassword(
email: email, password: password);
Navigator.pushReplacementNamed(context, '/homeScreen');
return "Success";
} on FirebaseAuthException catch (e) {
print(e.toString());
return e.code;
}
}
Future<String> signUp(
{required String email, required String password, required BuildContext context}) async {
try {
await _firebaseAuth.createUserWithEmailAndPassword(
email: email, password: password);
Navigator.pushNamed(context, '/mayScreen');
return "Success";
} on FirebaseAuthException catch (e) {
return e.code;
}
}
}

Event Timeline