How to link phone number to already logged in firebase gmail user - firebase

How to use firebase linkWithCredential? I'm trying to link the phone number to the current firebase user. My problem is linkWithCredentials has an error of The method 'linkWithCredential' isn't defined for the type 'Function' Is this because of my version of firebase_auth: ^0.15.5+3? Or I am doing it wrong.
FirebaseAuth.instance.currentUser.linkWithCredential(phoneCredential);

The error is because of the version.
.currentUser is a method in version 0.15.5+3. Link
You need to call the method to get the FirebaseUser instance.
So your code becomes as shown below:
await (await FirebaseAuth.instance.currentUser()).linkWithCredential(phoneCredential);

Related

Flutter app crashing without exception when calling FacebookAuth.instance.login()

I've followed the tutorial for implementing the Facebook Login from
https://firebase.flutter.dev/docs/auth/social/
Which is the official documentation, my function is literally just:
facebookLogin() async
{
final LoginResult loginResult = await FacebookAuth.instance.login(); // final OAuthCredential facebookAuthCredential = FacebookAuthProvider.credential(loginResult.accessToken!.token);
// var credentials = await FirebaseAuth.instance.signInWithCredential(facebookAuthCredential);
}
I've commented the following function to isolate the problem.
On the console i get the following:
Performing hot reload...
Reloaded 1 of 1031 libraries in 908ms.
Lost connection to device.
And no exceptions nor errors.
Has anyone faced the same problem before?
I'm using:
flutter_facebook_auth: ^4.1.1
firebase_core: ^1.13.1
firebase_auth: ^3.3.9
In my pubspec.yaml
Is there any way to debug this problem further and find the problem?
Please ensure that you followed the setup steps one by one, and they are:
Ensure the "Facebook" sign-in provider is enabled on the Firebase Console. with the Facebook App ID and Secret set
follow the steps in the plugin (flutter_facebook_auth) documentation to ensure that both the Android & iOS Facebook SDKs have been initialized correctly
Please note that firebase flutterfire uses: flutter_facebook_auth: '^3.5.0' in their documentation and the latest version of that package 4.1.1 untill this day (3/4/2022)
It can be an issue with info.plist configuration for flutter deep-linking.
Did you setup it for your app?
https://docs.flutter.dev/development/ui/navigation/deep-linking
to be more specific you should have only one CFBundleURLTypes section in your info.plist
I had exactly the same problem. Here is how I solved.
In Info.plist, I had 2 sessions called "CFBundleURLTypes", one for Facebook Login, and another one for Google login. Apparently you can only have one CFBundleURLTypes session.
So the solution was to merge everything into a single CFBundleURLTypes session.

Firebase App Check + Cloud functions : Failed to validate AppCheck token

I have recently added Firebase App Check in my Flutter app.
I am calling Cloud functions with the https.onCall() method. However i am receiving this error :
> {"severity":"WARNING","message":"Failed to validate AppCheck token. FirebaseAppCheckError: Decoding App Check token failed. Make sure you passed the entire string JWT which represents the Firebase App Check token.
at FirebaseAppCheckError.FirebaseError [as constructor] (/Users/foxtom/Desktop/Cloud Functions/functions/node_modules/firebase-admin/lib/utils/error.js:44:28)
at FirebaseAppCheckError.PrefixedFirebaseError [as constructor] (/Users/foxtom/Desktop/Cloud Functions/functions/node_modules/firebase-admin/lib/utils/error.js:90:28)
at new FirebaseAppCheckError (/Users/foxtom/Desktop/Cloud Functions/functions/node_modules/firebase-admin/lib/app-check/app-check-api-client-internal.js:187:28)
at /Users/foxtom/Desktop/Cloud Functions/functions/node_modules/firebase-admin/lib/app-check/token-verifier.js:82:19
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
errorInfo: {
code: 'app-check/invalid-argument',
message: 'Decoding App Check token failed. Make sure you passed the entire string JWT which represents the Firebase App Check token.'
},
codePrefix: 'app-check'
}"}
> {"verifications":{"app":"INVALID","auth":"MISSING"},"logging.googleapis.com/labels":{"firebase-log-type":"callable-request-verification"},"severity":"WARNING","message":"Callable request verification failed: AppCheck token was rejected."}
The severity seems to be WARNING only but it doesn't execute the function. My function only contains a console.log()
In my app i have this error :
W/FirebaseContextProvider( 6788): Error getting App Check token; using placeholder token instead. Error: com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed.
I/flutter ( 6788): Error is : [firebase_functions/unauthenticated] Unauthenticated
I have not enforced anything like suggested in the documentation
This is preventing me from using Cloud Functions and i can disable App Check for my app anymore...
EDIT :
I add that Firebase Storage and RealTime Database are working fine without any debug AppCheck token when it's not enforced.
What can I do ?
I created a reproducible code sample, which you see here: https://github.com/nilsreichardt/playground/tree/firebase-app-check-cloud-function-unauthenticated-issue/firebase-app-check-cloud-functions-unauthentificated
Therefore, I created a detailed issue in the FlutterFire repository: https://github.com/FirebaseExtended/flutterfire/issues/6794
A first workaround already posted as a comment and I'm sure that more workarounds or solutions will follow.
Firebaser here.
Thank you for reporting this issue -- we have now released a fix to all platforms that should resolve this issue. Please refer to the Github issue for full details.

