Skip to content

feat(auth): Firebase sign-in and ID token on API requests - #35

Merged
KALalev18 merged 3 commits into
mainfrom
feat/firebase-auth
Oct 28, 2026
Merged

KALalev18 merged 3 commits into
mainfrom
feat/firebase-auth

Conversation

@KALalev18

Copy link
Copy Markdown
Contributor

Closes #8, closes #22.

  • Sign up, log in and log out with Firebase Email/Password; the session survives reload, and private pages wait until Firebase has restored it.
  • Readable error messages (wrong password, existing account, weak password, network).
  • Every API request gets a fresh ID token; a 401 is retried once with a refreshed token, and a second 401 signs the user out.
  • Without VITE_FIREBASE_API_KEY, the demo sign-in still works, so the mock and the acceptance tests are unchanged.
  • .gitignore now also ignores .env and .env.* (except .env.example).
  • Tested manually with the shared dev project (alice): log in, wrong password, existing account, reload, sign out.

Not yet tested: the /api/auth/me smoke test against the backend.

@KALalev18
KALalev18 requested a review from kctong529 October 24, 2026 08:35
@KALalev18 KALalev18 self-assigned this Oct 24, 2026
- return repeated 401 errors after one token refresh attempt instead
  of unconditionally signing the user out
- update HTTP client tests for failed refresh and empty responses
- document verified Firebase authentication and backend user resolution
- clarify that application-user IDs and ownership remain backend concerns

@kctong529 kctong529 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review — Approved

Thanks for implementing Firebase authentication! This is an important step toward our Increment 2 goal of completing a real end-to-end workflow, introducing Firebase authentication alongside the existing demo mode and enabling authenticated backend requests.

I reviewed the implementation and tested it locally against backend PR #41 (feat/firebase-user-resolution), with real Firebase accounts and PostgreSQL enabled.

Implementation and architecture

The separation between Firebase authentication (auth.ts), the shared HTTP client (api/http.ts), and the live/mock API adapters looks good. In particular, centralizing ID token attachment means individual screens don't need to handle Firebase tokens themselves.

Backend #41 introduces persistent application-user resolution: the backend verifies the Firebase ID token and maps its UID to an internal PostgreSQL user UUID. The frontend already maintains the appropriate separation of responsibilities by handling authentication and attaching tokens, while application-user resolution remains a backend concern.

Integration tests performed

Area Verification Result
Registration Created an account through Get started → Create your account and confirmed it in the Firebase Console Passed
Login Signed in successfully with existing and newly registered accounts Passed
Authentication errors Verified incorrect credentials, successful recovery, and repeated failed attempts without the form getting stuck Passed
Session persistence Refreshed the dashboard and confirmed the Firebase session and route were preserved Passed
Frontend route protection Verified signed-out redirects, direct navigation, return to the originally requested route, and browser history after logout Passed
Token attachment Confirmed that the shared HTTP client attaches Firebase ID tokens to outgoing API requests Passed
Backend compatibility Temporarily called backend #41's protected /api/users/me endpoint through the frontend HTTP client, confirming successful backend verification of the attached Firebase ID token Passed
Application-user resolution Verified that two Firebase accounts resolve to distinct, persistent PostgreSQL user UUIDs, including after refresh Passed

The /api/users/me call was added temporarily for integration testing and removed afterward. It is not part of the frontend's normal authentication flow.

These tests verify both the frontend's implemented authentication features and their compatibility with the backend's Firebase token verification and user-resolution infrastructure. They do not establish authentication or ownership enforcement for the existing trip endpoints, which remains separate backend work.

Improvements and automated verification

I also incorporated a few follow-up improvements during review:

  • Changed the HTTP client to return the backend error after a second 401 instead of unconditionally signing out. A repeated 401 can indicate a backend configuration problem rather than an invalid Firebase session.
  • Extended the HTTP-client tests to cover this behavior, failed forced token refresh, and empty 204 responses.
  • Updated the README to document Firebase integration, backend user resolution, and current limitations.
  • Isolated Playwright acceptance tests from local Firebase/backend configuration so they consistently use the intended mock environment.

Final verification:

Check Result
Lint Passed — 29 warnings, 0 errors
Production build Passed
TypeScript typecheck Passed
Focused API-client tests 14/14 passed
Full Playwright acceptance suite Passed
Manual Firebase/backend integration tests Passed

Scope and remaining work

The scope is appropriate for the authentication issues and our updated project plan. The frontend can now authenticate users and attach Firebase ID tokens to backend requests.

One important limitation remains: the current trip endpoints don't yet enforce ownership using the resolved application-user identity. Likewise, most photo and upload operations remain mocked. These are separate integration tasks, not blockers for this authentication PR.

Approved. The implementation has been verified, the review findings have been addressed, and this provides a solid foundation for the next backend integration work.

Explicitly disable Firebase and live backend integration in the
Playwright test server so acceptance tests always run with mock data,
regardless of the developer's .env.local configuration.
@kctong529 kctong529 moved this from Backlog to In review in MapMory Project Board Oct 24, 2026
@KALalev18
KALalev18 merged commit 04c6e2f into main Oct 28, 2026
2 checks passed
@KALalev18
KALalev18 deleted the feat/firebase-auth branch October 28, 2026 09:46
@github-project-automation github-project-automation Bot moved this from In review to Done in MapMory Project Board Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Attach Firebase authentication to backend API requests Add Firebase sign-in

2 participants