Skip to content

Enhance auth context with abort signals and user data updatesai#46

Merged
Ross1116 merged 3 commits into
mainfrom
staging
Mar 6, 2026
Merged

Enhance auth context with abort signals and user data updatesai#46
Ross1116 merged 3 commits into
mainfrom
staging

Conversation

@Ross1116

@Ross1116 Ross1116 commented Mar 6, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Company name now appears in user profile.
  • Bug Fixes

    • Reduced noise in error reporting by filtering common non-error extension messages.
    • Profile UI now consistently reflects the authenticated user instead of stale cached data.
  • Chores

    • Improved auth initialization and request cancellation for more robust login flow.
    • Adjusted data-fetching behavior to reduce unnecessary revalidation and duplicate calls.
  • Documentation

    • Updated SWR docs to reflect new revalidation and deduplication behavior.

@vercel

vercel Bot commented Mar 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sitespace-app Ready Ready Preview, Comment Mar 6, 2026 6:52am

@Ross1116 Ross1116 changed the title @coderabbitia @coderabbitai Mar 6, 2026
@coderabbitai

coderabbitai Bot commented Mar 6, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Adds Sentry event filtering for known non-error messages, extends AuthContext to accept AbortSignal and include company_name, removes client-side SWR profile fetch in favor of AuthContext user data on the home page, and updates global SWR defaults (disable focus revalidate, increase dedupe window).

Changes

Cohort / File(s) Summary
Sentry configuration
sentry.client.config.ts
Introduce IGNORED_VALUES regex and a beforeSend hook to drop Sentry events whose exception value matches known non-error patterns (browser extensions/password managers).
Auth context & types
src/app/context/AuthContext.tsx, src/types/auth.ts
checkAuth now accepts an optional AbortSignal and maps company_name; initial/login flows use AbortController with cleanup; AbortError and TypeError are treated as non-errors (not reported to Sentry).
Home page UI
src/app/(dashboard)/home/page.tsx
Remove SWR-based profile fetching and related types; UI now reads identity (name, role, company, avatar, email) from AuthContext with loading Skeletons when auth is loading.
SWR defaults & docs
src/lib/swr.ts, README.md
Change global SWR defaults: revalidateOnFocus: false, dedupingInterval: 60000; README updated to document trade-offs and that profile identity is provided by AuthContext.

Sequence Diagram(s)

sequenceDiagram
  participant Browser as Browser
  participant AuthCtx as AuthContext (client)
  participant API as /api/auth/me
  participant Sentry as Sentry SDK

  Browser->>AuthCtx: mount / login trigger
  AuthCtx->>AuthCtx: create AbortController (signal)
  AuthCtx->>API: fetch /api/auth/me (with signal)
  API-->>AuthCtx: 200 OK + user data (includes company_name)
  AuthCtx->>AuthCtx: map user, set state
  Browser->>Sentry: capture error event
  Sentry-->>Sentry: beforeSend checks exception value against IGNORED_VALUES
  alt matches IGNORED_VALUES
    Sentry-->>Browser: drop event (return null)
  else
    Sentry-->>Browser: send event to server
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I hopped with signals, tidy and light,
tucked company names in by moonlight,
I sniffed out noisy extension cries,
silenced them soft with regex wise,
and let SWR breathe—quiet night. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed Title check skipped as CodeRabbit has written the PR title.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch staging

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 changed the title @coderabbitai Enhance auth context with abort signals and user data updatesai Mar 6, 2026

@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: 1

🧹 Nitpick comments (1)
src/app/(dashboard)/home/page.tsx (1)

196-198: Minor: "Loading..." fallback is misleading when user exists without first_name.

If the user object is present but first_name is empty/undefined, this displays "Loading..." which is inaccurate. Consider aligning with the greeting fallback pattern:

💡 Suggested fix
 <p className="text-sm font-bold text-slate-900 truncate">
