Skip to content

fix: add authentication to video script endpoint#274

Merged
knoxiboy merged 2 commits into
knoxiboy:mainfrom
KaparthyReddy:fix/add-auth-to-video-endpoints
May 25, 2026
Merged

fix: add authentication to video script endpoint#274
knoxiboy merged 2 commits into
knoxiboy:mainfrom
KaparthyReddy:fix/add-auth-to-video-endpoints

Conversation

@KaparthyReddy
Copy link
Copy Markdown
Contributor

Description

POST /api/video/script had no authentication check, allowing unauthenticated users to freely consume Groq AI credits without a valid Clerk session. This PR adds currentUser() from Clerk at the top of the handler, returning 401 Unauthorized for unauthenticated requests — consistent with /api/video/generate and all other protected routes in the project.

Also moved the Groq client instantiation inside the handler to prevent a module-level crash when GROQ_API_KEY is not set in the environment.

Note: The issue originally identified both /api/video/generate and /api/video/script as unprotected. After pulling the latest main, /api/video/generate/route.ts already had auth added. This PR addresses the remaining unprotected endpoint.

Related Issue

Closes #240

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update (README, guides, comments)
  • Style / UI change (no logic change)
  • Code refactor (no behavior change)
  • Test addition or update
  • Breaking change (fix or feature that would cause existing functionality to change)

Screenshots (if UI change)

N/A — API-level fix, no UI changes.

How Has This Been Tested?

  • Tested locally with npm run dev
  • Verified on mobile viewport (375px)
  • Verified on desktop viewport (1440px)

Sent a POST request to /api/video/script without a Clerk session — endpoint returns {"error":"Unauthorized"} with status 401 as expected.

Checklist

  • I have tested my changes locally (npm run dev)
  • My code follows the existing code style (TypeScript, Tailwind, no any types)
  • I have not introduced unrelated changes (each PR should address one issue)
  • I have added comments where necessary
  • My branch is up to date with main
  • I have linked the related issue above
  • Screenshots are included (if this is a UI change)

POST /api/video/script had no auth check, allowing unauthenticated
users to freely consume Groq AI credits. Added currentUser() from
Clerk to return 401 Unauthorized for requests without a valid session,
consistent with /api/video/generate and other protected routes.

Closes knoxiboy#240
POST /api/video/script had no auth check, allowing unauthenticated
users to freely consume Groq AI credits. Added currentUser() from
Clerk to return 401 Unauthorized for requests without a valid session,
consistent with /api/video/generate and other protected routes.

Also moved Groq client instantiation inside the handler to prevent
module-level crash when GROQ_API_KEY is not set.

Closes knoxiboy#240
@vercel
Copy link
Copy Markdown

vercel Bot commented May 24, 2026

@KaparthyReddy is attempting to deploy a commit to the Karan Mani Tripathi 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added size/size/xs gssoc'26 GSSoC program issue type:bug Bug fix labels May 24, 2026
@github-actions github-actions Bot requested a review from knoxiboy May 24, 2026 12:39
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello there! 🎉 Thank you so much for your first pull request to DoubtDesk!

We really appreciate your contribution. A maintainer will review your code soon. If you are participating in GSSoC, ensure your PR is linked to an open issue. Please make sure you have followed all rules in our Contributing Guidelines. Happy coding!

@knoxiboy knoxiboy added level:advanced Advanced level task and removed gssoc labels May 24, 2026
Copy link
Copy Markdown
Owner

@knoxiboy knoxiboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: Thank you for starring the repository! The PR is approved.

@knoxiboy knoxiboy merged commit e13f5e0 into knoxiboy:main May 25, 2026
5 of 6 checks passed
@knoxiboy knoxiboy added gssoc:approved Approved for GSSoC mentor:knoxiboy Reviewed by mentor knoxiboy quality:clean Clean code quality labels May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved for GSSoC gssoc'26 GSSoC program issue level:advanced Advanced level task mentor:knoxiboy Reviewed by mentor knoxiboy quality:clean Clean code quality type:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Video generation and script endpoints have no authentication — unauthenticated users can freely consume Groq AI credits and server resources

2 participants