Git Product home page Git Product logo

Comments (24)

rrousselGit avatar rrousselGit commented on June 14, 2024 1

You shouldn't need any special backend for the example.

A simple main directly executing createUser should do.

from dart_firebase_admin.

Ehesp avatar Ehesp commented on June 14, 2024 1

@niklasbartsch just confirming you have email authentication enabled on your project?

from dart_firebase_admin.

rrousselGit avatar rrousselGit commented on June 14, 2024

Pretty sure it worked before. Let me check

from dart_firebase_admin.

rrousselGit avatar rrousselGit commented on June 14, 2024

This works just fine for me. Do you maybe have a more specific example? Maybe it's a specific email/password combination that's the issue?

from dart_firebase_admin.

samtuga1 avatar samtuga1 commented on June 14, 2024

Has anyone already used the createUser function?

I always get a FirebaseAuthAdminException with the code auth/internalerror and the message An internal error has occurred.

final createRequest = CreateRequest(
      email: email,
      displayName: '$firstName $lastName',
      password: randomPassword,
    );

try {
      user = await auth.createUser(createRequest);
 } on FirebaseAuthAdminException catch (e) {
      print('');
      print('FirebaseAuthAdminException');
      print('code: ${e.code}');
      print('message: ${e.message}');
 } catch (e) {
      print('catched: $e);
 }

This works fine for me tho, print the email/password combination and make sure it exists

from dart_firebase_admin.

niklasbartsch avatar niklasbartsch commented on June 14, 2024

I have still the same issue. The email and password is correct.
I printed the error code and its AuthClientErrorCode.internalError
What am I missing?

Future<UserRecord> createUser(CreateRequest properties) async {
    return _authRequestHandler
        .createNewAccount(properties)
        // Return the corresponding user record.
        .then(getUser)
        .onError<FirebaseAuthAdminException>((error, _) {
      if (error.errorCode == AuthClientErrorCode.userNotFound) {
        // Something must have happened after creating the user and then retrieving it.
        throw FirebaseAuthAdminException(
          AuthClientErrorCode.internalError,
          'Unable to create the user record provided.',
        );
      }
      throw error;
    });
  }

It seems like the user is not created fast enough 🤷‍♂️

from dart_firebase_admin.

samtuga1 avatar samtuga1 commented on June 14, 2024

print the stacktrace and see where it leads to

from dart_firebase_admin.

rrousselGit avatar rrousselGit commented on June 14, 2024

@niklasbartsch Give us more than this. Like the mail or password, or a git repository to reproduce the issue.

from dart_firebase_admin.

niklasbartsch avatar niklasbartsch commented on June 14, 2024

Maybe this smaler example helps:

import 'package:api/helpers/extensions.dart';
import 'package:dart_firebase_admin/auth.dart';
import 'package:dart_frog/dart_frog.dart';

Future<Response> onRequest(RequestContext context) async {
  final auth = context.firebaseAuth;

  try {
    await auth.createUser(
      CreateRequest(
        email: '[email protected]',
        password: 'Hello1234',
      ),
    );
  } catch (e) {
    print('create user failed: $e');
  }

  return Response(body: 'Welcome to Dart Frog!');
}

create user failed: FirebaseAuthAdminException: auth/internalerror: An internal error has occurred.

The function is failing, but the user gets created.

from dart_firebase_admin.

rrousselGit avatar rrousselGit commented on June 14, 2024

This too works fine for me. It'd help if you could create a git repository at this point.

from dart_firebase_admin.

niklasbartsch avatar niklasbartsch commented on June 14, 2024

I created this sample dart_frog server.

[PROJECT_ID] and [username] has to be set manually user_api

from dart_firebase_admin.

rrousselGit avatar rrousselGit commented on June 14, 2024

Could you make an example without dart_frog? I don't use that package and am not familiar with it.

from dart_firebase_admin.

samtuga1 avatar samtuga1 commented on June 14, 2024

Could you make an example without dart_frog? I don't use that package and am not familiar with it.

@niklasbartsch Check out Pharaoh It is a backend framework that is highly inspired by ExpressJS. it is very easy to use when coming from Express. you can try building your example with it

from dart_firebase_admin.

niklasbartsch avatar niklasbartsch commented on June 14, 2024

You can find my simplified code in the local_main.dart file.

The user gets created but the functions throws the same error.

As I mentioned it is looking too early for the not yet created user.

FirebaseAuthAdminException: auth/internalerror: An internal error has occurred.

Your code in the dart_firebase_admin package:

  /// Creates a new user.
  ///
  /// See https://firebase.google.com/docs/auth/admin/manage-users#create_a_user
  /// for code samples and detailed documentation.
  ///
  /// Returns A Future fulfilled with the user
  /// data corresponding to the newly created user.
  Future<UserRecord> createUser(CreateRequest properties) async {
    return _authRequestHandler
        .createNewAccount(properties)
        // Return the corresponding user record.
        .then(getUser)
        .onError<FirebaseAuthAdminException>((error, _) {
      if (error.errorCode == AuthClientErrorCode.userNotFound) {
        // Something must have happened after creating the user and then retrieving it.
        throw FirebaseAuthAdminException(
          AuthClientErrorCode.internalError,
          'Unable to create the user record provided.',
        );
      }
      throw error;
    });
  }

from dart_firebase_admin.

rrousselGit avatar rrousselGit commented on June 14, 2024

As I mentioned it is looking too early for the not yet created user.

Where?
The getUser invocation is correct. That's exactly how the JS SDK does it too.

So far, there are no indications that your "internalError" is pointing to the "Unable to create the user record". You haven't shared the message nor the stacktrace after-all.

You can find my simplified code in the local_main.dart file.

I hate to say it, but your code works for me.

from dart_firebase_admin.

niklasbartsch avatar niklasbartsch commented on June 14, 2024

That is not the answer I was hoping for 😅

dart local_main.dart
error Code: AuthClientErrorCode.userNotFound
Stacktrace: #0      main (file:///Users/niklasbartsch/dev/user_api/local_main.dart:52:37)
<asynchronous suspension>

FirebaseAuthAdminException: auth/internalerror: An internal error has occurred.

"error Code:" is from the onError Function

from dart_firebase_admin.

niklasbartsch avatar niklasbartsch commented on June 14, 2024

Could you make an example without dart_frog? I don't use that package and am not familiar with it.

@niklasbartsch Check out Pharaoh It is a backend framework that is highly inspired by ExpressJS. it is very easy to use when coming from Express. you can try building your example with it

I'm currently too happy with dart_frog. I've been using it with Globe.dev since august and its working like a charm.

from dart_firebase_admin.

niklasbartsch avatar niklasbartsch commented on June 14, 2024

@niklasbartsch just confirming you have email authentication enabled on your project?

Yes. 👍

from dart_firebase_admin.

Ehesp avatar Ehesp commented on June 14, 2024

Another quick check would be 'npm i firebase-tools', use the same service account and see if it works. If it does, then we suspect it's to do with how the request is authenticated?

from dart_firebase_admin.

niklasbartsch avatar niklasbartsch commented on June 14, 2024

I only use Platform.environment for the server. I already use the firebase-tools on my local machine...

from dart_firebase_admin.

niklasbartsch avatar niklasbartsch commented on June 14, 2024

I printed the user id from the createNewAccount function and its the same one that gets created.

I tried to get the user with the id in a separate function and that failed too.
I also tried other ids of users that I already use in the frontend, didn't work either.

FirebaseAuthAdminException: auth/usernotfound: There is no user record corresponding to the provided identifier.

There is only one created account that i can find with the getUserByEmail and the uid of this user is not the one that I can find in the console.

To validate that I am in the correct project I printed the firebaseAuth.app.projectId and its correct

from dart_firebase_admin.

rrousselGit avatar rrousselGit commented on June 14, 2024

From your description, users are correctly created.
Sounds like what you're saying is that getUser does not work on your side.

Maybe try and make make new steps to reproduce the issue that do not rely on createNewAccount?

Such as maybe:

  • Manually create a new user in the Firebase console
  • call getUser on that newly created user

It sounds like this fails for you. So it'd be valuable to see how exactly you did this specifically

from dart_firebase_admin.

niklasbartsch avatar niklasbartsch commented on June 14, 2024

I tried to create a user in the firebase console and through the app. I am not able to get both accounts with getUserByEmail or getUser. Also not after signing in with them.

Any ideas why I get a wrong uid from the one user I can fetch?

from dart_firebase_admin.

rrousselGit avatar rrousselGit commented on June 14, 2024

Nope, no idea. I have yet to see a case where it doesn't work for me.

from dart_firebase_admin.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.