-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
125 changed files
with
2,126 additions
and
2,292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
sealed class AuthException { | ||
const factory AuthException.unknown(Exception exception) = AuthExceptionUnknown; | ||
|
||
const factory AuthException.canceled() = AuthExceptionCanceled; | ||
|
||
const factory AuthException.failed() = AuthExceptionFailed; | ||
|
||
const factory AuthException.networkUnavailable() = AuthExceptionNetworkUnavailable; | ||
|
||
const factory AuthException.popupBlockedByBrowser() = AuthExceptionPopupBlockedByBrowser; | ||
|
||
const factory AuthException.invalidEmail({String? email}) = AuthExceptionInvalidEmail; | ||
|
||
const factory AuthException.userDisabled({String? email}) = AuthExceptionUserDisabled; | ||
|
||
const factory AuthException.userNotFound({String? email}) = AuthExceptionUserNotFound; | ||
|
||
const factory AuthException.tooManyRequests({String? email}) = AuthExceptionTooManyRequests; | ||
} | ||
|
||
class AuthExceptionUnknown implements AuthException { | ||
const AuthExceptionUnknown(this.exception); | ||
|
||
final Exception exception; | ||
} | ||
|
||
class AuthExceptionCanceled implements AuthException { | ||
const AuthExceptionCanceled(); | ||
} | ||
|
||
class AuthExceptionFailed implements AuthException { | ||
const AuthExceptionFailed(); | ||
} | ||
|
||
class AuthExceptionNetworkUnavailable implements AuthException { | ||
const AuthExceptionNetworkUnavailable(); | ||
} | ||
|
||
class AuthExceptionPopupBlockedByBrowser implements AuthException { | ||
const AuthExceptionPopupBlockedByBrowser(); | ||
} | ||
|
||
class AuthExceptionInvalidEmail implements AuthException { | ||
const AuthExceptionInvalidEmail({this.email}); | ||
|
||
final String? email; | ||
} | ||
|
||
class AuthExceptionUserDisabled implements AuthException { | ||
const AuthExceptionUserDisabled({this.email}); | ||
|
||
final String? email; | ||
} | ||
|
||
class AuthExceptionUserNotFound implements AuthException { | ||
const AuthExceptionUserNotFound({this.email}); | ||
|
||
final String? email; | ||
} | ||
|
||
class AuthExceptionTooManyRequests implements AuthException { | ||
const AuthExceptionTooManyRequests({this.email}); | ||
|
||
final String? email; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import '../entities/account_entity.dart'; | ||
import '../repositories/accounts.dart'; | ||
|
||
class FetchAccountUseCase { | ||
const FetchAccountUseCase({required Accounts accounts}) : _accounts = accounts; | ||
|
||
final Accounts _accounts; | ||
|
||
Future<AccountEntity> call() => _accounts.fetch(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:rxdart/transformers.dart'; | ||
import 'package:tailor_made/core.dart'; | ||
|
||
import '../entities/account_entity.dart'; | ||
import '../entities/auth_exception.dart'; | ||
import '../repositories/accounts.dart'; | ||
|
||
class SignInUseCase { | ||
const SignInUseCase({required Accounts accounts}) : _accounts = accounts; | ||
|
||
final Accounts _accounts; | ||
|
||
Future<AccountEntity> call() async { | ||
final Completer<AccountEntity> completer = Completer<AccountEntity>(); | ||
|
||
late StreamSubscription<void> sub; | ||
sub = _accounts.onAuthStateChanged.whereType<String>().listen( | ||
(_) { | ||
completer.complete(_accounts.fetch()); | ||
sub.cancel(); | ||
}, | ||
onError: (Object error, StackTrace stackTrace) { | ||
completer.completeError(error, stackTrace); | ||
sub.cancel(); | ||
}, | ||
); | ||
|
||
try { | ||
await _accounts.signIn(); | ||
} on AuthException catch (error, stackTrace) { | ||
if (error is AuthExceptionFailed) { | ||
AppLog.e(error, stackTrace); | ||
} | ||
rethrow; | ||
} | ||
|
||
return completer.future; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'dart:async'; | ||
|
||
import '../repositories/accounts.dart'; | ||
|
||
class SignOutUseCase { | ||
const SignOutUseCase({required Accounts accounts}) : _accounts = accounts; | ||
|
||
final Accounts _accounts; | ||
|
||
Future<void> call() async { | ||
final Completer<void> completer = Completer<void>(); | ||
|
||
late StreamSubscription<void> sub; | ||
sub = _accounts.onAuthStateChanged.where((String? id) => id == null).listen( | ||
(_) { | ||
completer.complete(); | ||
sub.cancel(); | ||
}, | ||
onError: (Object error, StackTrace st) { | ||
completer.completeError(error, st); | ||
sub.cancel(); | ||
}, | ||
); | ||
|
||
await _accounts.signOut(); | ||
|
||
return completer.future; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.