Skip to content

fix: handle Supabase admin client absence in wakatime API route(closes #2233)#2261

Closed
shauryavardhan1307 wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
shauryavardhan1307:fix/wakatime-supabase-absence
Closed

fix: handle Supabase admin client absence in wakatime API route(closes #2233)#2261
shauryavardhan1307 wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
shauryavardhan1307:fix/wakatime-supabase-absence

Conversation

@shauryavardhan1307

Copy link
Copy Markdown
Contributor

Title

fix: handle Supabase admin client absence in wakatime API route


PR Body

## Summary

Safely guards the `/api/wakatime` route against unconfigured Supabase admin credentials by checking `isSupabaseAdminAvailable` and returning a clean fallback instead of throwing unhandled 500 errors. This prevents CI/Playwright test suites and local development setups without Supabase from failing.

Closes #2233 
---

## Type of Change

- [x] 🐛 Bug fix (non-breaking change that fixes an issue)
- [ ] ✨ New feature (non-breaking change that adds functionality)
- [ ] 💥 Breaking change (fix or feature that changes existing behavior)
- [ ] 📝 Documentation update
- [ ] ♻️ Refactor / code cleanup (no functional change)
- [ ] ⚡ Performance improvement
- [ ] 🔒 Security fix
- [ ] 🧪 Tests only

---

## What Changed

- **[`src/lib/supabase.ts`](file:///d:/devtrack/src/lib/supabase.ts)**: Defined and exported `isSupabaseAdminAvailable` helper to check if credentials are set.
- **[`src/app/api/wakatime/route.ts`](file:///d:/devtrack/src/app/api/wakatime/route.ts)**: Imported `isSupabaseAdminAvailable` and added a defensive guard at the start of the `GET` handler to return a clean fallback `{ hasData: false, not_configured: true }` when credentials are absent.
- **[`test/wakatime-api.test.ts`](file:///d:/devtrack/test/wakatime-api.test.ts)**: Created a new unit test suite checking authenticated, unauthenticated, and unconfigured Supabase paths.

---

## How to Test

1. Ensure Supabase credentials (`NEXT_PUBLIC_SUPABASE_URL`, `SUPABASE_SERVICE_ROLE_KEY`) are removed or set to placeholder values in your local `.env`.
2. Make a `GET` request to `/api/wakatime` (while authenticated).
3. Verify it returns `{ "hasData": false, "not_configured": true }` with a `200 OK` status rather than throwing a 500 error.
4. Run the unit tests to confirm they pass:
   ```bash
   npx vitest run test/wakatime-api.test.ts

Expected result:
The endpoint successfully falls back to a 200 response indicating Supabase is not configured instead of throwing a database connection crash.


Screenshots / Recordings

N/A


Checklist

  • Linked the related issue above
  • Self-reviewed my own diff
  • No unnecessary console.log, debug code, or commented-out blocks
  • npm run lint passes locally
  • No TypeScript errors (npm run type-check)
  • Added or updated tests where applicable
  • Updated documentation / comments if behavior changed

Accessibility (UI changes only)

Skip section (no UI impact).


Additional Context

None.

@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

@shauryavardhan1307 is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:testing GSSoC type bonus: tests (+10 pts) type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts) and removed gssoc26 GSSoC 2026 contribution labels Jun 10, 2026
@github-actions

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Priyanshu-byte-coder — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

@shauryavardhan1307 shauryavardhan1307 force-pushed the fix/wakatime-supabase-absence branch from a12dba1 to ea032c0 Compare June 10, 2026 07:12
@github-actions github-actions Bot added the gssoc26 GSSoC 2026 contribution label Jun 10, 2026
@shauryavardhan1307

Copy link
Copy Markdown
Contributor Author

⚠️ Note on E2E / Visual Regression CI Failures

The failing E2E and Visual Regression checks are pre-existing issues on upstream/main and are completely unrelated to the changes in this PR:

  1. [Dashboard E2E] no uncaught console errors on dashboard load:

    • Root Cause: React throws a duplicate key console warning in src/components/ContributionHeatmap.tsx. Around line 454, the legend elements are mapped using key={count}:
      [
        0,
        Math.ceil(maxCommits * 0.25),
        Math.ceil(maxCommits * 0.5),
        Math.ceil(maxCommits * 0.75),
        maxCommits,
      ].map((count) => ... key={count})
      When maxCommits is small (e.g., 1), the array evaluates to [0, 1, 1, 1, 1], which produces duplicate React keys (key={1}) and triggers a console warning that fails the console-error assertion.
    • Relation: Unrelated to our PR (this PR only modifies /api/wakatime and src/lib/supabase.ts).
  2. settings page saves and reflects changes:

    • Root Cause: Playwright times out trying to toggle and assert the state of the sr-only checkbox (locator.check: Clicking the checkbox did not change its state). This is an interaction flakiness with hidden input overlays in the E2E spec.
    • Relation: Unrelated to our PR.
  3. [Streak E2E] streak widget shows the mocked longest streak value:

    • Root Cause: The locator in e2e/streak.spec.ts fails to find the mocked streak value 21 due to recent upstream markup/layout refactorings.
    • Relation: Unrelated to our PR.

@Priyanshu-byte-coder

Copy link
Copy Markdown
Owner

The isSupabaseAdminAvailable guard already exists in this route. The only production code change is adding an explicit { status: 200 } which is already the default for NextResponse.json(). Please verify the fix addresses an actual issue not already handled.

@shauryavardhan1307

Copy link
Copy Markdown
Contributor Author

My apologies! I opened the issue and branch before PR #1982 was merged into upstream/main. Since the isSupabaseAdminAvailable guard has already been added upstream and handles the fallback cleanly, this PR is indeed redundant.

I will close this PR and the associated issue now. Thank you for pointing that out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts) type:testing GSSoC type bonus: tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants