Thuta Learning
ExercisesDevOps & Toolsintermediate

Exercise — Auth and Firestore Basics

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Get hands-on practice with Auth and Firestore Basics
  • Reinforce the skills you've already learned by practicing them
  • Get comfortable finding bugs, fixing them, and checking your own work

Take a moment to think about this

This lesson is about redoing, by typing it out yourself rather than copying from memory, what you learned earlier in the tutorial's Authentication and Firestore chapters. The focus is on writing separate signup/login/logout functions and making sure the UI updates every time the auth state changes. It also gives you practice with the full cycle of adding, reading, updating, and deleting a Firestore document. You're not writing new code here — you're just putting concepts you've already learned back into practice.

Practice Tasks

Task 1 — In a new (or existing) Firebase project, write a signup form using Email/Password auth. Task 2 — Once a user is logged in, show their email in the navbar, and make sure clicking the Logout button signs them out and sends them back to the login page. Task 3 — For the logged-in user, create a notes collection in Firestore and add a new note document. Task 4 — Read that document in realtime with onSnapshot, update its title field, and finally delete the document.

Code Sample

javascript
// Task skeleton — ကိုယ်တိုင်ဖြည့်စွက်ရန်
import { auth, db } from "./firebase-config";
import {
  createUserWithEmailAndPassword,
  signInWithEmailAndPassword,
  signOut,
  onAuthStateChanged,
} from "firebase/auth";
import {
  collection,
  addDoc,
  doc,
  updateDoc,
  deleteDoc,
  onSnapshot,
} from "firebase/firestore";

// Task 1: Signup
async function signup(email, password) {
  // TODO: createUserWithEmailAndPassword သုံးပါ
}

// Task 2: Login state watch
onAuthStateChanged(auth, (user) => {
  // TODO: user ရှိ/မရှိ အလိုက် UI update လုပ်ပါ
});

// Task 3: Note document add
async function addNote(uid, title) {
  // TODO: notes collection ထဲ addDoc
}

// Task 4: Update + Delete
async function updateNoteTitle(noteId, newTitle) {
  // TODO: updateDoc သုံးပါ
}
async function removeNote(noteId) {
  // TODO: deleteDoc သုံးပါ
}
You should see
Signup/login/logout should work smoothly, and you should be able to add, update, and delete a document in the notes collection without hitting any errors.

Try It in 5 Minutes

Try to get just Task 1 and Task 2 done within 5 minutes — check the user state with console.log every time you click the login/logout button.

A Quick Word of Caution

While practicing, use a separate test project or test collection in the Firebase Console so you don't mix things up with real user accounts.

Easy traps

  • Using user.email directly inside the onAuthStateChanged callback without checking whether user could be null tends to throw errors
  • Not saving the docRef.id returned by addDoc means you can end up unable to find the document ID when it's time to update or delete it

Now Try It Yourself

Try to get just Task 1 and Task 2 done within 5 minutes — check the user state with console.log every time you click the login/logout button.

You'll know it worked when: Signup/login/logout should work smoothly, and you should be able to add, update, and delete a document in the notes collection without hitting any errors.

Exercise — Auth and Firestore Basics | Thuta Learning