Skip to content

Commit

Permalink
feat(auth, android): change dynamic to Object
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyokone committed Jul 19, 2022
1 parent d6a62d6 commit 0facb04
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
3 changes: 2 additions & 1 deletion packages/firebase_auth/firebase_auth/lib/src/user.dart
Expand Up @@ -10,6 +10,7 @@ class User {
UserPlatform _delegate;

final FirebaseAuth _auth;
MultiFactor? _multiFactor;

User._(this._auth, this._delegate) {
UserPlatform.verifyExtends(_delegate);
Expand Down Expand Up @@ -422,7 +423,7 @@ class User {
}

MultiFactor get multiFactor {
return MultiFactor._(_delegate.multiFactor);
return _multiFactor ??= MultiFactor._(_delegate.multiFactor);
}

@override
Expand Down
Expand Up @@ -23,6 +23,7 @@ class MethodChannelFirebaseAuth extends FirebaseAuthPlatform {
'plugins.flutter.io/firebase_auth',
);

/// Map of [MethodChannelFirebaseAuth] that can be get with Firebase App Name.
static Map<String, MethodChannelFirebaseAuth>
methodChannelFirebaseAuthInstances =
<String, MethodChannelFirebaseAuth>{};
Expand Down
Expand Up @@ -3,6 +3,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:collection/collection.dart';
import 'package:firebase_auth_platform_interface/firebase_auth_platform_interface.dart';
import 'package:firebase_auth_platform_interface/src/method_channel/method_channel_firebase_auth.dart';
import 'package:firebase_auth_platform_interface/src/method_channel/method_channel_multi_factor.dart';
Expand Down Expand Up @@ -74,15 +75,21 @@ FirebaseException platformExceptionToFirebaseAuthException(
}

FirebaseAuthMultiFactorException parseMultiFactorError(
Map<String, dynamic> details) {
final code = details['code'];
final message = details['message'];
final additionalData = details['additionalData'];
Map<String, Object?> details) {
final code = details['code'] as String?;
final message = details['message'] as String?;
final additionalData = details['additionalData'] as Map<String, Object?>?;

if (additionalData == null) {
throw FirebaseAuthException(
code: "Can't parse multi factor error",
message: message,
);
}

final pigeonMultiFactorInfo =
(additionalData['multiFactorHints'] as List<Object?>)
.where((element) => element != null)
.cast<Object>()
(additionalData['multiFactorHints'] as List<Object?>? ?? [])
.whereNotNull()
.map(
PigeonMultiFactorInfo.decode,
)
Expand All @@ -97,20 +104,28 @@ FirebaseAuthMultiFactorException parseMultiFactorError(

if (auth == null) {
throw FirebaseAuthException(
code: code,
code: code ?? 'Unknown',
message: message,
);
}

final sessionId = additionalData['multiFactorSessionId'] as String?;
final resolverId = additionalData['multiFactorResolverId'] as String?;
if (sessionId == null || resolverId == null) {
throw FirebaseAuthException(
code: "Can't parse multi factor error",
message: message,
);
}
final multiFactorResolver = MethodChannelMultiFactorResolver(
multiFactorInfo,
MultiFactorSession(additionalData['multiFactorSessionId']),
additionalData['multiFactorResolverId'],
MultiFactorSession(sessionId),
resolverId,
auth,
);

return FirebaseAuthMultiFactorException(
code: code,
code: code ?? 'Unknown',
message: message,
resolver: multiFactorResolver,
);
Expand Down
@@ -1,13 +1,11 @@
import 'package:collection/collection.dart';
import 'package:firebase_auth_platform_interface/firebase_auth_platform_interface.dart';
import 'package:firebase_auth_platform_interface/src/pigeon/messages.pigeon.dart';

List<MultiFactorInfo> multiFactorInfoPigeonToObject(
List<PigeonMultiFactorInfo?> pigeonMultiFactorInfo,
) {
return pigeonMultiFactorInfo
.where((element) => element != null)
.cast<PigeonMultiFactorInfo>()
.map((e) {
return pigeonMultiFactorInfo.whereNotNull().map((e) {
if (e.phoneNumber != null) {
return PhoneMultiFactorInfo(
displayName: e.displayName,
Expand Down
Expand Up @@ -11,6 +11,7 @@ environment:
flutter: '>=1.9.1+hotfix.5'

dependencies:
collection: ^1.16.0
firebase_core: ^1.10.0
flutter:
sdk: flutter
Expand Down

0 comments on commit 0facb04

Please sign in to comment.