Skip to content

Fix Unkey API Key Verification and Improve Diagnostic Logs - #100

Merged
Simonc44 merged 9 commits into
mainfrom
fix-unkey-api-verification-11353562886668436631
Jul 12, 2026
Merged

Fix Unkey API Key Verification and Improve Diagnostic Logs#100
Simonc44 merged 9 commits into
mainfrom
fix-unkey-api-verification-11353562886668436631

Conversation

@Simonc44

Copy link
Copy Markdown
Owner

This PR resolves the 401 Unauthorized error reported by the user when calling the api with their key. It makes the key verification robust and highly diagnostic:

  1. Enhanced Debug Logging: It adds a clear environment status check in Vercel logs (UNKEY_API_ID present/missing) on every API request. This will immediately show the user if their newly added Vercel environment variables are actually loaded in the current deployment (as Vercel requires a re-deploy for new env vars to take effect).
  2. Robust Verification with Local Fallback: When Unkey is configured, it verifies keys against Unkey. If Unkey is unreachable or has an error, it returns a 503 Service Unavailable with the error details. If Unkey doesn't recognize the key, it falls back to local verification (for MANDAT_API_KEYS or mk_test_ keys).
  3. Strict Production Security: To prevent any security bypasses, automatic local verification of mk_test_ keys is strictly disabled in production (process.env.NODE_ENV !== "production"). It remains enabled in development and test environments to make unit tests and local runs work flawlessly.
  4. All Tests Pass: Ran npm test and all 46 tests pass successfully.

PR created automatically by Jules for task 11353562886668436631 started by @Simonc44

- Prioritize Unkey validation when configured, and gracefully fallback to local validation if the key is valid locally (e.g., test or fallback keys).
- Secure local key bypass: disable automatic `mk_test_` bypass in production to prevent authentication bypass vulnerabilities.
- Add detailed diagnostic logging in `apiGuard` to log the presence of UNKEY_API_ID and other variables to help users debug Vercel environment loading.
- Return explicit 503 error responses if Unkey verification fails with technical/network errors instead of a misleading 401.

Co-authored-by: Simonc44 <216070312+Simonc44@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel

vercel Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
mandat Ready Ready Preview, Comment Jul 12, 2026 10:58pm

…x build imports

- Prioritize Unkey validation when configured, and gracefully fallback to local validation if the key is valid locally (e.g., test or fallback keys).
- Secure local key bypass: disable automatic `mk_test_` bypass in production to prevent authentication bypass vulnerabilities.
- Add detailed diagnostic logging in `apiGuard` to log the presence of UNKEY_API_ID and other variables to help users debug Vercel environment loading.
- Return explicit 503 error responses if Unkey verification fails with technical/network errors instead of a misleading 401.
- Install missing build dependencies for @shadergradient/react (three, @react-three/fiber, @react-three/drei) to fix the Rolldown resolution build error.

Co-authored-by: Simonc44 <216070312+Simonc44@users.noreply.github.com>
…x shadergradient canvas R3F hooks

- Prioritize Unkey validation when configured, and gracefully fallback to local validation if the key is valid locally (e.g., test or fallback keys).
- Secure local key bypass: disable automatic `mk_test_` bypass in production to prevent authentication bypass vulnerabilities.
- Add detailed diagnostic logging in `apiGuard` to log the presence of UNKEY_API_ID and other variables to help users debug Vercel environment loading.
- Return explicit 503 error responses if Unkey verification fails with technical/network errors instead of a misleading 401.
- Install missing build dependencies for @shadergradient/react (three, @react-three/fiber, @react-three/drei).
- Fix "R3F: Hooks can only be used within the Canvas component" error by dynamically importing and wrapping `ShaderGradient` inside `ShaderGradientCanvas`.

Co-authored-by: Simonc44 <216070312+Simonc44@users.noreply.github.com>
…e visual effects

- Implemented detailed logging and service fallback logic in `src/lib/api-auth.server.ts` to debug and secure Unkey key verification.
- Locked local bypass for `mk_test_` keys strictly to non-production environments to prevent security vulnerabilities.
- Set dynamic shader gradient background to fixed position to maintain visual continuity when scrolling.
- Created `DispersingTitle` in `src/routes/index.tsx` with smooth CSS-based 3D air dispersion hover animation.
- Rendered description text, Turso, and GitHub trust logos/texts in full white for contrast, leaving search and daily update texts as requested.
- Installed `@shadergradient/react` and `@react-three/fiber` peer dependencies and wrapped with canvas to fix dynamic import errors.

Co-authored-by: Simonc44 <216070312+Simonc44@users.noreply.github.com>
… shader gradient background

- Removed the title air dispersion hover effect entirely as requested.
- Enhanced the "votre député a voté." title line with a highly visible, bright neon `.text-gradient-bright` gradient.
- Adjusted hero styles so the dynamic shader gradient background remains fully visible as a continuous background when scrolling down instead of shifting into a flat gray background.

Co-authored-by: Simonc44 <216070312+Simonc44@users.noreply.github.com>
- Adds the UNKEY_ROOT_KEY in the Authorization header for Unkey keys.verifyKey requests.
- Checks both UNKEY_ROOT_KEY and UNKEY_API_ID to trigger Unkey verification.
- Updates diagnostic logs to print the status of UNKEY_ROOT_KEY, UNKEY_API_ID, and MANDAT_API_KEYS.
- Updates unit tests to verify authorization header handling during Unkey check.

Co-authored-by: Simonc44 <216070312+Simonc44@users.noreply.github.com>
@Simonc44
Simonc44 merged commit 64b63b8 into main Jul 12, 2026
6 of 8 checks passed
@Simonc44
Simonc44 deleted the fix-unkey-api-verification-11353562886668436631 branch July 12, 2026 22:59
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