-  {user?.first_name
-    ? `${user.first_name} ${user.last_name ?? ""}`.trim()
+  {user
+    ? (user.first_name ? `${user.first_name} ${user.last_name ?? ""}`.trim() : user.email)
     : "Loading..."}
 </p>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/`(dashboard)/home/page.tsx around lines 196 - 198, The current JSX
ternary checks user?.first_name and shows "Loading..." when first_name is
missing even though a user exists; change the condition to check for user (not
first_name), construct the display name from both user.first_name and
user.last_name (trim the concatenation), and only fall back to the existing
greeting fallback (e.g., "Loading..." or the same greeting used elsewhere) if
the trimmed name is empty; update the JSX expression that references user,
user.first_name, and user.last_name accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/swr.ts`:
- Around line 6-10: Add a concise explanatory comment next to the SWR_CONFIG
export documenting the API-load vs. data-staleness trade-off introduced by
revalidateOnFocus: false and dedupingInterval: 60_000 (and refreshInterval:
5*60*1000), and list the affected hooks (useBookingsListQuery,
useUpcomingBookingsQuery, useResolvedProjectSelection, useProjectSubcontractors)
plus the fact that useBookingMutations invalidates caches on mutation and the
calendar view overrides refreshInterval to 30s; also add or update a short entry
in the repo docs/README linking to this comment so future devs understand why
manual refreshes or tab-focus updates might be required for these features.

---

Nitpick comments:
In `@src/app/`(dashboard)/home/page.tsx:
- Around line 196-198: The current JSX ternary checks user?.first_name and shows
"Loading..." when first_name is missing even though a user exists; change the
condition to check for user (not first_name), construct the display name from
both user.first_name and user.last_name (trim the concatenation), and only fall
back to the existing greeting fallback (e.g., "Loading..." or the same greeting
used elsewhere) if the trimmed name is empty; update the JSX expression that
references user, user.first_name, and user.last_name accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d3fd06ea-aa34-4b9f-9074-6b33333cda52

📥 Commits

Reviewing files that changed from the base of the PR and between 4981d9d and f41ea03.

📒 Files selected for processing (5)
  • sentry.client.config.ts
  • src/app/(dashboard)/home/page.tsx
  • src/app/context/AuthContext.tsx
  • src/lib/swr.ts
  • src/types/auth.ts

Comment thread src/lib/swr.ts

@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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/app/(dashboard)/home/page.tsx (1)

172-201: ⚠️ Potential issue | 🟡 Minor

Avoid rendering a fake identity while auth is still loading.

When authLoading is true and user is still null, this header briefly shows "User 👋", "Member", and "U" before the real account data arrives. It would be better to gate these fallbacks behind authLoading or show a consistent skeleton/loading placeholder so the UI doesn’t momentarily present the wrong user identity.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/`(dashboard)/home/page.tsx around lines 172 - 201, The header is
rendering placeholder identity strings when user is null, causing a brief fake
identity flash; update the JSX around the top greeting, role/company block,
avatar initial, and name/email lines (where {user?.first_name ?
`${user.first_name} 👋` : "User 👋"}, {user?.role || "Member"}, the avatar
initial expression, and the name/email rendering) to instead check authLoading
and, if true, render a consistent loading state (e.g., a skeleton or
"Loading..." placeholders) — only fall back to the static defaults when
authLoading is false and user is null; ensure all occurrences (greeting,
role/company, avatar initial, and name/email) use the same authLoading-gated
logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@README.md`:
- Around line 269-275: Update the earlier "State Management" bullet that
currently claims SWR handles `profile` to reflect the new auth flow: remove or
replace the `profile` mention with a note that user/profile data is provided via
`AuthContext` (or the new auth provider), and add a brief pointer to the auth
source (e.g., `AuthContext`/auth flow) so the README is consistent with the SWR
trade-off description and `src/lib/swr.ts` rationale.

---

Outside diff comments:
In `@src/app/`(dashboard)/home/page.tsx:
- Around line 172-201: The header is rendering placeholder identity strings when
user is null, causing a brief fake identity flash; update the JSX around the top
greeting, role/company block, avatar initial, and name/email lines (where
{user?.first_name ? `${user.first_name} 👋` : "User 👋"}, {user?.role ||
"Member"}, the avatar initial expression, and the name/email rendering) to
instead check authLoading and, if true, render a consistent loading state (e.g.,
a skeleton or "Loading..." placeholders) — only fall back to the static defaults
when authLoading is false and user is null; ensure all occurrences (greeting,
role/company, avatar initial, and name/email) use the same authLoading-gated
logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a3188dfc-5bdc-49d5-a4bd-980c7ac2e5f7

📥 Commits

Reviewing files that changed from the base of the PR and between f41ea03 and d73c680.

📒 Files selected for processing (3)
  • README.md
  • src/app/(dashboard)/home/page.tsx
  • src/lib/swr.ts

Comment thread README.md

@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.

🧹 Nitpick comments (1)
src/app/(dashboard)/home/page.tsx (1)

202-202: Avatar initial may render empty during loading.

When authLoading is true, the avatar shows an empty string. Consider showing a skeleton or placeholder character for visual consistency.

💡 Optional: Add skeleton for avatar during loading
 <div className="h-10 w-10 rounded-full bg-slate-100 flex items-center justify-center text-slate-700 font-bold border border-slate-200 shadow-sm text-sm">
-  {authLoading ? "" : user?.first_name?.charAt(0) || user?.email?.charAt(0) || "U"}
+  {authLoading ? (
+    <Skeleton className="h-5 w-5 rounded-full" />
+  ) : (
+    user?.first_name?.charAt(0) || user?.email?.charAt(0) || "U"
+  )}
 </div>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/app/`(dashboard)/home/page.tsx at line 202, The avatar currently renders
an empty string when authLoading is true; update the JSX that renders
{authLoading ? "" : user?.first_name?.charAt(0) || user?.email?.charAt(0) ||
"U"} to show a consistent placeholder during loading (e.g., a skeleton component
or a fallback character like "U") instead of an empty string; locate the
expression using authLoading, user, first_name, and email in page.tsx and
replace the ternary to render either a Skeleton/Placeholder element or the
computed initial so the avatar never appears blank while loading.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/app/`(dashboard)/home/page.tsx:
- Line 202: The avatar currently renders an empty string when authLoading is
true; update the JSX that renders {authLoading ? "" :
user?.first_name?.charAt(0) || user?.email?.charAt(0) || "U"} to show a
consistent placeholder during loading (e.g., a skeleton component or a fallback
character like "U") instead of an empty string; locate the expression using
authLoading, user, first_name, and email in page.tsx and replace the ternary to
render either a Skeleton/Placeholder element or the computed initial so the
avatar never appears blank while loading.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4091a0e1-d77a-409e-8324-4de97e0a98ee

📥 Commits

Reviewing files that changed from the base of the PR and between d73c680 and 7e95e86.

📒 Files selected for processing (2)
  • README.md
  • src/app/(dashboard)/home/page.tsx

@Ross1116 Ross1116 merged commit cf87de7 into main Mar 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant