question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

With Firebase Admin not able to create user in local emulator

See original GitHub issue

Team

I’m trying to create user with my Node JS backend with the following code

const admin = require("firebase-admin");
process.env.FIRESTORE_EMULATOR_HOST = "localhost:8080";
process.env['FIRESTORE_EMULATOR_HOST'] = 'localhost:8080';
var serviceAccount = require("../service-account.json");


 admin.initializeApp({
    projectId:"tndfc-app"
  });

  let data = {
        email: "santhoshlfms@gmail.com", password: "12345678"
    }
    try {
        
        admin.firestore().settings({
            host:"localhost:33007",
            ssl:false
        })
        const user = await admin.auth().createUser({ email: data.email, password: data.password, emailVerified: false, displayName: 'John Doe', disabled: false });
    } catch (err) {
        console.log(err)
    }

I tried to read similar git issues threads, but I’m not able to connect to emulator and create user , is this actually supported in firebase emulator right now ? version used : “firebase”: “^9.1.2”, “firebase-admin”: “^9.12.0”

Credential implementation provided to initializeApp() via the "credential" property fail initializeApp() ved to fetch a valid Google OAuth2 access token withd Google OAuth2 ac the following error: "Error fetching access token:g access token: Er Error while making request: getaddrinfo ENOTFOUND adata.google.inter
metadata.google.internal. Error code: ENOTFOUND

Ques: How do I connect to local emulator for Auth via Admin SDK, Im trying to create default users via admin-sdk and access then / authenticate then in UI using firebase/auth [signInWithEmailAndPassword] method.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hiranya911commented, Oct 26, 2021

That error implies the SDK is still operating in the non-emulator mode. If the emulator mode was correctly enabled, the implementation will skip the credential lookup entirely:

https://github.com/firebase/firebase-admin-node/blob/b26501b023194b664df5d81f526e237f975fae71/src/auth/auth-api-request.ts#L231-L237

I’d start by checking your env variables. You have mentioned FIRESTORE_EMULATOR_HOST. The correct variable for Auth is FIREBASE_AUTH_EMULATOR_HOST.

0reactions
santhoshlfmscommented, Oct 26, 2021

@hiranya911 : Thanks ! FIREBASE_AUTH_EMULATOR_HOST helped to resolved

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connect your app to the Authentication Emulator - Firebase
Create, update and manage emulated user accounts for testing ... The Firebase Local Emulator Suite emulates products for a single Firebase project.
Read more >
Create user with firebase admin sdk that can signIn using ...
@Mani I agree the method is there. However, the user won't be created in the Emulator, but in the actual Firebase project. Can...
Read more >
firebase-admin - npm
Firebase admin SDK for Node.js. Latest version: 11.4.1, last published: 4 days ago. Start using firebase-admin in your project by running ...
Read more >
Running firebase admin and storage emulator locally without ...
I had a similar issue and remember it being around passing or not passing those parameters to initializeApp while in emulation.
Read more >
Using Firebase Authentication - FlutterFire
idTokenChanges() , userChanges() & authStateChanges() will also not fire if you disable or delete the User via your own firebase admin sdk implementation...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found