Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/react/kitchen-sink/src/firebase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getApps, initializeApp } from "firebase/app";
import { connectAuthEmulator, getAuth } from "firebase/auth";
import { connectFirestoreEmulator, getFirestore } from "firebase/firestore";

if (getApps().length === 0) {
initializeApp({
projectId: "demo-test-project",
apiKey: "demo-api-key", // Required for Firebase to initialize
});

// Connect to emulators if running locally
if (import.meta.env.DEV) {
try {
// Connect to Auth emulator
const auth = getAuth();
connectAuthEmulator(auth, "http://localhost:9099");
console.log("Connected to Firebase Auth emulator");

// Connect to Firestore emulator
const firestore = getFirestore();
connectFirestoreEmulator(firestore, "localhost", 8080);
console.log("Connected to Firebase Firestore emulator");
} catch (error) {
console.warn("Could not connect to Firebase emulators:", error);
}
}
}
2 changes: 1 addition & 1 deletion examples/react/useGetIdTokenQuery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"dev:emulator": "cd ../../../ && firebase emulators:exec --project test-project 'cd examples/react/useGetIdTokenQuery && vite'",
"dev:emulator": "cd ../../../ && firebase emulators:exec --project demo-test-project 'cd examples/react/useGetIdTokenQuery && vite'",
"build": "npx vite build",
"preview": "vite preview"
},
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"packageManager": "[email protected]",
"scripts": {
"test": "turbo test",
"test:emulator": "firebase emulators:exec --project test-project \"pnpm turbo test:ci\"",
"test:emulator": "firebase emulators:exec --project demo-test-project \"pnpm turbo test:ci\"",
"serve:coverage": "npx serve coverage",
"emulator": "firebase emulators:start --project test-project",
"emulator": "firebase emulators:start --project demo-test-project",
"emulator:kill": "lsof -t -i:4001 -i:8080 -i:9000 -i:9099 -i:9199 -i:8085 -i:9399 -i:9299 | xargs kill -9",
"format": "biome check .",
"format:fix": "biome check . --write",
Expand Down
6 changes: 3 additions & 3 deletions packages/react/vitest/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { expect } from "vitest";
import { connectorConfig } from "@/dataconnect/default-connector";

const firebaseTestingOptions = {
projectId: "test-project",
projectId: "demo-test-project",
apiKey: "test-api-key",
authDomain: "test-auth-domain",
};
Expand All @@ -38,7 +38,7 @@ if (!firebaseApp) {

async function wipeFirestore() {
const response = await fetch(
"http://localhost:8080/emulator/v1/projects/test-project/databases/(default)/documents",
"http://localhost:8080/emulator/v1/projects/demo-test-project/databases/(default)/documents",
{
method: "DELETE",
},
Comment on lines 40 to 44

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve maintainability and avoid hardcoding the project ID in multiple places within this file, you can use the projectId from the firebaseTestingOptions constant. This ensures that if the project ID changes in the future, you only need to update it in one place.

Suggested change
const response = await fetch(
"http://localhost:8080/emulator/v1/projects/test-project/databases/(default)/documents",
"http://localhost:8080/emulator/v1/projects/demo-test-project/databases/(default)/documents",
{
method: "DELETE",
},
const response = await fetch(
`http://localhost:8080/emulator/v1/projects/${firebaseTestingOptions.projectId}/databases/(default)/documents`,
{
method: "DELETE",
},

Expand All @@ -51,7 +51,7 @@ async function wipeFirestore() {

async function wipeAuth() {
const response = await fetch(
"http://localhost:9099/emulator/v1/projects/test-project/accounts",
"http://localhost:9099/emulator/v1/projects/demo-test-project/accounts",
{
method: "DELETE",
},
Comment on lines 53 to 57

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the wipeFirestore function, you can use the projectId from firebaseTestingOptions here to avoid hardcoding and improve maintainability.

Suggested change
const response = await fetch(
"http://localhost:9099/emulator/v1/projects/test-project/accounts",
"http://localhost:9099/emulator/v1/projects/demo-test-project/accounts",
{
method: "DELETE",
},
const response = await fetch(
`http://localhost:9099/emulator/v1/projects/${firebaseTestingOptions.projectId}/accounts`,
{
method: "DELETE",
},

Expand Down
Loading