A value of type 'Future<FirebaseUser> Function()' can't be assigned to a variable of type 'User'

This line is causing me trouble
User fUser = FirebaseAuth.instance.currentUser;
FirebaseAuth.instance.currentUser is supposed to return User but dart gives me an error saying that it is returning Future<FirebaseUser> Function() instead. I got this line of code straight from the documentation (https://firebase.flutter.dev/docs/auth/usage). I have already run flutter pub upgrade so I am using the latest version of FirebaseAuth.
Please advise.
Your error is incorrect, I suspect it's from somewhere else.
Anyway, current user is nullable so:
User? fUser = FirebaseAuth.instance.currentUser;

Auth call errors signUpAppId is undefined

When I do a auth call using email, the function returns successful including the data expected, however leaves this console.error from shared.js (I assuming this is a Firebase file).
TypeError: undefined is not an object (evaluating 'b.currentSelfServiceAppID.signUpAppId')
I am using version "firebase": "^6.6.1", and added the email I am using to auth my app via the Firebase console. The email has not been verified.
Is this error expected when the email has not been verified? Or is there another set up error I have missed?
I have found where this error is coming from. I have an Okta extension installed on my browser, and this is causing the error. It has nothing to do with Firebase, it's a bug with the extension.

Flutter: firebase_auth seems not to work, how do I authorize?

I have a working flutter app which uses the cloud_firestore package, it's going well with Android and iOS. But my database is "allow read,write: if true", and so Google keeps reminding me to fix this unsecurity. This I did:
including firebase_auth
changing my rules on firebase
creating a mail/password account
implementing the login procedure
changing the rules to "allow write: if request.auth != null;"
I think I made everything ok. In the app, it seems so:
print("User ${(await FirebaseAuth.instance.currentUser()).email})");
This gives me the mail of my account. Also I have a onAuthStageChanged listener and I get what I would expect. So I guess the login did work.
But if I try to make a database access e.g. with .setData(), I get an error
W/Firestore( 4411): (19.0.0) [Firestore]: Write failed at...: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
It looked for me as if the auth package is not informing the firestore package correctly. In the logs, I see
D/FirebaseAuth( 5698): Notifying id token listeners about user (...).
I would expect something like "Firestore: received token...", but this does not come.
Do I have to be careful with the initialization order? Mine is
_app = await Firebase.App.configure...
_firestore = Firestore(app: _app);
await FirebaseAuth.instance.signInWithEmailAndPassword...
I tried it on some Samsung and OnePlus devices with Android 8 and 9.
Any hints someone?
I got it running!! Used a hint from Flutter & Firebase - using firebase_storage along with firebase_auth
When accessing the database, I used a pointer to the firestore which I created like
static Firestore _firestore;
...
_firestore = Firestore(app: ...);
And later I used
await _firestore.collection(...)...setData(...);
But the Firestore seems to change after a login. It works when I write:
await Firestore.instance.collection...setData
Interesting!!

Resources