Compare commits
	
		
			2 Commits
		
	
	
		
			37e00fe9c4
			...
			c7b241de2d
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c7b241de2d | |||
| 94d573a584 | 
@ -14,7 +14,6 @@
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
import 'package:firebase_auth/firebase_auth.dart';
 | 
			
		||||
import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
 | 
			
		||||
import 'package:wyatt_type_utils/wyatt_type_utils.dart';
 | 
			
		||||
 | 
			
		||||
@ -182,6 +181,39 @@ class AuthenticationFirebaseDataSourceImpl
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Future<Account> signInWithGoogle() async {
 | 
			
		||||
    try {
 | 
			
		||||
      // Trigger the authentication flow
 | 
			
		||||
      final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
 | 
			
		||||
 | 
			
		||||
      // Obtain the auth details from the request
 | 
			
		||||
      final GoogleSignInAuthentication? googleAuth =
 | 
			
		||||
          await googleUser?.authentication;
 | 
			
		||||
 | 
			
		||||
      // Create a new credential
 | 
			
		||||
      final credential = GoogleAuthProvider.credential(
 | 
			
		||||
        accessToken: googleAuth?.accessToken,
 | 
			
		||||
        idToken: googleAuth?.idToken,
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
      final userCredential =
 | 
			
		||||
          await _firebaseAuth.signInWithCredential(credential);
 | 
			
		||||
 | 
			
		||||
      _latestCreds = userCredential;
 | 
			
		||||
      final user = userCredential.user;
 | 
			
		||||
      if (user.isNotNull) {
 | 
			
		||||
        return _mapper(user!);
 | 
			
		||||
      } else {
 | 
			
		||||
        throw Exception(); // Get caught just after.
 | 
			
		||||
      }
 | 
			
		||||
    } on FirebaseAuthException catch (e) {
 | 
			
		||||
      throw SignInWithGoogleFailureFirebase.fromCode(e.code);
 | 
			
		||||
    } catch (_) {
 | 
			
		||||
      throw SignInWithGoogleFailureFirebase();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Future<bool> verifyPasswordResetCode({required String code}) async {
 | 
			
		||||
    try {
 | 
			
		||||
 | 
			
		||||
@ -123,6 +123,25 @@ class AuthenticationMockDataSourceImpl extends AuthenticationRemoteDataSource {
 | 
			
		||||
    return Future.value(mock);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Future<Account> signInWithGoogle() async {
 | 
			
		||||
    await _randomDelay();
 | 
			
		||||
    final creation = DateTime.now();
 | 
			
		||||
    final mock = AccountModel(
 | 
			
		||||
      uid: 'mock-id-google',
 | 
			
		||||
      emailVerified: true,
 | 
			
		||||
      isAnonymous: false,
 | 
			
		||||
      providerId: 'google',
 | 
			
		||||
      creationTime: creation,
 | 
			
		||||
      lastSignInTime: creation,
 | 
			
		||||
      isNewUser: creation == creation,
 | 
			
		||||
    );
 | 
			
		||||
    _streamAccount.add(mock);
 | 
			
		||||
    _connectedMock = _connectedMock?.copyWith(left: mock);
 | 
			
		||||
    _lastSignInTime = DateTime.now();
 | 
			
		||||
    return Future.value(mock);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Future<Account> signInWithEmailAndPassword({
 | 
			
		||||
    required String email,
 | 
			
		||||
 | 
			
		||||
@ -295,6 +295,17 @@ class AuthenticationRepositoryImpl<T extends Object>
 | 
			
		||||
        (error) => error,
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  FutureOrResult<Account> signInWithGoogle() =>
 | 
			
		||||
      Result.tryCatchAsync<Account, AppException, AppException>(
 | 
			
		||||
        () async {
 | 
			
		||||
          final account =
 | 
			
		||||
              await _authenticationRemoteDataSource.signInWithGoogle();
 | 
			
		||||
          return account;
 | 
			
		||||
        },
 | 
			
		||||
        (error) => error,
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  FutureOrResult<bool> verifyPasswordResetCode({required String code}) =>
 | 
			
		||||
      Result.tryCatchAsync<bool, AppException, AppException>(
 | 
			
		||||
 | 
			
		||||
@ -49,6 +49,8 @@ abstract class AuthenticationRemoteDataSource extends BaseRemoteDataSource {
 | 
			
		||||
 | 
			
		||||
  Future<Account> signInAnonymously();
 | 
			
		||||
 | 
			
		||||
  Future<Account> signInWithGoogle();
 | 
			
		||||
 | 
			
		||||
  Future<Account> updateEmail({required String email});
 | 
			
		||||
 | 
			
		||||
  Future<Account> updatePassword({required String password});
 | 
			
		||||
 | 
			
		||||
@ -73,6 +73,13 @@ abstract class AuthenticationRepository<T> extends BaseRepository {
 | 
			
		||||
  /// {@endtemplate}
 | 
			
		||||
  FutureOrResult<Account> signInAnonymously();
 | 
			
		||||
 | 
			
		||||
  /// {@template signin_google}
 | 
			
		||||
  /// Starts the Sign In with Google Flow.
 | 
			
		||||
  ///
 | 
			
		||||
  /// Throws a SignInWithGoogleFailureInterface if an exception occurs.
 | 
			
		||||
  /// {@endtemplate}
 | 
			
		||||
  FutureOrResult<Account> signInWithGoogle();
 | 
			
		||||
 | 
			
		||||
  /// {@template signin_pwd}
 | 
			
		||||
  /// Signs in with the provided [email] and [password].
 | 
			
		||||
  ///
 | 
			
		||||
 | 
			
		||||
@ -17,4 +17,7 @@
 | 
			
		||||
/// An authentication library for BLoC.
 | 
			
		||||
library wyatt_authentication_bloc;
 | 
			
		||||
 | 
			
		||||
export 'package:firebase_auth/firebase_auth.dart';
 | 
			
		||||
export 'package:google_sign_in/google_sign_in.dart';
 | 
			
		||||
 | 
			
		||||
export 'src/src.dart';
 | 
			
		||||
 | 
			
		||||
@ -10,17 +10,12 @@ environment:
 | 
			
		||||
  flutter: ">=1.17.0"
 | 
			
		||||
 | 
			
		||||
dependencies:
 | 
			
		||||
  flutter:
 | 
			
		||||
    sdk: flutter
 | 
			
		||||
 | 
			
		||||
  flutter: { sdk: flutter }
 | 
			
		||||
  crypto: ^3.0.2
 | 
			
		||||
  flutter_bloc: ^8.1.1
 | 
			
		||||
  equatable: ^2.0.5
 | 
			
		||||
  firebase_auth: ^4.1.1
 | 
			
		||||
  google_sign_in: ^5.3.0
 | 
			
		||||
  flutter_facebook_auth: ^4.3.0
 | 
			
		||||
  sign_in_with_apple: ^3.3.0
 | 
			
		||||
  twitter_login: ^4.2.3
 | 
			
		||||
  firebase_auth: ^4.2.0
 | 
			
		||||
  google_sign_in: ^5.4.2
 | 
			
		||||
  rxdart: ^0.27.7
 | 
			
		||||
 | 
			
		||||
  wyatt_form_bloc:
 | 
			
		||||
@ -36,8 +31,7 @@ dependencies:
 | 
			
		||||
    version: ^0.0.4
 | 
			
		||||
 | 
			
		||||
dev_dependencies:
 | 
			
		||||
  flutter_test:
 | 
			
		||||
    sdk: flutter
 | 
			
		||||
  flutter_test: { sdk: flutter }
 | 
			
		||||
  bloc_test: ^9.1.0
 | 
			
		||||
  mocktail: ^0.3.0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user