Skip to content

[firebase_auth] linking credential to anonymous user #2344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
adworzynski opened this issue Apr 10, 2020 · 9 comments
Closed

[firebase_auth] linking credential to anonymous user #2344

adworzynski opened this issue Apr 10, 2020 · 9 comments
Assignees
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. plugin: auth resolution: needs-repro This issue could not be reproduced or needs an up to date reproduction on latest FlutterFire plugin.

Comments

@adworzynski
Copy link

Calling:

(await _auth.currentUser())
  .linkWithCredential(
    EmailAuthProvider.getCredential(
        email: email,
        password: password,
      ))

on anonymous user case error:

PlatformException(ERROR_USER_TOKEN_EXPIRED, The user's credential is no longer valid. The user must sign in again., null)
flutter: 1.12.13+hotfix.9
firebase_core: ^0.4.4+3
firebase_auth: ^0.15.5+3
cloud_functions: ^0.4.2+3
cloud_firestore: ^0.13.4+2
@TahaTesser
Copy link

Hi @adworzynski
can you please provide your flutter doctor -v and flutter run --verbose?
Thank you

@TahaTesser TahaTesser added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Apr 14, 2020
@adworzynski
Copy link
Author

[√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 10.0.18363.720], locale pl-PL)
• Flutter version 1.12.13+hotfix.9 at C:\Users\Adam\AppData\Local\flutter\flutter
• Framework revision f139b11009 (2 weeks ago), 2020-03-30 13:57:30 -0700
• Engine revision af51afceb8
• Dart version 2.7.2

[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at C:\Users\Adam\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.3
• Java binary at: C:\Users\Adam\AppData\Local\Java\java\bin\java
• Java version OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_242-b08)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/setup/#android-setup for detailed instructions).

[√] IntelliJ IDEA Ultimate Edition (version 2019.3)
• IntelliJ at C:\Users\Adam\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\193.6911.18
• Flutter plugin version 44.0.3
• Dart plugin version 193.6494.35

[√] Connected device (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)

! Doctor found issues in 2 categories.

@adworzynski
Copy link
Author

adworzynski commented Apr 15, 2020

[+1240 ms] I/BiChannelGoogleApi(16998): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq@efe5620
[ +423 ms] D/FirebaseAuth(16998): Notifying id token listeners about a sign-out event.
[        ] D/FirebaseAuth(16998): Notifying auth state listeners about a sign-out event.
[  +10 ms] E/flutter (16998): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(ERROR_USER_TOKEN_EXPIRED, The user's credential is no longer valid. The user must sign in again., null)
[        ] E/flutter (16998): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
[        ] E/flutter (16998): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33)
[        ] E/flutter (16998): <asynchronous suspension>
[        ] E/flutter (16998): #2      MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:349:48)
[   +1 ms] E/flutter (16998): #3      MethodChannelFirebaseAuth.linkWithCredential (package:firebase_auth_platform_interface/src/method_channel_firebase_auth.dart:224:23)
[        ] E/flutter (16998): #4      FirebaseUser.linkWithCredential (package:firebase_auth/src/firebase_user.dart:66:10)
[        ] E/flutter (16998): #5      _AuthenticatedUser.enroll (package:flutter_application/widgets/firebase/firebase_user.dart:66:10)
[        ] E/flutter (16998): <asynchronous suspension>
[        ] E/flutter (16998): #6      _RegistrationState.build.<anonymous closure> (package:flutter_application/views/account/registration.dart:73:50)
[        ] E/flutter (16998): #7      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:706:14)
[        ] E/flutter (16998): #8      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:789:36)
[        ] E/flutter (16998): #9      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
[        ] E/flutter (16998): #10     TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486:11)
[        ] E/flutter (16998): #11     BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:264:5)
[        ] E/flutter (16998): #12     BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:236:7)
[        ] E/flutter (16998): #13     GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
[        ] E/flutter (16998): #14     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222:20)
[        ] E/flutter (16998): #15     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
[        ] E/flutter (16998): #16     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
[        ] E/flutter (16998): #17     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
[        ] E/flutter (16998): #18     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
[        ] E/flutter (16998): #19     _rootRunUnary (dart:async/zone.dart:1138:13)
[        ] E/flutter (16998): #20     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
[        ] E/flutter (16998): #21     _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
[        ] E/flutter (16998): #22     _invoke1 (dart:ui/hooks.dart:273:10)
[        ] E/flutter (16998): #23     _dispatchPointerDataPacket (dart:ui/hooks.dart:182:5)
[        ] E/flutter (16998): 

@kirstywilliams
Copy link
Contributor

Hey @adworzynski no biggie but in future please try to add log outputs in code blocks, github assumes anything with #number is an issue and links this issue with many others which can make it difficult to triage. I've updated your comment above.

Are you still having problems with your original issue? - thanks!

@TahaTesser TahaTesser added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Apr 22, 2020
@adworzynski
Copy link
Author

Yes, I've upgraded to firebase_auth: 0.16.0, but still the same issue appears.

@adworzynski
Copy link
Author

OK, that is strange. I've created automated test that first create anonymous account and after some time tries to link it with creadentials and it sometimes work and sometimes throw error mentioned earlier.
But even when it works, it looks like authentication status change is not published to FirebaseAuthPlatform.instance.onAuthStateChanged.

@TahaTesser TahaTesser removed the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Apr 23, 2020
@TahaTesser
Copy link

Hi @adworzynski
Tto better address the issue, would be helpful
if you could post a minimal code sample to reproduce the problem
Thank you

@TahaTesser TahaTesser added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Apr 23, 2020
@adworzynski
Copy link
Author

I'm just calling:
FirebaseAuth.instance.signInAnonymously();

And after that (after filling enrollment form, up to 20 seconds later)

(await FirebaseAuth.instance.currentUser())
          .linkWithCredential(EmailAuthProvider.getCredential(
            email: email,
            password: password,
          ))

At the top of my application I have StreamBuilder with stream:
FirebaseAuth.instance.onAuthStateChanged.map(_toUser)

@TahaTesser TahaTesser removed the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Apr 24, 2020
@Ehesp Ehesp self-assigned this Jul 2, 2020
@Salakar Salakar added blocked: customer-response Waiting for customer response, e.g. more information was requested. resolution: needs-repro This issue could not be reproduced or needs an up to date reproduction on latest FlutterFire plugin. labels Aug 25, 2020
@Salakar
Copy link
Member

Salakar commented Aug 25, 2020

Hey 👋

Our rework of the Auth, Core & Firestore plugins as part of the FlutterFire roadmap was published over a week ago with a ton of fixes and new features.

As part of this we introduced a new documentation site which should has a lot of new documentation that should cover this issue & others in general. If you spot any issues on the documentation or anything missing then please raise a new GitHub issue, or better yet suggest a change via a Pull Request (there's a 'Edit this page' button at the bottom of every page on the docs).

See: https://firebase.flutter.dev/docs/auth/usage#linking-user-accounts

Additionally, for help migrating to these new plugins I'd recommend checking out the migration guide: https://firebase.flutter.dev/docs/migration

@Salakar Salakar closed this as completed Aug 25, 2020
@firebase firebase locked and limited conversation to collaborators Sep 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. plugin: auth resolution: needs-repro This issue could not be reproduced or needs an up to date reproduction on latest FlutterFire plugin.
Projects
None yet
Development

No branches or pull requests

5 participants