master #81
@ -1,4 +1 @@
|
|||||||
include: package:wyatt_analysis/analysis_options.flutter.yaml
|
include: package:wyatt_analysis/analysis_options.flutter.yaml
|
||||||
|
|
||||||
analyzer:
|
|
||||||
exclude: "!example/**"
|
|
@ -45,5 +45,3 @@ app.*.map.json
|
|||||||
/android/app/debug
|
/android/app/debug
|
||||||
/android/app/profile
|
/android/app/profile
|
||||||
/android/app/release
|
/android/app/release
|
||||||
|
|
||||||
firebase_options.dart
|
|
@ -4,7 +4,7 @@
|
|||||||
* -----
|
* -----
|
||||||
* File: launch.json
|
* File: launch.json
|
||||||
* Created Date: 19/08/2022 15:12:25
|
* Created Date: 19/08/2022 15:12:25
|
||||||
* Last Modified: 19/08/2022 15:22:02
|
* Last Modified: Tue Dec 13 2022
|
||||||
* -----
|
* -----
|
||||||
* Copyright (c) 2022
|
* Copyright (c) 2022
|
||||||
*/
|
*/
|
||||||
@ -15,11 +15,18 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "example_router",
|
"name": "Mock",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"type": "dart",
|
"type": "dart",
|
||||||
"program": "lib/main.dart",
|
"program": "lib/main.dart",
|
||||||
"flutterMode": "debug"
|
"flutterMode": "debug"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Firebase",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "dart",
|
||||||
|
"program": "lib/main_firebase.dart",
|
||||||
|
"flutterMode": "debug"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -5,41 +5,30 @@ PODS:
|
|||||||
- AppAuth/Core (1.6.0)
|
- AppAuth/Core (1.6.0)
|
||||||
- AppAuth/ExternalUserAgent (1.6.0):
|
- AppAuth/ExternalUserAgent (1.6.0):
|
||||||
- AppAuth/Core
|
- AppAuth/Core
|
||||||
- FBAEMKit (14.1.0):
|
- Firebase/Auth (10.3.0):
|
||||||
- FBSDKCoreKit_Basics (= 14.1.0)
|
|
||||||
- FBSDKCoreKit (14.1.0):
|
|
||||||
- FBAEMKit (= 14.1.0)
|
|
||||||
- FBSDKCoreKit_Basics (= 14.1.0)
|
|
||||||
- FBSDKCoreKit_Basics (14.1.0)
|
|
||||||
- FBSDKLoginKit (14.1.0):
|
|
||||||
- FBSDKCoreKit (= 14.1.0)
|
|
||||||
- Firebase/Auth (10.0.0):
|
|
||||||
- Firebase/CoreOnly
|
- Firebase/CoreOnly
|
||||||
- FirebaseAuth (~> 10.0.0)
|
- FirebaseAuth (~> 10.3.0)
|
||||||
- Firebase/CoreOnly (10.0.0):
|
- Firebase/CoreOnly (10.3.0):
|
||||||
- FirebaseCore (= 10.0.0)
|
- FirebaseCore (= 10.3.0)
|
||||||
- firebase_auth (4.1.1):
|
- firebase_auth (4.2.0):
|
||||||
- Firebase/Auth (= 10.0.0)
|
- Firebase/Auth (= 10.3.0)
|
||||||
- firebase_core
|
- firebase_core
|
||||||
- Flutter
|
- Flutter
|
||||||
- firebase_core (2.1.1):
|
- firebase_core (2.4.0):
|
||||||
- Firebase/CoreOnly (= 10.0.0)
|
- Firebase/CoreOnly (= 10.3.0)
|
||||||
- Flutter
|
- Flutter
|
||||||
- FirebaseAuth (10.0.0):
|
- FirebaseAuth (10.3.0):
|
||||||
- FirebaseCore (~> 10.0)
|
- FirebaseCore (~> 10.0)
|
||||||
- GoogleUtilities/AppDelegateSwizzler (~> 7.8)
|
- GoogleUtilities/AppDelegateSwizzler (~> 7.8)
|
||||||
- GoogleUtilities/Environment (~> 7.8)
|
- GoogleUtilities/Environment (~> 7.8)
|
||||||
- GTMSessionFetcher/Core (~> 2.1)
|
- GTMSessionFetcher/Core (< 4.0, >= 2.1)
|
||||||
- FirebaseCore (10.0.0):
|
- FirebaseCore (10.3.0):
|
||||||
- FirebaseCoreInternal (~> 10.0)
|
- FirebaseCoreInternal (~> 10.0)
|
||||||
- GoogleUtilities/Environment (~> 7.8)
|
- GoogleUtilities/Environment (~> 7.8)
|
||||||
- GoogleUtilities/Logger (~> 7.8)
|
- GoogleUtilities/Logger (~> 7.8)
|
||||||
- FirebaseCoreInternal (10.1.0):
|
- FirebaseCoreInternal (10.3.0):
|
||||||
- "GoogleUtilities/NSData+zlib (~> 7.8)"
|
- "GoogleUtilities/NSData+zlib (~> 7.8)"
|
||||||
- Flutter (1.0.0)
|
- Flutter (1.0.0)
|
||||||
- flutter_facebook_auth (4.4.1):
|
|
||||||
- FBSDKLoginKit (= 14.1.0)
|
|
||||||
- Flutter
|
|
||||||
- google_sign_in_ios (0.0.1):
|
- google_sign_in_ios (0.0.1):
|
||||||
- Flutter
|
- Flutter
|
||||||
- GoogleSignIn (~> 6.2)
|
- GoogleSignIn (~> 6.2)
|
||||||
@ -47,47 +36,36 @@ PODS:
|
|||||||
- AppAuth (~> 1.5)
|
- AppAuth (~> 1.5)
|
||||||
- GTMAppAuth (~> 1.3)
|
- GTMAppAuth (~> 1.3)
|
||||||
- GTMSessionFetcher/Core (< 3.0, >= 1.1)
|
- GTMSessionFetcher/Core (< 3.0, >= 1.1)
|
||||||
- GoogleUtilities/AppDelegateSwizzler (7.8.0):
|
- GoogleUtilities/AppDelegateSwizzler (7.10.0):
|
||||||
- GoogleUtilities/Environment
|
- GoogleUtilities/Environment
|
||||||
- GoogleUtilities/Logger
|
- GoogleUtilities/Logger
|
||||||
- GoogleUtilities/Network
|
- GoogleUtilities/Network
|
||||||
- GoogleUtilities/Environment (7.8.0):
|
- GoogleUtilities/Environment (7.10.0):
|
||||||
- PromisesObjC (< 3.0, >= 1.2)
|
- PromisesObjC (< 3.0, >= 1.2)
|
||||||
- GoogleUtilities/Logger (7.8.0):
|
- GoogleUtilities/Logger (7.10.0):
|
||||||
- GoogleUtilities/Environment
|
- GoogleUtilities/Environment
|
||||||
- GoogleUtilities/Network (7.8.0):
|
- GoogleUtilities/Network (7.10.0):
|
||||||
- GoogleUtilities/Logger
|
- GoogleUtilities/Logger
|
||||||
- "GoogleUtilities/NSData+zlib"
|
- "GoogleUtilities/NSData+zlib"
|
||||||
- GoogleUtilities/Reachability
|
- GoogleUtilities/Reachability
|
||||||
- "GoogleUtilities/NSData+zlib (7.8.0)"
|
- "GoogleUtilities/NSData+zlib (7.10.0)"
|
||||||
- GoogleUtilities/Reachability (7.8.0):
|
- GoogleUtilities/Reachability (7.10.0):
|
||||||
- GoogleUtilities/Logger
|
- GoogleUtilities/Logger
|
||||||
- GTMAppAuth (1.3.1):
|
- GTMAppAuth (1.3.1):
|
||||||
- AppAuth/Core (~> 1.6)
|
- AppAuth/Core (~> 1.6)
|
||||||
- GTMSessionFetcher/Core (< 3.0, >= 1.5)
|
- GTMSessionFetcher/Core (< 3.0, >= 1.5)
|
||||||
- GTMSessionFetcher/Core (2.1.0)
|
- GTMSessionFetcher/Core (2.3.0)
|
||||||
- PromisesObjC (2.1.1)
|
- PromisesObjC (2.1.1)
|
||||||
- sign_in_with_apple (0.0.1):
|
|
||||||
- Flutter
|
|
||||||
- twitter_login (0.0.1):
|
|
||||||
- Flutter
|
|
||||||
|
|
||||||
DEPENDENCIES:
|
DEPENDENCIES:
|
||||||
- firebase_auth (from `.symlinks/plugins/firebase_auth/ios`)
|
- firebase_auth (from `.symlinks/plugins/firebase_auth/ios`)
|
||||||
- firebase_core (from `.symlinks/plugins/firebase_core/ios`)
|
- firebase_core (from `.symlinks/plugins/firebase_core/ios`)
|
||||||
- Flutter (from `Flutter`)
|
- Flutter (from `Flutter`)
|
||||||
- flutter_facebook_auth (from `.symlinks/plugins/flutter_facebook_auth/ios`)
|
|
||||||
- google_sign_in_ios (from `.symlinks/plugins/google_sign_in_ios/ios`)
|
- google_sign_in_ios (from `.symlinks/plugins/google_sign_in_ios/ios`)
|
||||||
- sign_in_with_apple (from `.symlinks/plugins/sign_in_with_apple/ios`)
|
|
||||||
- twitter_login (from `.symlinks/plugins/twitter_login/ios`)
|
|
||||||
|
|
||||||
SPEC REPOS:
|
SPEC REPOS:
|
||||||
trunk:
|
trunk:
|
||||||
- AppAuth
|
- AppAuth
|
||||||
- FBAEMKit
|
|
||||||
- FBSDKCoreKit
|
|
||||||
- FBSDKCoreKit_Basics
|
|
||||||
- FBSDKLoginKit
|
|
||||||
- Firebase
|
- Firebase
|
||||||
- FirebaseAuth
|
- FirebaseAuth
|
||||||
- FirebaseCore
|
- FirebaseCore
|
||||||
@ -105,37 +83,24 @@ EXTERNAL SOURCES:
|
|||||||
:path: ".symlinks/plugins/firebase_core/ios"
|
:path: ".symlinks/plugins/firebase_core/ios"
|
||||||
Flutter:
|
Flutter:
|
||||||
:path: Flutter
|
:path: Flutter
|
||||||
flutter_facebook_auth:
|
|
||||||
:path: ".symlinks/plugins/flutter_facebook_auth/ios"
|
|
||||||
google_sign_in_ios:
|
google_sign_in_ios:
|
||||||
:path: ".symlinks/plugins/google_sign_in_ios/ios"
|
:path: ".symlinks/plugins/google_sign_in_ios/ios"
|
||||||
sign_in_with_apple:
|
|
||||||
:path: ".symlinks/plugins/sign_in_with_apple/ios"
|
|
||||||
twitter_login:
|
|
||||||
:path: ".symlinks/plugins/twitter_login/ios"
|
|
||||||
|
|
||||||
SPEC CHECKSUMS:
|
SPEC CHECKSUMS:
|
||||||
AppAuth: 8fca6b5563a5baef2c04bee27538025e4ceb2add
|
AppAuth: 8fca6b5563a5baef2c04bee27538025e4ceb2add
|
||||||
FBAEMKit: a899515e45476027f73aef377b5cffadcd56ca3a
|
Firebase: f92fc551ead69c94168d36c2b26188263860acd9
|
||||||
FBSDKCoreKit: 24f8bc8d3b5b2a8c5c656a1329492a12e8efa792
|
firebase_auth: 579a0dc15451491cc83fccaa5102296635f24938
|
||||||
FBSDKCoreKit_Basics: 6e578c9bdc7aa1365dbbbde633c9ebb536bcaa98
|
firebase_core: 6f2f753e316765799d88568232ed59e300ff53db
|
||||||
FBSDKLoginKit: 787de205d524c3a4b17d527916f1d066e4361660
|
FirebaseAuth: 0e415d29d846c1dce2fb641e46f35e9888d9bec6
|
||||||
Firebase: 1b810f3d0c0532e27a48f1961f8c0400a668a2cf
|
FirebaseCore: 988754646ab3bd4bdcb740f1bfe26b9f6c0d5f2a
|
||||||
firebase_auth: dd33e93fce72a1c72040f7380dacf06e89db5705
|
FirebaseCoreInternal: 29b76f784d607df8b2a1259d73c3f04f1210137b
|
||||||
firebase_core: 5c0bb0ca7d0e70480a68a6e9ad9bf55d1edd5305
|
|
||||||
FirebaseAuth: 493382cf533cc45e2862b00e9aa4cfe4c98daf71
|
|
||||||
FirebaseCore: 97f48a3a567a72b8d4daa0f03c3aadb78df4e995
|
|
||||||
FirebaseCoreInternal: 96d75228e10fd369564da51bd898414eb0f54df5
|
|
||||||
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
|
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
|
||||||
flutter_facebook_auth: 361ac7a57263ebf327f26089507ead0d66558ee8
|
|
||||||
google_sign_in_ios: 4f85eb9f937450765c8573bb85fd8cd6a5af675c
|
google_sign_in_ios: 4f85eb9f937450765c8573bb85fd8cd6a5af675c
|
||||||
GoogleSignIn: 5651ce3a61e56ca864160e79b484cd9ed3f49b7a
|
GoogleSignIn: 5651ce3a61e56ca864160e79b484cd9ed3f49b7a
|
||||||
GoogleUtilities: 1d20a6ad97ef46f67bbdec158ce00563a671ebb7
|
GoogleUtilities: bad72cb363809015b1f7f19beb1f1cd23c589f95
|
||||||
GTMAppAuth: 0ff230db599948a9ad7470ca667337803b3fc4dd
|
GTMAppAuth: 0ff230db599948a9ad7470ca667337803b3fc4dd
|
||||||
GTMSessionFetcher: ffbb25ec00ebcb5201adab0a56d808f6f1902d9f
|
GTMSessionFetcher: 3a63d75eecd6aa32c2fc79f578064e1214dfdec2
|
||||||
PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb
|
PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb
|
||||||
sign_in_with_apple: f3bf75217ea4c2c8b91823f225d70230119b8440
|
|
||||||
twitter_login: 2794db69b7640681171b17b3c2c84ad9dfb4a57f
|
|
||||||
|
|
||||||
PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3
|
PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3
|
||||||
|
|
||||||
|
@ -28,6 +28,17 @@
|
|||||||
<string>LaunchScreen</string>
|
<string>LaunchScreen</string>
|
||||||
<key>UIMainStoryboardFile</key>
|
<key>UIMainStoryboardFile</key>
|
||||||
<string>Main</string>
|
<string>Main</string>
|
||||||
|
<key>CFBundleURLTypes</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleTypeRole</key>
|
||||||
|
<string>Editor</string>
|
||||||
|
<key>CFBundleURLSchemes</key>
|
||||||
|
<array>
|
||||||
|
<string>com.googleusercontent.apps.405351917235-2jv4ff02kovoim58f8d6d0rsa14apgkj</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
<key>UISupportedInterfaceOrientations</key>
|
<key>UISupportedInterfaceOrientations</key>
|
||||||
<array>
|
<array>
|
||||||
<string>UIInterfaceOrientationPortrait</string>
|
<string>UIInterfaceOrientationPortrait</string>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"file_generated_by": "FlutterFire CLI",
|
"file_generated_by": "FlutterFire CLI",
|
||||||
"purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory",
|
"purpose": "FirebaseAppID & ProjectID for this Firebase app in this directory",
|
||||||
"GOOGLE_APP_ID": "1:136771801992:ios:bcdca68d2b7d227097203d",
|
"GOOGLE_APP_ID": "1:405351917235:ios:869f0ad8ace08db899f2c6",
|
||||||
"FIREBASE_PROJECT_ID": "tchat-beta",
|
"FIREBASE_PROJECT_ID": "meerabel-dev",
|
||||||
"GCM_SENDER_ID": "136771801992"
|
"GCM_SENDER_ID": "405351917235"
|
||||||
}
|
}
|
@ -18,9 +18,47 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:example_router/core/dependency_injection/get_it.dart';
|
import 'package:example_router/core/dependency_injection/get_it.dart';
|
||||||
import 'package:example_router/core/utils/app_bloc_observer.dart';
|
import 'package:example_router/core/utils/app_bloc_observer.dart';
|
||||||
|
import 'package:example_router/firebase_options.dart';
|
||||||
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
|
class MockSettings {
|
||||||
|
static MockSettings? _instance;
|
||||||
|
|
||||||
|
/// Data source mode
|
||||||
|
late bool enable = false;
|
||||||
|
|
||||||
|
MockSettings._(this.enable);
|
||||||
|
|
||||||
|
factory MockSettings.enable() {
|
||||||
|
_instance ??= MockSettings._(true);
|
||||||
|
if (_instance!.enable != true) {
|
||||||
|
throw Exception('Mock already initialized in: ${_instance!.enable}');
|
||||||
|
}
|
||||||
|
return _instance!;
|
||||||
|
}
|
||||||
|
|
||||||
|
factory MockSettings.disable() {
|
||||||
|
_instance ??= MockSettings._(false);
|
||||||
|
if (_instance!.enable != false) {
|
||||||
|
throw Exception('Mock already initialized in: ${_instance!.enable}');
|
||||||
|
}
|
||||||
|
return _instance!;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool isEnable() {
|
||||||
|
if (_instance == null) {
|
||||||
|
throw Exception('MockSettings not initialized!');
|
||||||
|
}
|
||||||
|
return _instance!.enable == true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool isDisable() {
|
||||||
|
return !isEnable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> bootstrap(FutureOr<Widget> Function() builder) async {
|
Future<void> bootstrap(FutureOr<Widget> Function() builder) async {
|
||||||
await runZonedGuarded(
|
await runZonedGuarded(
|
||||||
() async {
|
() async {
|
||||||
@ -30,6 +68,12 @@ Future<void> bootstrap(FutureOr<Widget> Function() builder) async {
|
|||||||
FlutterError.onError = (details) {
|
FlutterError.onError = (details) {
|
||||||
debugPrint(details.toString());
|
debugPrint(details.toString());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (MockSettings.isDisable()) {
|
||||||
|
await Firebase.initializeApp(
|
||||||
|
options: DefaultFirebaseOptions.currentPlatform,
|
||||||
|
);
|
||||||
|
}
|
||||||
await GetItInitializer.init();
|
await GetItInitializer.init();
|
||||||
|
|
||||||
runApp(await builder());
|
runApp(await builder());
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
// 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:example_router/bootstrap.dart';
|
||||||
|
import 'package:example_router/firebase_options.dart';
|
||||||
import 'package:get_it/get_it.dart';
|
import 'package:get_it/get_it.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';
|
||||||
@ -24,7 +26,8 @@ abstract class GetItInitializer {
|
|||||||
static Future<void> init() async {
|
static Future<void> init() async {
|
||||||
getIt
|
getIt
|
||||||
..registerLazySingleton<AuthenticationRemoteDataSource>(
|
..registerLazySingleton<AuthenticationRemoteDataSource>(
|
||||||
() => AuthenticationMockDataSourceImpl(registeredAccounts: [
|
MockSettings.isEnable()
|
||||||
|
? () => AuthenticationMockDataSourceImpl(registeredAccounts: [
|
||||||
Pair(
|
Pair(
|
||||||
AccountModel(
|
AccountModel(
|
||||||
uid: '1',
|
uid: '1',
|
||||||
@ -45,7 +48,10 @@ abstract class GetItInitializer {
|
|||||||
),
|
),
|
||||||
'tata1234',
|
'tata1234',
|
||||||
),
|
),
|
||||||
]),
|
])
|
||||||
|
: () => AuthenticationFirebaseDataSourceImpl(
|
||||||
|
googleSignIn: GoogleSignIn(
|
||||||
|
clientId: DefaultFirebaseOptions.ios.iosClientId)),
|
||||||
)
|
)
|
||||||
..registerLazySingleton<AuthenticationCacheDataSource<int>>(
|
..registerLazySingleton<AuthenticationCacheDataSource<int>>(
|
||||||
() => AuthenticationCacheDataSourceImpl<int>(),
|
() => AuthenticationCacheDataSourceImpl<int>(),
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
// File generated by FlutterFire CLI.
|
||||||
|
// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members
|
||||||
|
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
|
||||||
|
import 'package:flutter/foundation.dart'
|
||||||
|
show defaultTargetPlatform, kIsWeb, TargetPlatform;
|
||||||
|
|
||||||
|
/// Default [FirebaseOptions] for use with your Firebase apps.
|
||||||
|
///
|
||||||
|
/// Example:
|
||||||
|
/// ```dart
|
||||||
|
/// import 'firebase_options.dart';
|
||||||
|
/// // ...
|
||||||
|
/// await Firebase.initializeApp(
|
||||||
|
/// options: DefaultFirebaseOptions.currentPlatform,
|
||||||
|
/// );
|
||||||
|
/// ```
|
||||||
|
class DefaultFirebaseOptions {
|
||||||
|
static FirebaseOptions get currentPlatform {
|
||||||
|
if (kIsWeb) {
|
||||||
|
throw UnsupportedError(
|
||||||
|
'DefaultFirebaseOptions have not been configured for web - '
|
||||||
|
'you can reconfigure this by running the FlutterFire CLI again.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
switch (defaultTargetPlatform) {
|
||||||
|
case TargetPlatform.android:
|
||||||
|
throw UnsupportedError(
|
||||||
|
'DefaultFirebaseOptions have not been configured for android - '
|
||||||
|
'you can reconfigure this by running the FlutterFire CLI again.',
|
||||||
|
);
|
||||||
|
case TargetPlatform.iOS:
|
||||||
|
return ios;
|
||||||
|
case TargetPlatform.macOS:
|
||||||
|
throw UnsupportedError(
|
||||||
|
'DefaultFirebaseOptions have not been configured for macos - '
|
||||||
|
'you can reconfigure this by running the FlutterFire CLI again.',
|
||||||
|
);
|
||||||
|
case TargetPlatform.windows:
|
||||||
|
throw UnsupportedError(
|
||||||
|
'DefaultFirebaseOptions have not been configured for windows - '
|
||||||
|
'you can reconfigure this by running the FlutterFire CLI again.',
|
||||||
|
);
|
||||||
|
case TargetPlatform.linux:
|
||||||
|
throw UnsupportedError(
|
||||||
|
'DefaultFirebaseOptions have not been configured for linux - '
|
||||||
|
'you can reconfigure this by running the FlutterFire CLI again.',
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
throw UnsupportedError(
|
||||||
|
'DefaultFirebaseOptions are not supported for this platform.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const FirebaseOptions ios = FirebaseOptions(
|
||||||
|
apiKey: 'AIzaSyDDmtf0KN7Xw12_pqUsxoBfAxMuvCMmMmk',
|
||||||
|
appId: '1:405351917235:ios:869f0ad8ace08db899f2c6',
|
||||||
|
messagingSenderId: '405351917235',
|
||||||
|
projectId: 'meerabel-dev',
|
||||||
|
storageBucket: 'meerabel-dev.appspot.com',
|
||||||
|
androidClientId:
|
||||||
|
'405351917235-4g1dh3475tq6t1sa2qoh7ol60nf4ta05.apps.googleusercontent.com',
|
||||||
|
iosClientId:
|
||||||
|
'405351917235-2jv4ff02kovoim58f8d6d0rsa14apgkj.apps.googleusercontent.com',
|
||||||
|
iosBundleId: 'com.example.exampleRouter',
|
||||||
|
);
|
||||||
|
}
|
@ -18,5 +18,6 @@ import 'package:example_router/bootstrap.dart';
|
|||||||
import 'package:example_router/presentation/features/app/app.dart';
|
import 'package:example_router/presentation/features/app/app.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
MockSettings.enable();
|
||||||
bootstrap(App.new);
|
bootstrap(App.new);
|
||||||
}
|
}
|
||||||
|
@ -14,4 +14,10 @@
|
|||||||
// 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/>.
|
||||||
|
|
||||||
export 'cryptography.dart';
|
import 'package:example_router/bootstrap.dart';
|
||||||
|
import 'package:example_router/presentation/features/app/app.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
MockSettings.disable();
|
||||||
|
bootstrap(App.new);
|
||||||
|
}
|
@ -94,6 +94,22 @@ class _SignInAnonymouslyButton extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _SignInWithGoogleButton extends StatelessWidget {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SubmitBuilder<SignInCubit<int>>(
|
||||||
|
builder: ((context, cubit, status) {
|
||||||
|
return status.isSubmissionInProgress
|
||||||
|
? const CircularProgressIndicator()
|
||||||
|
: ElevatedButton(
|
||||||
|
onPressed: () => cubit.signInWithGoogle(),
|
||||||
|
child: const Text('Sign in Google'),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class SignInForm extends StatelessWidget {
|
class SignInForm extends StatelessWidget {
|
||||||
const SignInForm({Key? key}) : super(key: key);
|
const SignInForm({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@ -116,6 +132,8 @@ class SignInForm extends StatelessWidget {
|
|||||||
_SignInButton(),
|
_SignInButton(),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
_SignInAnonymouslyButton(),
|
_SignInAnonymouslyButton(),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
_SignInWithGoogleButton(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -30,10 +30,12 @@ class SubPage extends StatelessWidget {
|
|||||||
title: const Text('Sub'),
|
title: const Text('Sub'),
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => context.read<AuthenticationCubit<int>>().signOut(),
|
onPressed: () =>
|
||||||
|
context.read<AuthenticationCubit<int>>().signOut(),
|
||||||
icon: const Icon(Icons.logout_rounded)),
|
icon: const Icon(Icons.logout_rounded)),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => context.read<AuthenticationRepository<int>>().refresh(),
|
onPressed: () =>
|
||||||
|
context.read<AuthenticationRepository<int>>().refresh(),
|
||||||
icon: const Icon(Icons.refresh))
|
icon: const Icon(Icons.refresh))
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -18,4 +18,3 @@ export 'constants/form_field.dart';
|
|||||||
export 'constants/form_name.dart';
|
export 'constants/form_name.dart';
|
||||||
export 'enums/enums.dart';
|
export 'enums/enums.dart';
|
||||||
export 'exceptions/exceptions.dart';
|
export 'exceptions/exceptions.dart';
|
||||||
export 'utils/utils.dart';
|
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
// 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 'dart:convert';
|
|
||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:crypto/crypto.dart';
|
|
||||||
|
|
||||||
class Cryptography {
|
|
||||||
/// Generates a cryptographically secure random nonce, to be included in a
|
|
||||||
/// credential request.
|
|
||||||
static String generateNonce([int length = 32]) {
|
|
||||||
const charset =
|
|
||||||
'0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._';
|
|
||||||
final random = Random.secure();
|
|
||||||
return List.generate(length, (_) => charset[random.nextInt(charset.length)])
|
|
||||||
.join();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the sha256 hash of [input] in hex notation.
|
|
||||||
static String sha256ofString(String input) {
|
|
||||||
final bytes = utf8.encode(input);
|
|
||||||
final digest = sha256.convert(bytes);
|
|
||||||
return digest.toString();
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
||||||
|
@ -14,34 +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:firebase_auth/firebase_auth.dart';
|
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({
|
||||||
|
FirebaseAuth? firebaseAuth,
|
||||||
|
GoogleSignIn? googleSignIn,
|
||||||
|
}) : _firebaseAuth = firebaseAuth ?? FirebaseAuth.instance,
|
||||||
|
_googleSignIn = googleSignIn ?? GoogleSignIn();
|
||||||
|
|
||||||
AuthenticationFirebaseDataSourceImpl({FirebaseAuth? firebaseAuth})
|
|
||||||
: _firebaseAuth = firebaseAuth ?? FirebaseAuth.instance;
|
|
||||||
final FirebaseAuth _firebaseAuth;
|
final FirebaseAuth _firebaseAuth;
|
||||||
|
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,
|
||||||
@ -54,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 (_) {
|
||||||
@ -80,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 (_) {
|
||||||
@ -121,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
|
||||||
@ -170,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 (_) {
|
||||||
@ -182,6 +161,35 @@ 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;
|
||||||
|
return AccountModelFirebase.fromFirebaseUser(user);
|
||||||
|
} on FirebaseAuthException catch (e) {
|
||||||
|
throw SignInWithGoogleFailureFirebase.fromCode(e.code);
|
||||||
|
} catch (_) {
|
||||||
|
throw SignInWithGoogleFailureFirebase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> verifyPasswordResetCode({required String code}) async {
|
Future<bool> verifyPasswordResetCode({required String code}) async {
|
||||||
try {
|
try {
|
||||||
@ -215,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 (_) {
|
||||||
@ -232,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 (_) {
|
||||||
@ -249,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 (_) {
|
||||||
|
@ -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,
|
||||||
@ -112,7 +111,26 @@ class AuthenticationMockDataSourceImpl extends AuthenticationRemoteDataSource {
|
|||||||
uid: 'mock-id-anom',
|
uid: 'mock-id-anom',
|
||||||
emailVerified: false,
|
emailVerified: false,
|
||||||
isAnonymous: true,
|
isAnonymous: true,
|
||||||
providerId: 'wyatt',
|
providerId: 'wyatt-studio.fr',
|
||||||
|
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> signInWithGoogle() async {
|
||||||
|
await _randomDelay();
|
||||||
|
final creation = DateTime.now();
|
||||||
|
final mock = AccountModel(
|
||||||
|
uid: 'mock-id-google',
|
||||||
|
emailVerified: true,
|
||||||
|
isAnonymous: false,
|
||||||
|
providerId: 'google.com',
|
||||||
creationTime: creation,
|
creationTime: creation,
|
||||||
lastSignInTime: creation,
|
lastSignInTime: creation,
|
||||||
isNewUser: creation == creation,
|
isNewUser: creation == creation,
|
||||||
|
@ -72,7 +72,8 @@ class AccountModel extends Account {
|
|||||||
String? phoneNumber,
|
String? phoneNumber,
|
||||||
String? photoURL,
|
String? photoURL,
|
||||||
String? providerId,
|
String? providerId,
|
||||||
}) => AccountModel(
|
}) =>
|
||||||
|
AccountModel(
|
||||||
uid: uid ?? this.uid,
|
uid: uid ?? this.uid,
|
||||||
email: email ?? this.email,
|
email: email ?? this.email,
|
||||||
creationTime: creationTime ?? this.creationTime,
|
creationTime: creationTime ?? this.creationTime,
|
||||||
|
@ -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!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -29,7 +29,8 @@ class AccountWrapperModel<T> extends AccountWrapper<T> {
|
|||||||
AccountWrapperModel<T> copyWith({
|
AccountWrapperModel<T> copyWith({
|
||||||
Account? account,
|
Account? account,
|
||||||
T? data,
|
T? data,
|
||||||
}) => AccountWrapperModel<T>(
|
}) =>
|
||||||
|
AccountWrapperModel<T>(
|
||||||
account ?? this.account,
|
account ?? this.account,
|
||||||
data ?? this.data,
|
data ?? this.data,
|
||||||
);
|
);
|
||||||
|
@ -41,8 +41,7 @@ typedef OnAuthChange<T> = FutureOrResult<T?> Function(
|
|||||||
);
|
);
|
||||||
|
|
||||||
class AuthenticationRepositoryImpl<T extends Object>
|
class AuthenticationRepositoryImpl<T extends Object>
|
||||||
extends AuthenticationRepository<T> { // Semaphore
|
extends AuthenticationRepository<T> {
|
||||||
|
|
||||||
AuthenticationRepositoryImpl({
|
AuthenticationRepositoryImpl({
|
||||||
required AuthenticationCacheDataSource<T> authenticationCacheDataSource,
|
required AuthenticationCacheDataSource<T> authenticationCacheDataSource,
|
||||||
required AuthenticationRemoteDataSource authenticationRemoteDataSource,
|
required AuthenticationRemoteDataSource authenticationRemoteDataSource,
|
||||||
@ -295,6 +294,17 @@ class AuthenticationRepositoryImpl<T extends Object>
|
|||||||
(error) => error,
|
(error) => error,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
FutureOrResult<Account> signInWithGoogle() =>
|
||||||
|
Result.tryCatchAsync<Account, AppException, AppException>(
|
||||||
|
() async {
|
||||||
|
final account =
|
||||||
|
await _authenticationRemoteDataSource.signInWithGoogle();
|
||||||
|
return account;
|
||||||
|
},
|
||||||
|
(error) => error,
|
||||||
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
FutureOrResult<bool> verifyPasswordResetCode({required String code}) =>
|
FutureOrResult<bool> verifyPasswordResetCode({required String code}) =>
|
||||||
Result.tryCatchAsync<bool, AppException, AppException>(
|
Result.tryCatchAsync<bool, AppException, AppException>(
|
||||||
|
@ -49,6 +49,8 @@ abstract class AuthenticationRemoteDataSource extends BaseRemoteDataSource {
|
|||||||
|
|
||||||
Future<Account> signInAnonymously();
|
Future<Account> signInAnonymously();
|
||||||
|
|
||||||
|
Future<Account> signInWithGoogle();
|
||||||
|
|
||||||
Future<Account> updateEmail({required String email});
|
Future<Account> updateEmail({required String email});
|
||||||
|
|
||||||
Future<Account> updatePassword({required String password});
|
Future<Account> updatePassword({required String password});
|
||||||
|
@ -73,6 +73,13 @@ abstract class AuthenticationRepository<T> extends BaseRepository {
|
|||||||
/// {@endtemplate}
|
/// {@endtemplate}
|
||||||
FutureOrResult<Account> signInAnonymously();
|
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}
|
/// {@template signin_pwd}
|
||||||
/// Signs in with the provided [email] and [password].
|
/// Signs in with the provided [email] and [password].
|
||||||
///
|
///
|
||||||
|
@ -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,
|
||||||
|
@ -17,11 +17,8 @@
|
|||||||
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._({required this.status, this.accountWrapper});
|
: this._(status: AuthenticationStatus.unauthenticated);
|
||||||
|
|
||||||
const AuthenticationState.unknown()
|
|
||||||
: this._(status: AuthenticationStatus.unknown);
|
|
||||||
|
|
||||||
const AuthenticationState.authenticated(AccountWrapper<Extra> accountWrapper)
|
const AuthenticationState.authenticated(AccountWrapper<Extra> accountWrapper)
|
||||||
: this._(
|
: this._(
|
||||||
@ -29,8 +26,10 @@ class AuthenticationState<Extra> extends Equatable {
|
|||||||
accountWrapper: accountWrapper,
|
accountWrapper: accountWrapper,
|
||||||
);
|
);
|
||||||
|
|
||||||
const AuthenticationState.unauthenticated()
|
const AuthenticationState.unknown()
|
||||||
: this._(status: AuthenticationStatus.unauthenticated);
|
: this._(status: AuthenticationStatus.unknown);
|
||||||
|
|
||||||
|
const AuthenticationState._({required this.status, this.accountWrapper});
|
||||||
final AuthenticationStatus status;
|
final AuthenticationStatus status;
|
||||||
final AccountWrapper<Extra>? accountWrapper;
|
final AccountWrapper<Extra>? accountWrapper;
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ import 'package:wyatt_form_bloc/wyatt_form_bloc.dart';
|
|||||||
part 'email_verification_state.dart';
|
part 'email_verification_state.dart';
|
||||||
|
|
||||||
class EmailVerificationCubit<Extra> extends Cubit<EmailVerificationState> {
|
class EmailVerificationCubit<Extra> extends Cubit<EmailVerificationState> {
|
||||||
|
|
||||||
EmailVerificationCubit({
|
EmailVerificationCubit({
|
||||||
required AuthenticationRepository<Extra> authenticationRepository,
|
required AuthenticationRepository<Extra> authenticationRepository,
|
||||||
}) : _authenticationRepository = authenticationRepository,
|
}) : _authenticationRepository = authenticationRepository,
|
||||||
|
@ -25,7 +25,6 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart';
|
|||||||
part 'password_reset_state.dart';
|
part 'password_reset_state.dart';
|
||||||
|
|
||||||
class PasswordResetCubit<Extra> extends FormDataCubit<PasswordResetState> {
|
class PasswordResetCubit<Extra> extends FormDataCubit<PasswordResetState> {
|
||||||
|
|
||||||
PasswordResetCubit({
|
PasswordResetCubit({
|
||||||
required AuthenticationRepository<Extra> authenticationRepository,
|
required AuthenticationRepository<Extra> authenticationRepository,
|
||||||
}) : _authenticationRepository = authenticationRepository,
|
}) : _authenticationRepository = authenticationRepository,
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
part of 'password_reset_cubit.dart';
|
part of 'password_reset_cubit.dart';
|
||||||
|
|
||||||
class PasswordResetState extends FormDataState {
|
class PasswordResetState extends FormDataState {
|
||||||
|
|
||||||
const PasswordResetState({
|
const PasswordResetState({
|
||||||
required super.form,
|
required super.form,
|
||||||
super.status = FormStatus.pure,
|
super.status = FormStatus.pure,
|
||||||
|
@ -23,7 +23,6 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart';
|
|||||||
part 'sign_in_state.dart';
|
part 'sign_in_state.dart';
|
||||||
|
|
||||||
class SignInCubit<Extra> extends FormDataCubit<SignInState> {
|
class SignInCubit<Extra> extends FormDataCubit<SignInState> {
|
||||||
|
|
||||||
SignInCubit({
|
SignInCubit({
|
||||||
required AuthenticationRepository<Extra> authenticationRepository,
|
required AuthenticationRepository<Extra> authenticationRepository,
|
||||||
}) : _authenticationRepository = authenticationRepository,
|
}) : _authenticationRepository = authenticationRepository,
|
||||||
@ -206,4 +205,24 @@ class SignInCubit<Extra> extends FormDataCubit<SignInState> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> signInWithGoogle() async {
|
||||||
|
if (state.status.isSubmissionInProgress) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// TODO(wyatt): maybe emit new state (to not carry an old errorMessage)
|
||||||
|
emit(state.copyWith(status: FormStatus.submissionInProgress));
|
||||||
|
|
||||||
|
final uid = await _authenticationRepository.signInWithGoogle();
|
||||||
|
|
||||||
|
emit(
|
||||||
|
uid.fold(
|
||||||
|
(value) => state.copyWith(status: FormStatus.submissionSuccess),
|
||||||
|
(error) => state.copyWith(
|
||||||
|
errorMessage: error.message,
|
||||||
|
status: FormStatus.submissionFailure,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
part of 'sign_in_cubit.dart';
|
part of 'sign_in_cubit.dart';
|
||||||
|
|
||||||
class SignInState extends FormDataState {
|
class SignInState extends FormDataState {
|
||||||
|
|
||||||
const SignInState({
|
const SignInState({
|
||||||
required super.form,
|
required super.form,
|
||||||
super.status = FormStatus.pure,
|
super.status = FormStatus.pure,
|
||||||
|
@ -25,7 +25,6 @@ import 'package:wyatt_type_utils/wyatt_type_utils.dart';
|
|||||||
part 'sign_up_state.dart';
|
part 'sign_up_state.dart';
|
||||||
|
|
||||||
class SignUpCubit<Extra> extends FormDataCubit<SignUpState> {
|
class SignUpCubit<Extra> extends FormDataCubit<SignUpState> {
|
||||||
|
|
||||||
SignUpCubit({
|
SignUpCubit({
|
||||||
required AuthenticationRepository<Extra> authenticationRepository,
|
required AuthenticationRepository<Extra> authenticationRepository,
|
||||||
}) : _authenticationRepository = authenticationRepository,
|
}) : _authenticationRepository = authenticationRepository,
|
||||||
|
@ -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,
|
||||||
|
@ -17,4 +17,7 @@
|
|||||||
/// An authentication library for BLoC.
|
/// An authentication library for BLoC.
|
||||||
library wyatt_authentication_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';
|
export 'src/src.dart';
|
||||||
|
@ -10,17 +10,12 @@ environment:
|
|||||||
flutter: ">=1.17.0"
|
flutter: ">=1.17.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter: { sdk: flutter }
|
||||||
sdk: flutter
|
|
||||||
|
|
||||||
crypto: ^3.0.2
|
crypto: ^3.0.2
|
||||||
flutter_bloc: ^8.1.1
|
flutter_bloc: ^8.1.1
|
||||||
equatable: ^2.0.5
|
equatable: ^2.0.5
|
||||||
firebase_auth: ^4.1.1
|
firebase_auth: ^4.2.0
|
||||||
google_sign_in: ^5.3.0
|
google_sign_in: ^5.4.2
|
||||||
flutter_facebook_auth: ^4.3.0
|
|
||||||
sign_in_with_apple: ^3.3.0
|
|
||||||
twitter_login: ^4.2.3
|
|
||||||
rxdart: ^0.27.7
|
rxdart: ^0.27.7
|
||||||
|
|
||||||
wyatt_form_bloc:
|
wyatt_form_bloc:
|
||||||
@ -36,8 +31,7 @@ dependencies:
|
|||||||
version: ^0.0.4
|
version: ^0.0.4
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test: { sdk: flutter }
|
||||||
sdk: flutter
|
|
||||||
bloc_test: ^9.1.0
|
bloc_test: ^9.1.0
|
||||||
mocktail: ^0.3.0
|
mocktail: ^0.3.0
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user