This guide explains how to modernize your client application to use Firebase Authentication and the Firebase Data Connect generated SDK.
- Bundler (Webpack, Vite, etc.): Data Connect SDKs are generated as ES Modules. Your project must support ES Modules.
- Firebase Web Config: Get this from Firebase Console > Project Settings > General.
Ensure your project is set up to bundle ES Modules. If you are using a tool like Vite/Webpack/Rollup, ensure it is configured to handle nodes_modules imports.
If you are starting fresh, we recommend initializing a modern JavaScript project:
npm init -y
npm install firebase
# Install your preferred bundler (e.g., vite, webpack)Ensure your HTML points to your entry script as a module if supported by your bundler/browser:
<script type="module" src="app.js"></script>Configure dataconnect/connector/connector.yaml to output the JS SDK:
generate:
javascriptSdk:
outputDir: "../../client-app/generated/js"
package: "@my-org/sdk"Run the generator:
firebase dataconnect:sdk:generateInstall the local SDK package:
cd client-app
npm install ./generated/jsReplace supabase.auth with firebase/auth.
Supabase:
const { data, error } = await supabase.auth.signInWithPassword({ email, password });Firebase:
import { getAuth, signInWithEmailAndPassword } from 'firebase/auth';
const auth = getAuth();
await signInWithEmailAndPassword(auth, email, password);Replace supabase.from('table') with Data Connect SDK functions (defined in queries.gql and mutations.gql).
Supabase:
const { data, error } = await supabase.from('todos').select('*');Data Connect:
import { listMyItems, getDataConnect, connectorConfig } from '@my-org/sdk';
import { getAuth } from 'firebase/auth';
const dataConnect = getDataConnect(connectorConfig);
const response = await listMyItems(dataConnect);
const items = response.data.items;Ensure you pass the uid if your mutations require it (e.g. CreateItem).
Note: Data Connect queries/mutations marked @auth(level: USER) will automatically use the Firebase Auth token if auth is initialized.
const user = getAuth().currentUser;
await createItem(dataConnect, {
title: "New Item",
uid: user.uid
});Run your dev server:
# Run your dev server (command depends on your tool)
npm run devOpen the local URL (e.g. http://localhost:3000) and verify Login and Todo operations.