Skip to content

fix: resolve Gemini API authentication and quiz generation - #38

Merged
nasseralkawari merged 1 commit into
mainfrom
fix/gemini-api
Apr 11, 2026
Merged

nasseralkawari merged 1 commit into
mainfrom
fix/gemini-api

Conversation

@nasseralkawari

Copy link
Copy Markdown
Collaborator

This PR resolves the issue where quiz generation was failing due to invalid or missing Gemini API credentials.

Problem

  • Quiz generation endpoint (/api/quiz/generate) was returning:

    • 401 Unauthorized
    • GEMINI_API_KEY environment variable is not set
  • Backend was unable to authenticate with the Gemini API

  • Result: frontend showed "Failed to generate quiz"

Root Cause

  • .env file was missing or incorrectly placed
  • Invalid or unsupported API key was used
  • Gemini API key was not properly loaded via environment variables

Fix Implemented

  • Added proper .env configuration support using dotenv

  • Ensured backend loads environment variables correctly:

    require('dotenv').config({ path: require('path').resolve(__dirname, '../.env') });
  • Replaced invalid API key with a valid Gemini API key from Google AI Studio

  • Restarted backend to apply environment changes

Additional Improvements

  • Verified backend health endpoint (/api/quiz/health)
  • Confirmed successful API response (200) from /generate
  • Ensured frontend properly connects to backend (port 5000)

Testing

  • Successfully generated quizzes from frontend

  • Verified API response includes:

    • quizId
    • questions
  • Confirmed no more authentication errors

Notes

  • .env file is excluded from version control for security
  • API keys must be configured locally for each developer

Impact

  • Restores full quiz generation functionality
  • Enables end-to-end flow (Generate → Quiz → Feedback → Dashboard)

@nasseralkawari
nasseralkawari merged commit b92f095 into main Apr 11, 2026
1 check 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