Skip to content

Commit b1245bb

Browse files
committed
Use auth emulator when running locally
1 parent 01c198a commit b1245bb

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/auth.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,22 @@ const firebaseConfig = {
1414

1515
firebase.initializeApp(firebaseConfig);
1616

17+
const auth = firebase.auth();
18+
19+
if (window.location.hostname === "localhost") {
20+
console.log("Using auth emulator");
21+
auth.useEmulator("http://localhost:9099");
22+
}
23+
1724
function useAnonymousLogin() {
1825
const [user, setUser] = useState<firebase.User | null | undefined>();
1926

2027
useEffect(() => {
21-
return firebase.auth().onAuthStateChanged((user) => {
28+
return auth.onAuthStateChanged((user) => {
2229
setUser(user);
2330

2431
if (!user) {
25-
firebase.auth().signInAnonymously().catch(console.error);
32+
auth.signInAnonymously().catch(console.error);
2633
return;
2734
}
2835
});

src/pages/Main.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import "firebase/functions";
2121
const functions = firebase.app().functions("europe-west1");
2222

2323
if (window.location.hostname === "localhost") {
24-
console.log("Using emulator");
24+
console.log("Using functions emulator");
2525
functions.useEmulator("localhost", 5001);
2626
}
2727

0 commit comments

Comments
 (0)