You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4e491c6
Browse filesBrowse the repository at this point in the historyBrowse files
fix(web): address CodeRabbit review findings on auth layer
Security:
- Verify Firebase ID tokens with firebase-admin verifyIdToken() instead
of decoding the JWT payload without signature verification; add
lib/firebase-admin.ts with singleton Admin app init
- Sign out of Firebase client alongside NextAuth in useSignOut hook to
prevent stale Firebase auth state after logout
Correctness:
- Preserve query string in callbackUrl (proxy.ts) so users are returned
to their original URL with params after login
- Restore sidebar open/close state from cookie in DashboardLayout by
reading the sidebar_state cookie server-side and passing as defaultOpen
- Fix NavAuth test mock shape: use user instead of session to match the
UseSessionReturn type
- Handle popup-dismissed Firebase errors silently in GoogleSignInButton;
disable button while sign-in is in flight
Quality:
- Switch to z.email() (Zod v4.4.3+) from deprecated z.string().email()
- Update docs/auth.md to accurately describe the Firebase idToken flow
- Fix stale middleware.ts reference in docs/_index.md to proxy.ts
- Add FIREBASE_PROJECT_ID and FIREBASE_SERVICE_ACCOUNT_JSON to
web/.env.example
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
-**`handlers`** — `{ GET, POST }` for the route handler.
45
-
-**`auth()`** — async function; call in Server Components, Server Actions, and middleware to read the session.
56
+
-**`auth()`** — async function; call in Server Components, Server Actions, and proxy to read the session.
46
57
-**`signIn(provider, options)`** — trigger sign-in from server context.
47
58
-**`signOut(options)`** — trigger sign-out from server context.
48
59
49
-
### Providers
60
+
### Provider
50
61
51
-
**Google**— reads `AUTH_GOOGLE_ID` / `AUTH_GOOGLE_SECRET` from env.
62
+
Single **Credentials**provider that accepts `{ idToken: string }`.
52
63
53
-
**Credentials** — validates email + password with Zod, then proxies a `POST` to `${NEXT_PUBLIC_API_URL}/auth/login`. Returns `{ id, email, name }` on success or `null` on failure.
64
+
`authorize()`:
65
+
1. Validates `idToken` is a non-empty string with Zod.
- Exports inferred types `LoginFormValues` and `RegisterFormValues`.
171
204
205
+
Used with `standardSchemaResolver` from `@hookform/resolvers/standard-schema` (required for Zod v4).
206
+
172
207
## Auth components (`features/auth/components/`)
173
208
174
-
All are `'use client'` components.
209
+
All are `'use client'` components. Errors are surfaced via Sonner toasts, not inline error state.
175
210
176
211
### `LoginForm`
177
212
178
-
`react-hook-form` with `standardSchemaResolver(loginSchema)` from `@hookform/resolvers/standard-schema`. Calls `signIn('credentials', { redirect: false })` from `next-auth/react` on submit, then pushes to `/dashboard` on success. Displays an inline error string on failure.
213
+
`react-hook-form` with `standardSchemaResolver(loginSchema)`. On submit:
214
+
1.`signInWithEmailAndPassword(getFirebaseAuth(), email, password)` via Firebase.
215
+
2. Retrieves ID token from the credential.
216
+
3.`signIn('credentials', { idToken, redirect: false })` via NextAuth.
217
+
4. Pushes to `/dashboard` on success; shows `toast.error` on failure.
179
218
180
219
### `RegisterForm`
181
220
182
-
Same form setup with `registerSchema`. On submit: POSTs to `${NEXT_PUBLIC_API_URL}/auth/register`, then calls `signIn('credentials', { redirect: false })` to sign in immediately after registration. Pushes to `/dashboard` on success.
|`/login`|`app/(auth)/login/page.tsx`| Server Component |
215
269
|`/register`|`app/(auth)/register/page.tsx`| Server Component |
216
270
|`/dashboard`|`app/(dashboard)/dashboard/page.tsx`| Server Component |
271
+
|`/settings`|`app/(dashboard)/settings/page.tsx`| Server Component |
217
272
218
273
Login and Register pages are layout-less Server Components that render a centered `Card` containing `GoogleSignInButton`, a divider, the form, and a link to the other page.
219
274
@@ -222,9 +277,14 @@ Login and Register pages are layout-less Server Components that render a centere
222
277
| Variable | Description |
223
278
|---|---|
224
279
|`AUTH_SECRET`| Secret used to sign JWTs. Generate with `openssl rand -base64 32`. |
225
-
|`AUTH_GOOGLE_ID`| Google OAuth client ID. |
226
-
|`AUTH_GOOGLE_SECRET`| Google OAuth client secret. |
227
-
|`NEXT_PUBLIC_API_URL`| Go backend base URL (e.g. `http://localhost:8080`). Used by Credentials provider and RegisterForm. |
280
+
|`FIREBASE_PROJECT_ID`| Firebase project ID (server-side). Used when `FIREBASE_SERVICE_ACCOUNT_JSON` is absent and ADC is available (GCP). |
281
+
|`FIREBASE_SERVICE_ACCOUNT_JSON`| Full service account JSON as a single-line string. Required outside GCP for `verifyIdToken`. |
282
+
|`NEXT_PUBLIC_FIREBASE_API_KEY`| Firebase web API key. |
0 commit comments