Skip to content
This repository was archived by the owner on Jun 10, 2026. It is now read-only.

feat: deliver frontend auth flow#4

Merged
0-sayed merged 12 commits into
mainfrom
feat/t003-frontend-auth-delivery
Jun 2, 2026
Merged

feat: deliver frontend auth flow#4
0-sayed merged 12 commits into
mainfrom
feat/t003-frontend-auth-delivery

Conversation

@0-sayed

@0-sayed 0-sayed commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add browser-ready signup, signin, logout, and protected app flows.
  • Wire API CORS/runtime metadata fixes and document the auth delivery notes.

Summary by cubic

Delivers a browser-ready auth flow with signup, signin, logout, and a protected app route. Updates API CORS, hardens redirects/session bootstrapping, and adds a Playwright browser smoke test to complete T003 by wiring the React app to /auth/signup, /auth/signin, and /auth/me.

  • New Features

    • Added React routes /signup, /signin, /app with RequireAuth and an AuthProvider that persists tokens and boots the current user from /auth/me.
    • Built API client with VITE_API_URL support and localStorage session handling; forms use react-hook-form + zod.
    • Migrated styling to Tailwind via @tailwindcss/vite and tailwindcss; added tests with vitest, @testing-library/react, and a Playwright browser smoke test via @playwright/test with pnpm test:browser and README steps.
  • Bug Fixes

    • Enabled CORS for http://127.0.0.1:${WEB_PORT} and http://localhost:${WEB_PORT} with Authorization and Content-Type; added preflight E2E coverage.
    • Made Nest DI explicit with @Inject and corrected user schema field types.
    • Sanitized signin redirect paths and prevented stale bootstrap requests from overwriting a new session; handled empty validation errors and preserved forced-colors focus outlines.

Written for commit 20266cb. Summary will update on new commits.

Review in cubic

0-sayed added 3 commits June 2, 2026 23:21
Enable the configured web origin for auth calls and make runtime metadata explicit where the browser-driven E2E flow exposed it.
Add signup, signin, protected app routing, session storage, form validation, Tailwind styling, and focused browser-facing tests.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request implements the frontend authentication flow, including sign-up, sign-in, and protected application pages, styled with Tailwind CSS and backed by Zod validation and React Router. On the backend, CORS is configured to allow requests from the frontend origin, and dependency injection is updated with explicit @Inject decorators. Feedback on these changes highlights several key areas for improvement: addressing a potential race condition and optimizing function stability with useCallback in AuthProvider.tsx, handling array-based validation error messages from NestJS in the API helper, preventing layout shifts in the sign-up page by unconditionally rendering the error slot, and securing the sign-in redirect logic against open redirect vulnerabilities.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread apps/web/src/auth/AuthProvider.tsx
Comment thread apps/web/src/auth/AuthProvider.tsx
Comment thread apps/web/src/auth/AuthProvider.tsx
Comment thread apps/web/src/auth/api.ts
Comment thread apps/web/src/pages/SignupPage.tsx Outdated
Comment thread apps/web/src/pages/SigninPage.tsx
@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR implements a complete authentication system for a monorepo application. On the backend, the API gains explicit NestJS dependency injection decorators, CORS configuration pinned to a configurable web origin, refined User schema property annotations, and an e2e test validating CORS preflight handling. On the frontend, the web app adds npm dependencies for form handling, routing, and validation, migrates global CSS to a Tailwind-based system with design tokens, implements auth infrastructure (API client, session token storage, form validation schemas), provides an AuthProvider context managing login state and user data, protects routes with RequireAuth, and adds SignupPage, SigninPage, and ApplicationPage components. Integration tests verify the complete authentication flow across protected and public routes.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title 'feat: deliver frontend auth flow' accurately reflects the main changes—implementing a complete browser-ready authentication system with signup, signin, logout, and protected routes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description comprehensively relates to the changeset, detailing frontend auth flows, API CORS fixes, and documentation updates that align with the actual changes across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
apps/api/src/users/schemas/user.schema.ts (1)

5-5: 💤 Low value

Minor: index: true is redundant alongside unique: true.

Mongoose's unique: true implicitly creates an index, so the explicit index: true is redundant. However, this is harmless and may improve clarity.

♻️ Optional simplification
-  `@Prop`({ index: true, lowercase: true, required: true, trim: true, type: String, unique: true })
+  `@Prop`({ lowercase: true, required: true, trim: true, type: String, unique: true })
   email!: string;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/api/src/users/schemas/user.schema.ts` at line 5, The `@Prop` decorator
includes both index: true and unique: true which is redundant because Mongoose
creates an index for unique fields; remove index: true from the options in the
`@Prop`(...) call (the decorator that currently reads { index: true, lowercase:
true, required: true, trim: true, type: String, unique: true }) so it becomes {
lowercase: true, required: true, trim: true, type: String, unique: true }; keep
unique: true and other flags unchanged and only re-add index: true if there is a
specific reason documented.
apps/web/src/auth/api.ts (1)

67-81: 💤 Low value

Consider adding more descriptive runtime validation errors.

The error messages "Unexpected authentication response." and "Unexpected current user response." are generic. Including details about which fields failed validation would improve debugging during development.

♻️ Example with more detail
 function readAuthResponse(body: unknown): AuthResponse {
   if (!isObject(body) || typeof body.accessToken !== "string" || !isPublicUser(body.user)) {
-    throw new Error("Unexpected authentication response.");
+    throw new Error(
+      "Unexpected authentication response. Expected { accessToken: string, user: { id, email, name } }"
+    );
   }

   return { accessToken: body.accessToken, user: body.user };
 }

 function readCurrentUser(body: unknown): PublicUser {
   if (!isObject(body) || !isPublicUser(body.user)) {
-    throw new Error("Unexpected current user response.");
+    throw new Error(
+      "Unexpected current user response. Expected { user: { id, email, name } }"
+    );
   }

   return body.user;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/auth/api.ts` around lines 67 - 81, Update readAuthResponse and
