DEV Community

Cover image for Firebase Authentication with GetX in Flutter

Firebase Authentication with GetX in Flutter

Imran Sefat on October 16, 2021

Introduction 🎉 You know about GetX. It is an extra-light and robust solution for Flutter. It combines high-performance state management,...
Collapse
 
bigbott profile image
bigbott

Nice article.
Especially I like the part when controller decides where to go. Clever.
But I have a doubt about making navigation from controllers. It makes code much less readable.
Also, you don't need to clear stack from the beginning, since there is nothing in stack. But this is not important detail.
Thanks for sharing.

Collapse
 
imransefat profile image
Imran Sefat

Hey thanks for your comment. It's been so long I worked with getx but I had a look at the code after reading your comment. I agree with the code not being readable about the navigation controller but it's probably because of handling all the state but I'm not too sure as I worked on it years ago.

Also, I cleared the navigation as the time I wrote this article, I thought of user credential issues like a token can be expired or something and that can be an issue with the navigation stack cause you don't want your user to be getting back to the Dashboard page after you navigated them from Dashboard to the Register page. This is just an assumption as I wrote this years ago and don't remember every details.

Cheers

Collapse
 
shah000 profile image
HUSSAIN SHAH

thanks but one question for you ..
how do we execute two function in single(login/Register) button pressed in flutter?

Collapse
 
cris96174560 profile image
Cris

Hello, I had a problem with the signOut method. It says it is not implemented. I'm using
firebase_auth: ^3.2.0
firebase_core: ^1.10.0

Would appreciate any help

Collapse
 
imransefat profile image
Imran Sefat

Please check if you have imported the files correctly or check whether you have copied the signout function or not.

void signOut() async {
await auth.signOut();
}

Check if the above function is present in the auth_controller.dart file

Collapse
 
cris96174560 profile image
Cris

Yes. Thanks for the reply
I traced the function all the way to
.../snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth_platform_interface-6.1.4/lib/src/platform_interface/platform_interface_firebase_auth.dart

this is its code:

Future signOut() async {
throw UnimplementedError('signOut() is not implemented');
}

Collapse
 
idaudk profile image
Daud K

bro, can you provide guide for facebook and forget password feature.

Collapse
 
imransefat profile image
Imran Sefat

It's mostly the same for the Facebook authentication. You will be needing the flutter_facebook_auth package which can be found here: pub.dev/packages/flutter_facebook_...

a sample sign in function is given below:

Future signInWithFacebook() async {
// Trigger the sign-in flow
final LoginResult loginResult = await FacebookAuth.instance.login();

// Create a credential from the access token
final OAuthCredential facebookAuthCredential = FacebookAuthProvider.credential(loginResult.accessToken.token);

// Once signed in, return the UserCredential
return FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
}

I will try to make a video or write an article for the auth process including the password reset functions.

Collapse
 
ankita_tripathi_5cdae815b profile image
Ankita Tripathi

This is by far the most sorted article on using GetX! Would you like to submit this article on Dev Library as well? devlibrary.withgoogle.com/

Collapse
 
imransefat profile image
Imran Sefat

Thanks for being so kind.
Yes, I will be glad to submit there as well.

Collapse
 
dbestech profile image
Info Comment hidden by post author - thread only accessible via permalink
dbestech

Learn more about Getx here
dbestech.com/tutorials/flutter-get...

Collapse
 
mdusaama0 profile image
mdusaama0

when app is running sometime it navigates to home screen automatically.
Console Log:
D/FirebaseAuth( 2968): Notifying id token listeners about user ( mjnetiCUregDma3eBECG79vyU9p2 ).

Collapse
 
whoadityanawandar profile image
Aditya B Nawandar

How do you make this role based?

Some comments have been hidden by the post's author - find out more