Create a Firebase project, add auth providers, and build sign-up/login/logout flows.
npm install firebaseimport { initializeApp } from 'firebase/app';
import { getAuth } from 'firebase/auth';
import { getFirestore } from 'firebase/firestore';
const firebaseConfig = {
apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
authDomain: 'your-app.firebaseapp.com',
projectId: 'your-app-id',
storageBucket: 'your-app.appspot.com',
messagingSenderId: '123456789',
appId: '1:123456789:web:abcdef'
};
const app = initializeApp(firebaseConfig);
export const auth = getAuth(app);
export const db = getFirestore(app);import { auth } from './firebase';
import {
createUserWithEmailAndPassword,
signInWithEmailAndPassword,
signInWithPopup,
GoogleAuthProvider,
signOut,
onAuthStateChanged
} from 'firebase/auth';
// Sign up
await createUserWithEmailAndPassword(auth, email, password);
// Login
await signInWithEmailAndPassword(auth, email, password);
// Google OAuth
const provider = new GoogleAuthProvider();
await signInWithPopup(auth, provider);
// Logout
await signOut(auth);
// Listen to auth state
onAuthStateChanged(auth, (user) => {
if (user) console.log('Logged in:', user.uid);
else console.log('Logged out');
});createUserWithEmailAndPassword, signInWithEmailAndPassword, signOut — the core auth methods.onAuthStateChanged is the auth state listener. Use it to update your app's UI.