readCurrentUser to throw more descriptive runtime validation errors that include
which expected fields are missing or have the wrong type; for example, when
readAuthResponse sees !isObject(body), missing/invalid accessToken, or invalid
user, construct and throw an Error that indicates which of those checks failed
(mention accessToken type and user validation via isPublicUser), and do the same
in readCurrentUser to report whether body is not an object or body.user failed
isPublicUser validation so logs show which field caused the failure.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/api/src/app.e2e.test.ts`:
- Around line 53-67: Update the CORS preflight test inside the "allows frontend
auth preflight requests from the configured web origin" it-block (the
request(...).options("/auth/signup") call) to assert that the response includes
both the Authorization header and POST method: check
response.headers["access-control-allow-headers"] (or its lowercase variant)
contains "Authorization" and response.headers["access-control-allow-methods"]
contains "POST" so the test fails if CORS removes required auth headers or
methods.

In `@apps/web/src/auth/AuthProvider.unit.test.tsx`:
- Around line 61-65: The synchronous assertions after clicking the "Sign in"
button are flaky because the click handler calls signin(...) without returning
its promise; change the test to wait for the post-signin state by replacing the
direct expects with an asynchronous wait (e.g., use waitFor to assert
localStorage has "easygen.accessToken" set to "token-123" and/or use
findByText("Person Name") or waitFor(() => expect(screen.getByText("Person
Name")).toBeInTheDocument())); update the test around the userEvent.click call
in AuthProvider.unit.test.tsx to await the appropriate waitFor/findBy* so
setAccessToken/setUser changes settle before asserting.

In `@apps/web/src/pages/authStyles.ts`:
- Around line 3-10: The focus outline utilities should use outline-hidden for
forced-colors accessibility: update the button class (the top-level button class
string that contains focus-visible:outline-none) to use
focus-visible:outline-hidden, and update the input class (the input key's string
that contains outline-none) to use outline-hidden instead; keep all other
classes and spacing identical.

---

Nitpick comments:
In `@apps/api/src/users/schemas/user.schema.ts`:
- Line 5: The `@Prop` decorator includes both index: true and unique: true which
is redundant because Mongoose creates an index for unique fields; remove index:
true from the options in the `@Prop`(...) call (the decorator that currently reads
{ index: true, lowercase: true, required: true, trim: true, type: String,
unique: true }) so it becomes { lowercase: true, required: true, trim: true,
type: String, unique: true }; keep unique: true and other flags unchanged and
only re-add index: true if there is a specific reason documented.

In `@apps/web/src/auth/api.ts`:
- Around line 67-81: Update readAuthResponse and readCurrentUser to throw more
descriptive runtime validation errors that include which expected fields are
missing or have the wrong type; for example, when readAuthResponse sees
!isObject(body), missing/invalid accessToken, or invalid user, construct and
throw an Error that indicates which of those checks failed (mention accessToken
type and user validation via isPublicUser), and do the same in readCurrentUser
to report whether body is not an object or body.user failed isPublicUser
validation so logs show which field caused the failure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1d50f1f2-cbb3-47d4-a6fa-0de919920722

📥 Commits

Reviewing files that changed from the base of the PR and between e346501 and 94b9f0b.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (31)
  • AI.md
  • README.md
  • apps/api/src/app.e2e.test.ts
  • apps/api/src/auth/auth.controller.ts
  • apps/api/src/auth/auth.service.ts
  • apps/api/src/auth/jwt-auth.guard.ts
  • apps/api/src/configure-app.ts
  • apps/api/src/users/schemas/user.schema.ts
  • apps/api/src/users/users.service.ts
  • apps/web/package.json
  • apps/web/src/App.tsx
  • apps/web/src/auth/AuthProvider.tsx
  • apps/web/src/auth/AuthProvider.unit.test.tsx
  • apps/web/src/auth/RequireAuth.tsx
  • apps/web/src/auth/api.ts
  • apps/web/src/auth/api.unit.test.ts
  • apps/web/src/auth/session.ts
  • apps/web/src/auth/session.unit.test.ts
  • apps/web/src/auth/validation.ts
  • apps/web/src/auth/validation.unit.test.ts
  • apps/web/src/index.css
  • apps/web/src/main.tsx
  • apps/web/src/pages/ApplicationPage.tsx
  • apps/web/src/pages/SigninPage.tsx
  • apps/web/src/pages/SignupPage.tsx
  • apps/web/src/pages/auth-pages.unit.test.tsx
  • apps/web/src/pages/authStyles.ts
  • apps/web/src/test/setup.ts
  • apps/web/src/vite-env.d.ts
  • apps/web/tsconfig.json
  • apps/web/vite.config.ts

Comment thread apps/api/src/app.e2e.test.ts
Comment thread apps/web/src/auth/AuthProvider.unit.test.tsx
Comment thread apps/web/src/pages/authStyles.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3 issues found across 32 files

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

Comment thread apps/api/src/configure-app.ts Outdated
Comment thread apps/web/src/auth/AuthProvider.tsx Outdated
Comment thread apps/web/src/auth/AuthProvider.unit.test.tsx
@0-sayed 0-sayed self-assigned this Jun 2, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 issues found across 8 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread apps/web/src/auth/api.ts
Comment thread .github/workflows/auto-assign-pr.yml Outdated
@0-sayed 0-sayed merged commit e9515cb into main Jun 2, 2026
13 checks passed
@0-sayed 0-sayed deleted the feat/t003-frontend-auth-delivery branch June 2, 2026 21:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant