dart_firebase_admin icon indicating copy to clipboard operation
dart_firebase_admin copied to clipboard

Updating user data based on UID fails

Open jusuf-el opened this issue 2 years ago • 3 comments

I have issue updating the user data based on user's bid. First, I retrieve the user's data by email, and I get what I expect. Then, I used the uid from the response for updating the user's data, but I keep getting the following error:

E/flutter (13587): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FirebaseAuthAdminException: auth/missinguid: A uid identifier is required for the current operation.
E/flutter (13587): #0      validateResponse (package:_discoveryapis_commons/src/api_requester.dart:306:9)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #1      ApiRequester.request (package:_discoveryapis_commons/src/api_requester.dart:72:16)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #2      AccountsResource.update (package:firebaseapis/identitytoolkit/v1.dart:714:23)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #3      _AuthHttpClient.setAccountInfo.<anonymous closure> (package:dart_firebase_admin/src/auth/auth_api_request.dart:966:24)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #4      _AbstractAuthRequestHandler.updateExistingAccount (package:dart_firebase_admin/src/auth/auth_api_request.dart:733:22)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #5      _BaseAuth.updateUser (package:dart_firebase_admin/src/auth/base_auth.dart:772:9)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #6      LoginController.login.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:stock_log/app/modules/login/controllers/login_controller.dart:162:23)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #7      LoginController.login.<anonymous closure>.<anonymous closure> (package:stock_log/app/modules/login/controllers/login_controller.dart:149:13)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #8      LoginController.login.<anonymous closure> (package:stock_log/app/modules/login/controllers/login_controller.dart:144:11)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): #9      LoginController.login (package:stock_log/app/modules/login/controllers/login_controller.dart:87:28)
E/flutter (13587): <asynchronous suspension>
E/flutter (13587): 

Here is my code:

await auth.getUserByEmail(email.value).then((user) async {
            String uid = user.uid;
            await auth
                .updateUser(uid, ath.UpdateRequest(password: code.toString()))
                .then((value) async {
              print('USER UPDATED');
              print(value.toJson());
            });
          });

jusuf-el avatar Feb 06 '24 15:02 jusuf-el

The exception occurred because the UID was missing in the update request (possibly missed implementation in the package). Added a PR to fix!

The0xArchitect avatar Feb 12 '24 16:02 The0xArchitect

@HeySreelal when we can expect the fix to be merged, so we can continue with our work that is dependent to this issue.

Thank you once again!

jusuf-el avatar Feb 13 '24 15:02 jusuf-el

I'm actually unsure about the timelines. May be an admin can help you with that. Fix is actually a one liner, you can check this commit: 8315f5373ed7e72d93cba02fffa67e3cb69e3ea7. In addition to that, you could add it locally on your machine/server and continue your work while waiting for the PR to be merged. Best :)

The0xArchitect avatar Feb 13 '24 16:02 The0xArchitect

Still facing the issue (currently using the 0.3.1 version FirebaseAuthAdminException: auth/missinguid: A uid identifier is required for the current operation.

This is the function

await auth.updateUser( uid, UpdateRequest( email: emailCtrl.text, password: passCtrl.text, ));

AbuBakar044 avatar Sep 21 '24 23:09 AbuBakar044

Hi @AbuBakar044, I can see that this fix hasn't been released to pub.dev yet. I'm not sure why though :) Probably there'll be an update soon.

The0xArchitect avatar Sep 22 '24 05:09 The0xArchitect