Firebase Console Setup
Firebase is a Google-backed platform that provides backend-as-a-service. For NetDocs, we use their Authentication module.
Create Project
Go to the Firebase Console and click Add Project. Give it a name and click through the setup.
Enable Auth
In the sidebar, go to Authentication → Get Started. Enable the Email/Password and Google sign-in methods.
Register Web App
Click the </> icon in your project overview to register a web app. Copy the firebaseConfig object — you'll need it later.
SDK Integration
Include the Firebase SDK in your project. We'll use the modular v9+ syntax for better performance.
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.22.0/firebase-app.js"; import { getAuth } from "https://www.gstatic.com/firebasejs/9.22.0/firebase-auth.js"; const firebaseConfig = { apiKey: "YOUR_API_KEY", authDomain: "YOUR_PROJECT.firebaseapp.com", projectId: "YOUR_PROJECT_ID", // ... other config values }; const app = initializeApp(firebaseConfig); export const auth = getAuth(app);
Authentication Logic
Creating a simple sign-up function using Email and Password.
import { createUserWithEmailAndPassword } from "..."; export const signUp = (email, password) => { createUserWithEmailAndPassword(auth, email, password) .then((userCredential) => { const user = userCredential.user; console.log("User signed up:", user); }) .catch((error) => { console.error("Error signing up:", error.message); }); };
Handling User State
Use the onAuthStateChanged listener to detect when a user logs in or out and update your UI accordingly.