Thuta Learning
IntermediateDevOps & Toolsintermediate

Logging out

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

Logging out

Logout is the action that closes the user's session and sends them away from protected pages. In Firebase, you use signOut.

Code Example

javascript
import { getAuth, signOut } from 'firebase/auth';

const auth = getAuth();

async function logout() {
  try {
    await signOut(auth);
    console.log('Logout successful');
  } catch (error) {
    console.log('Logout failed:', error.message);
  }
}

logout();

What does this code do?

signOut closes out the Firebase Auth session. Once logout is done, the user in the onAuthStateChanged listener becomes null, so the UI can switch over to the Login page.

Best practice

After logging out, you should also clear out any user-specific UI state, draft data, and private cache. It's better for the app to start fresh and clean.

Logging out | Thuta Learning