Skip to main content
The starter template uses Zustand for state management and supports both local and Firebase authentication.

State Management

Zustand Store

The app uses Zustand with localStorage persistence (lib/store.ts):

Store State Shape

Using Selectors

Access specific state slices to avoid unnecessary re-renders:

Storage Key

All data persists under the localStorage key: ttai-app-store

Authentication

The template supports two authentication modes:

1. Local User Auth (No Setup Required)

Simple auth for development or apps that don’t need full authentication:

2. Firebase Auth (Google OAuth)

Full authentication with Firebase:

AuthContext Provider

The AuthContext wraps your app in app/layout.tsx:

Using Auth in Components

Protecting Routes

Use the AuthGuard component:

Firebase Setup

1

Create Firebase Project

Go to Firebase Console and create a new project.
2

Enable Authentication

Navigate to Authentication β†’ Sign-in method and enable:
  • Email/Password
  • Google
3

Get Config

Go to Project Settings β†’ General β†’ Your apps β†’ Web app. Copy the configuration object.
4

Add Environment Variables

.env.local
All Firebase config variables must be prefixed with NEXT_PUBLIC_ to be accessible in the browser. Never commit .env.local to version control!

Integrating Auth with ToughTongue

Pass user info to scenarios:
Store sessions with user context:

Troubleshooting

Solution:
  • Double-check all Firebase config values in .env.local
  • Ensure all 6 Firebase variables are set
  • Restart dev server after changes
Solution: - Verify Google provider is enabled in Firebase Console - Add your domain to authorized domains in Firebase Console β†’ Authentication β†’ Settings - For localhost, it should be authorized by default
Cause: Zustand store uses localStorage (per-browser, per-domain).Notes:
  • Clearing browser data clears saved results
  • Data doesn’t sync across browsers/devices
  • For production, consider syncing to Firestore

Next Steps

Deployment

Deploy to production

API Reference

Full API documentation