When i sign in with 2FA (email provider, phone provider) i just do signInWithEmailAndPassword, then i catch FirebaseAuthMultiFactorException, get MultiFactorResolver to resolve second factor and sign in successfully. Similar for sign up.
The problem arises when i try to modify user data, like to change password.
I tried the same flow as we do for sign in/ sign up flow, but it doesn't work, it returns FirebaseException instead of FirebaseAuthMultifactorException:
Future<void> changePassword({required String email, required String password, required String newPassword}) async{
final user = _firebaseAuth.currentUser!;
try{
final cred = EmailAuthProvider.credential(email: email, password: password);
await user.reauthenticateWithCredential(cred);
} on FirebaseAuthMultiFactorException catch(e){
log("i need to get resolver here but this line is never executed");
} on FirebaseException catch(e){
log("firebase exception, which doesn`t provide resolver");
rethrow;
}
}
The output is following:
[log] firebase exception, which doesn`t provide resolver
E/flutter (18929): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_auth/second-factor-required] Please complete a second factor challenge to finish signing into this account.
E/flutter (18929): #0 parseMultiFactorError (package:firebase_auth_platform_interface/src/method_channel/utils/exception.dart:106:5)
E/flutter (18929): #1 platformExceptionToFirebaseAuthException (package:firebase_auth_platform_interface/src/method_channel/utils/exception.dart:49:14)
E/flutter (18929): #2 convertPlatformException (package:firebase_auth_platform_interface/src/method_channel/utils/exception.dart:23:5)
E/flutter (18929): #3 MethodChannelUser.reauthenticateWithCredential (package:firebase_auth_platform_interface/src/method_channel/method_channel_user.dart:181:7)
E/flutter (18929): <asynchronous suspension>
E/flutter (18929): #4 User.reauthenticateWithCredential (package:firebase_auth/src/user.dart:452:7)
E/flutter (18929): <asynchronous suspension>
E/flutter (18929): #5 AuthRepository.changePassword (package:vendor/repositories/auth/auth_repository.dart:43:7)
E/flutter (18929): <asynchronous suspension>
E/flutter (18929): #6 new AuthBloc.<anonymous closure> (package:vendor/blocs/auth_bloc/auth_bloc.dart:50:7)
E/flutter (18929): <asynchronous suspension>
E/flutter (18929): #7 Bloc.on.<anonymous closure>.handleEvent (package:bloc/src/bloc.dart:226:13)
E/flutter (18929): <asynchronous suspension>
That was flutter firebase-sdk issue that was fixed since firebase_auth 4.1.0.
Changelog:
FIX: properly propagate the FirebaseAuthMultiFactorException for all reauthenticate and link methods (#9700). (9ad97c82)
Related
I've a Flutter App Project which contains levels of permission, so, my main objective with this is allow an manager delete a user, making him not allowed anymore to login, deleting from FirebaseAuth.
I've a permission called "Deactivated" to prevent the user from logging in, but i really want to remove from FirebaseAuth too.
The only way I've found is using the Firebase Cloud Functions, so I tried to do very similar to FlutterFire Docs
When i execute using PostMan, it works perfectly, the user test is deleted as expected:
METHOD: Post
Url: https://us-central1-<DATABASE_NAME>.cloudfunctions.net/deleteUserByEmail/
Body -> Raw:
{
"userEmail": "test#gmail.com"
}
My index.js
const functions = require("firebase-functions");
const admin = require('firebase-admin');
admin.initializeApp();
exports.deleteUserByEmail = functions.https.onRequest(async (request, response) => {
try {
const userEmail = request.body.userEmail;
admin.auth().getUserByEmail(userEmail)
.then(userRecord => {
const uid = userRecord.uid
return admin.auth().deleteUser(uid)
.then(() => {
console.log("Successfully deleted user");
response.status(200).send('Delete User');
return
})
}).catch(error => {
throw new functions.https.HttpsError('invalid-argument', error.HttpsError);
});
} catch (err) {
throw new functions.https.HttpsError('invalid-argument', "Error passing arguments into");
}
})
Part of my code that calls the code Flutter code:
HttpsCallable callable =
FirebaseFunctions.instance.httpsCallable('deleteUserByEmail');
try {
final resp = await callable.call(<String, dynamic>{
"userEmail" : userModel.email,
});
} on FirebaseFunctionsException catch (e) {
debugPrint(e.toString());
}
Once i tap the button, i receive this error code:
E/flutter (20323): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_functions/internal] INTERNAL
E/flutter (20323):
E/flutter (20323): #0 StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:653
E/flutter (20323): #1 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:296
E/flutter (20323): <asynchronous suspension>
E/flutter (20323): #2 MethodChannelHttpsCallable.call
package:cloud_functions_platform_interface/…/method_channel/method_channel_https_callable.dart:23
E/flutter (20323): <asynchronous suspension>
E/flutter (20323): #3 HttpsCallable.call
package:cloud_functions/src/https_callable.dart:49
E/flutter (20323): <asynchronous suspension>
E/flutter (20323):
E/flutter (20323): #0 StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:653
E/flutter (20323): #1 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:296
E/flutter (20323): <asynchronous suspension>
E/flutter (20323): #2 MethodChannelHttpsCallable.call
package:cloud_functions_platform_interface/…/method_channel/method_channel_https_callable.dart:23
After some research I've found that some people had that problem when their code wasn't inside a tryCatch block, but mine was since ever...
I've tried to start admin.initializeApp() parsing the credentials and databaseURL even though my FlutterFire CLI is configured, but didn't work too.
Flutter&Dart, when I try to send an udp packet and the screen of the emulator is turned off the sending fails. Ok.
The mystery is I cannot catch the failing in any way.
Udp socket send() is not async so try&catch is correct. If I add await nothing changes. If I try to append .catchError it is not permitted because it is not an async method.
try {
print(_udpSocket.toString()); //It prints Instance of '_RawDatagramSocket'
_udpSocket!.send(_packet,_serverAddress!,Server_UdpPort); //Send packet
} catch (exception) {
print("aaaaaaaaaaaa"); //It never prints aaaaa, it never executes this code
print(exception.toString());
}
Error in console:
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: SocketException: Send failed (OS Error: Operation not permitted, errno = 1), address = 0.0.0.0, port = 0
E/flutter (25939): #0 _NativeSocket.send (dart:io-patch/socket_patch.dart:1213:34)
E/flutter (25939): #1 _RawDatagramSocket.send (dart:io-patch/socket_patch.dart:2460:15)
E/flutter (25939): #2 ClassServerConnection._handleOutcomingUdpStreamPacketsQueueEvent_async (package:meet2/2_1_4_ClassServerConnection.dart:1129:29)
E/flutter (25939): #3 ClassServerConnection._handleOutcomingUdpStreamPackets.<anonymous closure> (package:meet2/2_1_4_ClassServerConnection.dart:1090:93)
E/flutter (25939): #4 ClassQueue.callEvent.<anonymous closure> (package:meet2/2_1_2_ClassQueue.dart:78:68)
E/flutter (25939): #5 new Future.delayed.<anonymous closure> (dart:async/future.dart:424:39)
E/flutter (25939): #6 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter (25939): #7 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
E/flutter (25939): #8 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
E/flutter (25939): #9 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
I have this code below which plays a sound every time I hit a button.
AudioPlayer player = AudioPlayer();
Future<void> playSound({required String soundStr}) async {
player.setAsset(soundStr);
player.play();
}
But whenever I hit the button fast, sometimes it will show this error. How can I eliminate this error? I tried adding player.stop(); but it still the same.
E/flutter ( 4312): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(abort, Loading interrupted, null, null)
E/flutter ( 4312): #0 AudioPlayer._setPlatformActive.checkInterruption (package:just_audio/just_audio.dart:1236:7)
E/flutter ( 4312): #1 AudioPlayer._setPlatformActive.setPlatform (package:just_audio/just_audio.dart:1347:11)
E/flutter ( 4312): <asynchronous suspension>
E/flutter ( 4312):
E/flutter ( 4312): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(abort, Loading interrupted, null, null)
E/flutter ( 4312):
Edit: I tried adding await.
Future<void> playSound({required String soundStr}) async {
await player.setAsset(soundStr);
await player.play();
}
If I hit the buttons fast, it will still have error. Though it is now different.
E/flutter (21654): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Connection aborted
E/flutter (21654): #0 AudioPlayer._load (package:just_audio/just_audio.dart:843:11)
E/flutter (21654): <asynchronous suspension>
E/flutter (21654): #1 AudioPlayer.load (package:just_audio/just_audio.dart:770:14)
E/flutter (21654): <asynchronous suspension>
E/flutter (21654): #2 AudioPlayer.setAudioSource (package:just_audio/just_audio.dart:745:18)
E/flutter (21654): <asynchronous suspension>
E/flutter (21654): #3 playSound (package:super_pinoy_quiz/common/generic_methods.dart:396:3)
E/flutter (21654): <asynchronous suspension>
E/flutter (21654):
I'm using this package: just_audio: ^0.9.29
Though I tried using different package but it also encounters the same error when hitting the button fast: audioplayers: ^1.1.1
Both setAsset and play are future method, you can await for setting assets
Future<void> playSound({required String soundStr}) async {
await player.setAsset(soundStr);
await player.play();
}
I have my flutter App integrated with firebase, everything was fine but after i integrate firebase i got error whenever I try to run my app.
My main method looks like this:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(child: MyApp());
}
Error:
E/flutter ( 7922): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception:
PlatformException(firebase_core, FirebaseApp name [DEFAULT] already exists!, null, null)
E/flutter ( 7922): #0 StandardMethodCodec.decodeEnvelope
(package:flutter/src/services/message_codecs.dart:607:7)
E/flutter ( 7922): #1 MethodChannel._invokeMethod
(package:flutter/src/services/platform_channel.dart:177:18)
E/flutter ( 7922): <asynchronous suspension>
E/flutter ( 7922): #2 MethodChannel.invokeMapMethod
(package:flutter/src/services/platform_channel.dart:377:43)
E/flutter ( 7922): <asynchronous suspension>
E/flutter ( 7922): #3 MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:100:40)
E/flutter ( 7922): <asynchronous suspension>
E/flutter ( 7922): #4 Firebase.initializeApp
(package:firebase_core/src/firebase.dart:40:31)
E/flutter ( 7922): <asynchronous suspension>
E/flutter ( 7922): #5 main (package:zunada/main.dart:11:3)
E/flutter ( 7922): <asynchronous suspension>
E/flutter ( 7922):
I had similar issue when create firebase app by flavors using flutterfire CLI. I realized that flutterfire create apps with same name in different projects. Then I tried 2 ways and it works.
1st: manually change app name in each firebase project.
2nd: add param name when initialize such as in main_dev.dart
Example:
await Firebase.initializeApp(
name: "dev-project",
options: DefaultFirebaseOptions.currentPlatform);
I used the same name used in the firebase console as my project ID for consistency, keep in mind that you cannot add spaces to the name (only dashes -).
I am trying to implement the twilio_voice: ^0.0.9 plug in and register my firebase app at the same time but, when I run my registration function I get the error:
E/flutter (27321): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: [firebase_functions/not-found] NOT_FOUND
E/flutter (27321):
E/flutter (27321): #0 StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:607
E/flutter (27321): #1 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:156
E/flutter (27321): <asynchronous suspension>
E/flutter (27321): #2 MethodChannelHttpsCallable.call
package:cloud_functions_platform_interface/…/method_channel/method_channel_https_callable.dart:23
E/flutter (27321): <asynchronous suspension>
E/flutter (27321): #3 HttpsCallable.call
package:cloud_functions/src/https_callable.dart:35
E/flutter (27321): <asynchronous suspension>
E/flutter (27321): #4 _TextScreenState.register
package:buddiesDrivers/CallScreen/TextScreen.dart:72
E/flutter (27321): <asynchronous suspension>
E/flutter (27321):
E/flutter (27321): #0 MethodChannelHttpsCallable.call
package:cloud_functions_platform_interface/…/method_channel/method_channel_https_callable.dart:39
E/flutter (27321): <asynchronous suspension>
E/flutter (27321): #1 HttpsCallable.call
package:cloud_functions/src/https_callable.dart:35
E/flutter (27321): <asynchronous suspension>
I am have firebase implemented and running and I am getting my token when logging in. The app seems to fail when calling the httpsCallable("voice-accessToken") in the app. Here is the function:
register() async {
print("voip-registtering with token ");
print("voip-calling voice-accessToken");
final function =
FirebaseFunctions.instance.httpsCallable("voice-accessToken");
final data = {
"platform": Platform.isIOS ? "iOS" : "Android",
};
final result = await function.call(data);
print("voip-result");
print(result.data);
String androidToken;
if (Platform.isAndroid) {
androidToken = await FirebaseMessaging.instance.getToken();
print("androidToken is " + androidToken);
}
TwilioVoice.instance
.setTokens(accessToken: result.data, deviceToken: androidToken);
}
Any help in the right direction would be appreciated