Skip to content

Auth using Emulator with demo project #844

@Ticlext-Altihaf

Description

@Ticlext-Altihaf

Describe the feature you would like to see

Is it possible to use Firebase Emulator with demo Firebase project, it would be useful for CI testing where the current setup require creating new Firebase project and issue service account.

https://firebase.google.com/docs/emulator-suite/connect_auth#choose_a_firebase_project

Example from using official Admin SDK for Node.js, it works without requiring internet connection or having Firebase project.
firebase emulators:start --project=demo-project

process.env.FIREBASE_AUTH_EMULATOR_HOST = "127.0.0.1:9099"
import { initializeApp } from 'firebase-admin/app';
import { getAuth } from 'firebase-admin/auth';

initializeApp({
    projectId: 'demo-project',
});

const newUserData = {
    email: Math.random()*10000 + '@example.com', // XXXX@example.com
    emailVerified: false,
    phoneNumber: '+1' + Math.random()*10000000000, // +1XXXXXXXXXX
    password: 'secretPassword',
    displayName: 'John Doe',
    photoURL: 'http://www.example.com/12345678/photo.png',
    disabled: false,
};

const user = await getAuth().createUser(newUserData)

// Getting the ID token with signInWithPassword
let idToken = await fetch(`http://127.0.0.1:9099/identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=random`, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
    },
    body: JSON.stringify({
        email: user.email,
        password: "secretPassword",
        returnSecureToken: true,
    }),
})

idToken = await idToken.json()
idToken = idToken.idToken

const userFromIdToken = await getAuth().verifyIdToken(idToken)

await getAuth().deleteUser(userFromIdToken.uid)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions