master #81

Closed
malo wants to merge 322 commits from master into feat/bloc_layout/new-package
11 changed files with 92 additions and 66 deletions
Showing only changes of commit 5f52b2fc3d - Show all commits

View File

@ -50,8 +50,8 @@ abstract class GetItInitializer {
), ),
]) ])
: () => AuthenticationFirebaseDataSourceImpl( : () => AuthenticationFirebaseDataSourceImpl(
googleSignIn: GoogleSignIn(clientId: DefaultFirebaseOptions.ios.iosClientId) googleSignIn: GoogleSignIn(
), clientId: DefaultFirebaseOptions.ios.iosClientId)),
) )
..registerLazySingleton<AuthenticationCacheDataSource<int>>( ..registerLazySingleton<AuthenticationCacheDataSource<int>>(
() => AuthenticationCacheDataSourceImpl<int>(), () => AuthenticationCacheDataSourceImpl<int>(),

View File

@ -58,8 +58,10 @@ class DefaultFirebaseOptions {
messagingSenderId: '405351917235', messagingSenderId: '405351917235',
projectId: 'meerabel-dev', projectId: 'meerabel-dev',
storageBucket: 'meerabel-dev.appspot.com', storageBucket: 'meerabel-dev.appspot.com',
androidClientId: '405351917235-4g1dh3475tq6t1sa2qoh7ol60nf4ta05.apps.googleusercontent.com', androidClientId:
iosClientId: '405351917235-2jv4ff02kovoim58f8d6d0rsa14apgkj.apps.googleusercontent.com', '405351917235-4g1dh3475tq6t1sa2qoh7ol60nf4ta05.apps.googleusercontent.com',
iosClientId:
'405351917235-2jv4ff02kovoim58f8d6d0rsa14apgkj.apps.googleusercontent.com',
iosBundleId: 'com.example.exampleRouter', iosBundleId: 'com.example.exampleRouter',
); );
} }

View File

@ -20,7 +20,6 @@ part 'exceptions_firebase.dart';
abstract class AuthenticationFailureInterface extends AppException abstract class AuthenticationFailureInterface extends AppException
implements Exception { implements Exception {
AuthenticationFailureInterface(this.code, this.msg); AuthenticationFailureInterface(this.code, this.msg);
AuthenticationFailureInterface.fromCode(this.code) AuthenticationFailureInterface.fromCode(this.code)
: msg = 'An unknown error occurred.'; : msg = 'An unknown error occurred.';
@ -277,3 +276,10 @@ abstract class UpdatePasswordFailureInterface
UpdatePasswordFailureInterface.fromCode(super.code) : super.fromCode(); UpdatePasswordFailureInterface.fromCode(super.code) : super.fromCode();
} }
abstract class ModelParsingFailureInterface
extends AuthenticationFailureInterface {
ModelParsingFailureInterface(super.code, super.msg);
ModelParsingFailureInterface.fromCode(super.code) : super.fromCode();
}

View File

@ -349,3 +349,10 @@ class UpdatePasswordFailureFirebase extends UpdatePasswordFailureInterface {
} }
} }
} }
class ModelParsingFailureFirebase extends ModelParsingFailureInterface {
ModelParsingFailureFirebase([String? code, String? msg])
: super(code ?? 'unknown', msg ?? 'An unknown error occurred.');
ModelParsingFailureFirebase.fromCode(super.code) : super.fromCode();
}

View File

@ -20,7 +20,6 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart';
class AuthenticationCacheDataSourceImpl<T extends Object> class AuthenticationCacheDataSourceImpl<T extends Object>
extends AuthenticationCacheDataSource<T> { extends AuthenticationCacheDataSource<T> {
AuthenticationCacheDataSourceImpl(); AuthenticationCacheDataSourceImpl();
Account? _account; Account? _account;
T? _data; T? _data;

View File

@ -14,36 +14,22 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:wyatt_authentication_bloc/src/data/models/account_model_firebase.dart';
import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart'; import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
import 'package:wyatt_type_utils/wyatt_type_utils.dart'; import 'package:wyatt_type_utils/wyatt_type_utils.dart';
class AuthenticationFirebaseDataSourceImpl class AuthenticationFirebaseDataSourceImpl
extends AuthenticationRemoteDataSource { extends AuthenticationRemoteDataSource {
AuthenticationFirebaseDataSourceImpl( AuthenticationFirebaseDataSourceImpl({
{FirebaseAuth? firebaseAuth, GoogleSignIn? googleSignIn,}) FirebaseAuth? firebaseAuth,
: _firebaseAuth = firebaseAuth ?? FirebaseAuth.instance, GoogleSignIn? googleSignIn,
}) : _firebaseAuth = firebaseAuth ?? FirebaseAuth.instance,
_googleSignIn = googleSignIn ?? GoogleSignIn(); _googleSignIn = googleSignIn ?? GoogleSignIn();
final FirebaseAuth _firebaseAuth; final FirebaseAuth _firebaseAuth;
final GoogleSignIn _googleSignIn; final GoogleSignIn _googleSignIn;
UserCredential? _latestCreds; UserCredential? _latestCreds;
Account _mapper(User user) => AccountModel(
uid: user.uid,
emailVerified: user.emailVerified,
isAnonymous: user.isAnonymous,
providerId: user.providerData.first.providerId,
creationTime: user.metadata.creationTime,
lastSignInTime: user.metadata.lastSignInTime,
isNewUser: (user.metadata.creationTime != null &&
user.metadata.lastSignInTime != null)
? user.metadata.lastSignInTime! == user.metadata.creationTime!
: null,
email: user.email,
phoneNumber: user.phoneNumber,
photoURL: user.photoURL,
);
@override @override
Future<Account> signInWithEmailAndPassword({ Future<Account> signInWithEmailAndPassword({
required String email, required String email,
@ -56,11 +42,7 @@ class AuthenticationFirebaseDataSourceImpl
); );
_latestCreds = userCredential; _latestCreds = userCredential;
final user = userCredential.user; final user = userCredential.user;
if (user.isNotNull) { return AccountModelFirebase.fromFirebaseUser(user);
return _mapper(user!);
} else {
throw Exception(); // Get caught just after.
}
} on FirebaseAuthException catch (e) { } on FirebaseAuthException catch (e) {
throw SignInWithEmailAndPasswordFailureFirebase.fromCode(e.code); throw SignInWithEmailAndPasswordFailureFirebase.fromCode(e.code);
} catch (_) { } catch (_) {
@ -82,11 +64,7 @@ class AuthenticationFirebaseDataSourceImpl
); );
_latestCreds = userCredential; _latestCreds = userCredential;
final user = userCredential.user; final user = userCredential.user;
if (user.isNotNull) { return AccountModelFirebase.fromFirebaseUser(user);
return _mapper(user!);
} else {
throw Exception(); // Get caught just after.
}
} on FirebaseAuthException catch (e) { } on FirebaseAuthException catch (e) {
throw SignUpWithEmailAndPasswordFailureFirebase.fromCode(e.code); throw SignUpWithEmailAndPasswordFailureFirebase.fromCode(e.code);
} catch (_) { } catch (_) {
@ -123,8 +101,11 @@ class AuthenticationFirebaseDataSourceImpl
@override @override
Stream<Account?> streamAccount() => Stream<Account?> streamAccount() =>
_firebaseAuth.userChanges().map<Account?>((user) { _firebaseAuth.userChanges().map<Account?>((user) {
final Account? account = (user.isNotNull) ? _mapper(user!) : null; try {
return account; return AccountModelFirebase.fromFirebaseUser(user);
} on FirebaseAuthException {
return null;
}
}); });
@override @override
@ -172,11 +153,7 @@ class AuthenticationFirebaseDataSourceImpl
final userCredential = await _firebaseAuth.signInAnonymously(); final userCredential = await _firebaseAuth.signInAnonymously();
_latestCreds = userCredential; _latestCreds = userCredential;
final user = userCredential.user; final user = userCredential.user;
if (user.isNotNull) { return AccountModelFirebase.fromFirebaseUser(user);
return _mapper(user!);
} else {
throw Exception(); // Get caught just after.
}
} on FirebaseAuthException catch (e) { } on FirebaseAuthException catch (e) {
throw SignInAnonymouslyFailureFirebase.fromCode(e.code); throw SignInAnonymouslyFailureFirebase.fromCode(e.code);
} catch (_) { } catch (_) {
@ -205,11 +182,7 @@ class AuthenticationFirebaseDataSourceImpl
_latestCreds = userCredential; _latestCreds = userCredential;
final user = userCredential.user; final user = userCredential.user;
if (user.isNotNull) { return AccountModelFirebase.fromFirebaseUser(user);
return _mapper(user!);
} else {
throw Exception(); // Get caught just after.
}
} on FirebaseAuthException catch (e) { } on FirebaseAuthException catch (e) {
throw SignInWithGoogleFailureFirebase.fromCode(e.code); throw SignInWithGoogleFailureFirebase.fromCode(e.code);
} catch (_) { } catch (_) {
@ -250,11 +223,7 @@ class AuthenticationFirebaseDataSourceImpl
throw Exception(); // Get caught just after. throw Exception(); // Get caught just after.
} }
final user = _firebaseAuth.currentUser; final user = _firebaseAuth.currentUser;
if (user.isNotNull) { return AccountModelFirebase.fromFirebaseUser(user);
return _mapper(user!);
} else {
throw Exception(); // Get caught just after.
}
} on FirebaseAuthException catch (e) { } on FirebaseAuthException catch (e) {
throw ReauthenticateFailureFirebase.fromCode(e.code); throw ReauthenticateFailureFirebase.fromCode(e.code);
} catch (_) { } catch (_) {
@ -267,11 +236,7 @@ class AuthenticationFirebaseDataSourceImpl
try { try {
await _firebaseAuth.currentUser!.updateEmail(email); await _firebaseAuth.currentUser!.updateEmail(email);
final user = _firebaseAuth.currentUser; final user = _firebaseAuth.currentUser;
if (user.isNotNull) { return AccountModelFirebase.fromFirebaseUser(user);
return _mapper(user!);
} else {
throw Exception(); // Get caught just after.
}
} on FirebaseAuthException catch (e) { } on FirebaseAuthException catch (e) {
throw UpdateEmailFailureFirebase.fromCode(e.code); throw UpdateEmailFailureFirebase.fromCode(e.code);
} catch (_) { } catch (_) {
@ -284,11 +249,7 @@ class AuthenticationFirebaseDataSourceImpl
try { try {
await _firebaseAuth.currentUser!.updatePassword(password); await _firebaseAuth.currentUser!.updatePassword(password);
final user = _firebaseAuth.currentUser; final user = _firebaseAuth.currentUser;
if (user.isNotNull) { return AccountModelFirebase.fromFirebaseUser(user);
return _mapper(user!);
} else {
throw Exception(); // Get caught just after.
}
} on FirebaseAuthException catch (e) { } on FirebaseAuthException catch (e) {
throw UpdatePasswordFailureFirebase.fromCode(e.code); throw UpdatePasswordFailureFirebase.fromCode(e.code);
} catch (_) { } catch (_) {

View File

@ -21,7 +21,6 @@ import 'package:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
import 'package:wyatt_type_utils/wyatt_type_utils.dart'; import 'package:wyatt_type_utils/wyatt_type_utils.dart';
class AuthenticationMockDataSourceImpl extends AuthenticationRemoteDataSource { class AuthenticationMockDataSourceImpl extends AuthenticationRemoteDataSource {
AuthenticationMockDataSourceImpl({ AuthenticationMockDataSourceImpl({
this.idToken = 'fake-id-token', this.idToken = 'fake-id-token',
this.registeredAccounts, this.registeredAccounts,

View File

@ -0,0 +1,55 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
// Copyright (C) 2022 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// 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:wyatt_authentication_bloc/wyatt_authentication_bloc.dart';
class AccountModelFirebase extends AccountModel {
AccountModelFirebase._({
required super.uid,
required super.emailVerified,
required super.isAnonymous,
required super.providerId,
super.lastSignInTime,
super.creationTime,
super.isNewUser,
super.email,
super.phoneNumber,
super.photoURL,
});
factory AccountModelFirebase.fromFirebaseUser(User? user) {
if (user != null) {
return AccountModelFirebase._(
uid: user.uid,
emailVerified: user.emailVerified,
isAnonymous: user.isAnonymous,
providerId: user.providerData.first.providerId,
creationTime: user.metadata.creationTime,
lastSignInTime: user.metadata.lastSignInTime,
isNewUser: (user.metadata.creationTime != null &&
user.metadata.lastSignInTime != null)
? user.metadata.lastSignInTime! == user.metadata.creationTime!
: null,
email: user.email,
phoneNumber: user.phoneNumber,
photoURL: user.photoURL,
);
} else {
throw ModelParsingFailureFirebase('null-user', 'User cannot be null!');
}
}
}

View File

@ -26,7 +26,6 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart';
part 'authentication_state.dart'; part 'authentication_state.dart';
class AuthenticationCubit<Extra> extends Cubit<AuthenticationState<Extra>> { class AuthenticationCubit<Extra> extends Cubit<AuthenticationState<Extra>> {
AuthenticationCubit({ AuthenticationCubit({
required AuthenticationRepository<Extra> authenticationRepository, required AuthenticationRepository<Extra> authenticationRepository,
}) : _authenticationRepository = authenticationRepository, }) : _authenticationRepository = authenticationRepository,

View File

@ -17,7 +17,6 @@
part of 'authentication_cubit.dart'; part of 'authentication_cubit.dart';
class AuthenticationState<Extra> extends Equatable { class AuthenticationState<Extra> extends Equatable {
const AuthenticationState.unauthenticated() const AuthenticationState.unauthenticated()
: this._(status: AuthenticationStatus.unauthenticated); : this._(status: AuthenticationStatus.unauthenticated);

View File

@ -17,7 +17,6 @@
part of 'sign_up_cubit.dart'; part of 'sign_up_cubit.dart';
class SignUpState extends FormDataState { class SignUpState extends FormDataState {
const SignUpState({ const SignUpState({
required super.form, required super.form,
super.status = FormStatus.pure, super.status = FormStatus.pure,