71 - ChatOS - Setup Firebase Emulator

Livestream

https://firebase.google.com/docs/emulator-suite

Setup Firebase CLI & emulator

curl -sL firebase.tools | bash

# Choose Emulators, and other services you'd like to use e.g. Firestore, Auth
firebase init

# Start emulators
firebase emulators:start

Then, connect the app to emulator in your Firebase initialization step. You can add condition to connect to the emulator.

import { getAuth, connectAuthEmulator } from 'firebase/auth';

export const auth = getAuth(app);

// Connect to Firebase Emulator only in development
if (process.env.NODE_ENV === 'development') {
	connectAuthEmulator(auth, 'http://localhost:9099');
}

Then try logging in, instead of redirecting to Google login, you’ll see this page.

Then add new account and fill in user information, or auto generate it.

Adding Firebase Emulator for other services can be done in a similar fashion

import { getAuth, connectAuthEmulator, type User } from 'firebase/auth';
import { getFirestore, connectFirestoreEmulator } from 'firebase/firestore';

export const auth = getAuth(app);
export const firestore = getFirestore(app);

if (process.env.NODE_ENV === 'development') {
	connectAuthEmulator(auth, 'http://localhost:9099');
	connectFirestoreEmulator(firestore, 'localhost', 8080);
}