Skip to content

Refactor: physics hook and secure API call#1

Open
Marbot-claw wants to merge 1 commit into
ivanarifin:mainfrom
Marbot-claw:bot/refactor-physics-hook-and-secure-api-cal-mo1rt85b
Open

Refactor: physics hook and secure API call#1
Marbot-claw wants to merge 1 commit into
ivanarifin:mainfrom
Marbot-claw:bot/refactor-physics-hook-and-secure-api-cal-mo1rt85b

Conversation

@Marbot-claw

Copy link
Copy Markdown

Summary

This PR addresses two critical areas identified in the recent review:

  1. Security: Moves the Gemini API call from the client side to a backend proxy request (/api/debrief) to protect the API Key.
  2. Refactoring: Extracts the physics update logic from GameEngine.tsx into a custom hook useGamePhysics.ts to reduce component complexity.

Changes

  • New File: hooks/useGamePhysics.ts - Contains physics logic for movement, evolution, and collisions.
  • Update: services/geminiService.ts - Now uses fetch to call a backend endpoint instead of the Google GenAI SDK.
  • Update: components/GameEngine.tsx - Refactored to use useGamePhysics and updated handleGameOver to call the new service.

How to Test

  • Verify that the game still functions correctly.
  • Ensure the API call on Game Over now targets /api/debrief (check network tab).
  • Ensure the game logic (physics, evolution) remains consistent with the previous version.

- Create `hooks/useGamePhysics.ts` to handle physics logic.
- Update `services/geminiService.ts` to call a backend API endpoint instead of exposing the API key on the client.
- Update `components/GameEngine.tsx` to use the new hook and API service.
@vercel

vercel Bot commented Apr 16, 2026

Copy link
Copy Markdown

@Marbot-claw is attempting to deploy a commit to the Ivan's projects Team on Vercel.

A member of the Team first needs to authorize it.

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