firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.54k stars 3.93k forks source link

[Firebase_auth]: <When I use signInWithEmailAndPassword without first using the createUserWithEmailAndPassword method, I get the error message [firebase_auth/channel-error] "dev.flutter.pigeon.firebase_auth_platform_interface.FirebaseAuthHostApi.signInWithEmailAndPassword".> #13065

Closed chohangmin closed 2 weeks ago

chohangmin commented 3 weeks ago

Is there an existing issue for this?

Which plugins are affected?

Auth

Which platforms are affected?

Android

Description

When I use signInWithEmailAndPassword without first using the createUserWithEmailAndPassword method, I get the error message [firebase_auth/channel-error] "dev.flutter.pigeon.firebase_auth_platform_interface.FirebaseAuthHostApi.signInWithEmailAndPassword".

I created user info before, and I turn off the app and start the app. I try to sign in using exiting user information. but it didn't work with this error message. [firebase_auth/channel-error] "dev.flutter.pigeon.firebase_auth_platform_interface.FirebaseAuthHostApi.signInWithEmailAndPassword"

However, I create new user information, and I log out (If user create account, and it sign in automatic in my app) and I try sign in exiting user info or just created user info. It work very well, and even no print the error message.

Reproducing the issue

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Firebase.initializeApp(
      options: const FirebaseOptions(
    apiKey: ,
    appId: ,
    messagingSenderId:,
    projectId: '',
    storageBucket: '',
  ));

  runApp(const MyApp());
}

                          if (isSignup) {
                            if (userPickedImage == null) {
                              setState(() {
                                showSpinner = false;
                              });
                              ScaffoldMessenger.of(context).showSnackBar(
                                const SnackBar(
                                  content: Text('Please choose image'),
                                  backgroundColor: Colors.blue,
                                ),
                              );
                              return;
                            }
                            _tryValidation();
                            try {
                              final newUser = await _authentication
                                  .createUserWithEmailAndPassword(
                                email: userEmail,
                                password: userPassword,
                              );

                              final refImage = FirebaseStorage.instance
                                  .ref()
                                  .child('picked_image')
                                  .child('${newUser.user!.uid}.png');

                              await refImage.putFile(userPickedImage!);

                              final url = await refImage.getDownloadURL();

                              await FirebaseFirestore.instance
                                  .collection('user')
                                  .doc(newUser.user!.uid)
                                  .set({
                                'userName': userName,
                                'email': userEmail,
                                'picked_image': url,
                              });

                              if (newUser.user != null) {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) {
                                    return const ChatScreen();
                                  }),
                                );

                                                          if (!isSignup) {
                            _tryValidation();
                            try {
                              final newUser = await _authentication
                                  .signInWithEmailAndPassword(
                                email: userEmail,
                                password: userPassword,
                              );
                              if (newUser.user != null) {

                                Navigator.push(
                                  context,
                                  MaterialPageRoute(builder: (context) {
                                    return const ChatScreen();
                                  }),
                                );
                                setState(() {
                                  showSpinner = false;
                                });
                              }

For more code, you can visit https://github.com/chohangmin/cs_chatting_app.git

Firebase Core version

^3.1.1

Flutter Version

=3.4.1 <4.0.0

Relevant Log Output

I/ImeTracker( 5651): com.example.cs_chat_app:e5134e84: onRequestShow at ORIGIN_CLIENT_SHOW_SOFT_INPUT reason SHOW_SOFT_INPUT
D/InputMethodManager( 5651): showSoftInput() view=io.flutter.embedding.android.FlutterView{2f13df6 VFE...... .F...... 0,0-1080,2154 #1 aid=1073741824} flags=0 reason=SHOW_SOFT_INPUT
D/InsetsController( 5651): show(ime(), fromIme=true)
I/ImeTracker( 5651): com.example.cs_chat_app:e5134e84: onCancelled at PHASE_CLIENT_APPLY_ANIMATION
I/flutter ( 5651): [SSS] [firebase_auth/channel-error] "dev.flutter.pigeon.firebase_auth_platform_interface.FirebaseAuthHostApi.signInWithEmailAndPassword". 
D/EGL_emulation( 5651): app_time_stats: avg=123.63ms min=6.72ms max=351.98ms count=8
D/EGL_emulation( 5651): app_time_stats: avg=11.11ms min=6.88ms max=17.12ms count=59
D/EGL_emulation( 5651): app_time_stats: avg=11.35ms min=5.58ms max=38.33ms count=59
E/FrameTracker( 5651): force finish cuj, time out: J<IME_INSETS_ANIMATION::0@1@com.example.cs_chat_app>

Flutter dependencies

version: 1.0.0+1

environment: sdk: '>=3.4.1 <4.0.0'

dependencies: flutter: sdk: flutter

cupertino_icons: ^1.0.6 cloud_firestore: ^5.0.2 firebase_core: ^3.1.1 firebase_auth: ^5.1.1 modal_progress_hud_nsn: ^0.5.1 image_picker: ^1.1.2 firebase_storage: ^12.1.1

dev_dependencies: flutter_test: sdk: flutter

Additional context and comments

No response

TarekkMA commented 3 weeks ago

@chohangmin Thank you for reporting this error. Just to be sure I understand, are you saying that if you use signInWithEmailAndPassword with a non-existing email and password, you will get this error?

raininfotech-prapti153 commented 3 weeks ago

@TarekkMA have a look at this one if you can help I'm trying signInWithCredential using PhoneAuthCredential and i'm getting error below, Unhandled Exception: [firebase_auth/channel-error] "dev.flutter.pigeon.firebase_auth_platform_interface.FirebaseAuthHostApi.signInWithCredential".

TarekkMA commented 3 weeks ago

@raininfotech-prapti153 Can you please provide a minimal complete example of how to reproduce this issue? Minimal Reproducible Example

raininfotech-prapti153 commented 3 weeks ago

@TarekkMA Yes, sure. What I'm trying to do is, after verifying the phone number, to verify the code I get, which has been added for testing purposes in the console. I'm using,

PhoneAuthCredential credential = PhoneAuthProvider.credential(
      verificationId: verificationId,
      smsCode: code,
    );

and then this:

await FirebaseAuth.instance.signInWithCredential(credential).then((value) {
      debugPrint("Value: $value");
    }

and while executing signInWithCredential, I get the error mentioned in the previous comment

Hope this helps and please also let me know if there is any other way i can verify the code

chohangmin commented 2 weeks ago

@chohangmin Thank you for reporting this error. Just to be sure I understand, are you saying that if you use signInWithEmailAndPassword with a non-existing email and password, you will get this error?

Thanks to your immediate comment. Sorry to check your commet late.

I mean, If I turn on the app. and using signInWithEmailAndPassword with existing user info. The error is haapend [firebase_auth/channel-error] "dev.flutter.pigeon.firebase_auth_platform_interface.FirebaseAuthHostApi.signInWithEmailAndPassword".

However, If I try to using createUserWithEmailAndPassword method somehow before using signInWithEmailAndPassword . The error is not happend. and I work very well. (Even I create 'B' user's info. And I try to sign in 'A' user's info, It works well. If I follow the rule, Using createUserWithEmailAndPassword before using signInWithEmailAndPassword)

To sum it up to, If I use only signInWithEmailAndPassword method, The error happens. However If I use createUserWithEmailAndPassword before signInWithEmailAndPassword. It works well.

I guess If I use createUserWithEmailAndPassword first the channel connection is set very well. But If I use signInWithEmailAndPassword first. There is error of channel connection, It occurs [firebase_auth/channel-error] "dev.flutter.pigeon.firebase_auth_platform_interface.FirebaseAuthHostApi.signInWithEmailAndPassword".

If you need more information, I answer anytime.

Thank you

chohangmin commented 2 weeks ago

@raininfotech-prapti153 Can you please provide a minimal complete example of how to reproduce this issue? Minimal Reproducible Example

  1. Set the firebase core option in Main.dart
  2. Turn on the app, and Sign In
  3. Trun off the app
  4. Restart the app
  5. LogIn the existing user Info, Sign in in 2 step
  6. the error message is occured. [firebase_auth/channel-error] "dev.flutter.pigeon.firebase_auth_platform_interface.FirebaseAuthHostApi.signInWithEmailAndPassword".

I made the simple example code to test the error, But In this code, the error is not occured. LOL I don't know the reason. ;(

the below code is the code that I mentioned.

import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; import 'package:reproduce_firebase_auth_error/screen.dart';

void main() async { WidgetsFlutterBinding.ensureInitialized();

await Firebase.initializeApp( options: const FirebaseOptions( apiKey: '', appId: '', messagingSenderId: '', projectId: '', storageBucket: '', ), );

runApp(const MyApp()); }

class MyApp extends StatelessWidget { const MyApp({super.key});

// This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const Test(), ); } }

class Test extends StatefulWidget { const Test({super.key});

@override State createState() => _TestState(); }

class _TestState extends State { final _authentication = FirebaseAuth.instance; bool isSignup = false;

final _formKey = GlobalKey();

String userEmail = ''; String userPassword = '';

void _tryValidation() { final isValid = _formKey.currentState?.validate() ?? false; if (isValid) { _formKey.currentState!.save(); } }

@override Widget build(BuildContext context) { return Scaffold( body: Column( children: [ const SizedBox( height: 50, ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ GestureDetector( onTap: () { setState(() { isSignup = false; }); }, child: const Text('LOGIN')), GestureDetector( onTap: () { setState(() { isSignup = true; }); }, child: const Text('SIGNIN')) ], ), if (isSignup) Container( child: Column( children: [ TextFormField( key: const ValueKey(1), validator: (value) { if (value!.isEmpty || value.contains('@')) { return 'Please enter valid email address'; } return null; }, onSaved: (value) { userEmail = value!; }, onChanged: (value) { userEmail = value; }, decoration: const InputDecoration( prefixIcon: Icon(Icons.email), ), ), const SizedBox(height: 10), TextFormField( key: const ValueKey(2), validator: (value) { if (value!.isEmpty || value.length < 6) { return 'Password length must be more than 6 characters'; } return null; }, onSaved: (value) { userPassword = value!; }, onChanged: (value) { userPassword = value; }, decoration: const InputDecoration( prefixIcon: Icon(Icons.lock), ), ), ], ), ), if (!isSignup) Container( child: Column( children: [ TextFormField( key: const ValueKey(3), validator: (value) { if (value!.isEmpty || value.contains('@')) { return 'Please enter valid email address'; } return null; }, onSaved: (value) { userEmail = value!; }, onChanged: (value) { userEmail = value; }, decoration: const InputDecoration( prefixIcon: Icon(Icons.email), ), ), const SizedBox(height: 10), TextFormField( key: const ValueKey(4), validator: (value) { if (value!.isEmpty || value.length < 6) { return 'Password length must be more than 6 characters'; } return null; }, onSaved: (value) { userPassword = value!; }, onChanged: (value) { userPassword = value; }, decoration: const InputDecoration( prefixIcon: Icon(Icons.lock), ), ), ], ), ), const SizedBox(height: 30), GestureDetector( onTap: () async { try { if (isSignup) { _tryValidation(); final newUser = await _authentication.createUserWithEmailAndPassword( email: userEmail, password: userPassword, );

                if (newUser.user != null) {
                  print('Success the SignIn');

                  Navigator.push(context,
                      MaterialPageRoute(builder: (context) {
                    return const Screen();
                  }));
                }
              } else {
                _tryValidation();
                final newUser =
                    await _authentication.signInWithEmailAndPassword(
                  email: userEmail,
                  password: userPassword,
                );

                if (newUser.user != null) {
                  print('Success the LogIn');
                  Navigator.push(context,
                      MaterialPageRoute(builder: (context) {
                    return const Screen();
                  }));
                }
              }
            } catch (e) {
              print(e);
            }
          },
          child: const SizedBox(
            height: 40,
            width: 40,
            child: Text('Submit'),
          )),
    ],
  ),
);

} }

raininfotech-prapti153 commented 2 weeks ago

@chohangmin Are you getting the specified error while signing in? As I'm not able to reproduce it using the code you've provided

chohangmin commented 2 weeks ago

@chohangmin Are you getting the specified error while signing in? As I'm not able to reproduce it using the code you've provided

Yes, error occurs in my environment. I don't know exactly. Because In my environment the error is occured. I don't know Whether there is an error the other environment In your environment, It works well? No error?? or The code didn't work?

The code in the recent reply. It works well too, in my environment. So if you test the recent reply code, you can test the code that I first mentioned in my first post. (this code, https://github.com/chohangmin/cs_chatting_app.git)

Maybe, you set the firebase core and auth setting. And set serveral environment. If you have any question, ask me. I answer it!

raininfotech-prapti153 commented 2 weeks ago

@chohangmin Hey I just found out that variable userEmail you're using is not getting any value while performing signInWithEmailAndPassword, so I would suggest you to use,

TextEditingController emailController = TextEditingController(); //define it just like you define other variables
TextEditingController passwordController = TextEditingController(); //define it just like you define other variables

TextFormField(
          controller: emailController, // this is how to use it
           // Other code here

and use them instead of other variables, and you'll be able to sign in successfully. Try this out, and if it still doesn't work, I'm happy to help again.

chohangmin commented 2 weeks ago

@chohangmin Hey I just found out that variable userEmail you're using is not getting any value while performing signInWithEmailAndPassword, so I would suggest you to use,

TextEditingController emailController = TextEditingController(); //define it just like you define other variables
TextEditingController passwordController = TextEditingController(); //define it just like you define other variables

TextFormField(
          controller: emailController, // this is how to use it
           // Other code here

and use them instead of other variables, and you'll be able to sign in successfully. Try this out, and if it still doesn't work, I'm happy to help again.

oh I see, the error message is disappeared. Thank you very much.

I searched about the error message on google. But there is no solution about it, And I don't know why the code isn't working.

I'm first time to submit the issue on github. So I was inadequate in may way.

However, Thank you to listen my short english and short questions carefully.

Thank you very much. Have a good day sir!!!

raininfotech-prapti153 commented 2 weeks ago

@chohangmin
You too have a good day !! (I'm not sir by the way 😅)