Skip to content

[firebase_auth] linking credential to anonymous user #2344

Closed

Description

@adworzynski

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

Activity

  1. TahaTesser commented on Apr 14, 2020

    @TahaTesser

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

  2. adworzynski commented on Apr 15, 2020

    @adworzynski
    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.

  3. adworzynski commented on Apr 15, 2020

    @adworzynski
    Author
    [+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): 
    
  4. kirstywilliams commented on Apr 21, 2020

    @kirstywilliams
    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!

  5. added
    blocked: customer-responseWaiting for customer response, e.g. more information was requested.
    and removed
    blocked: customer-responseWaiting for customer response, e.g. more information was requested.
    on Apr 22, 2020
  6. adworzynski commented on Apr 23, 2020

    @adworzynski
    Author

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

  7. adworzynski commented on Apr 23, 2020

    @adworzynski
    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.

  8. TahaTesser commented on Apr 23, 2020

    @TahaTesser

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

  9. adworzynski commented on Apr 23, 2020

    @adworzynski
    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)

  10. self-assigned this
    on Jul 2, 2020
  11. added
    blocked: customer-responseWaiting for customer response, e.g. more information was requested.
    resolution: needs-reproThis issue could not be reproduced or needs an up to date reproduction on latest FlutterFire plugin.
    on Aug 25, 2020
  12. Salakar commented on Aug 25, 2020

    @Salakar
    Contributor

    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

  13. locked and limited conversation to collaborators on Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

blocked: customer-responseWaiting for customer response, e.g. more information was requested.plugin: authresolution: needs-reproThis issue could not be reproduced or needs an up to date reproduction on latest FlutterFire plugin.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions