Urgent.News

What's breaking now, across hundreds of outlets.

AI

Secure Next.js Server Actions for Remotion-Based AI Video Generation

Secure Next.js Server Actions for Remotion-Based AI Video Generation The page hits at 3:07 a.m.: the promo renderer has burned the monthly model quota, and the key that belonged on the server is inside a client chunk. I was not on the video-shotcraft team. I was the external architect asked to integrate Vincentwei1021/video-shotcraft into a Next.js 15 app without turning Remotion previews into a…

On March 7th around 3:07 a.m., the promo renderer exceeded the monthly model quota for the AI video generation process. The key that belonged on the server was inadvertently exposed in a client chunk. This incident occurred while working with Vincentwei1021/video-shotcraft within a Next.js 15 application. The external architect's task was to integrate this tool into the app without compromising sensitive credentials.

The Remotion library handled the pixel rendering, but a misplaced 'use client' directive inadvertently included the AI API key in the browser bundle, making it visible during bundle analysis or network monitoring. Moving the fetch operation to the client side to "fix" the leak resulted in a longer request waterfall, negatively impacting Largest Contentful Paint (LCP) performance because the browser couldn't prioritize assets that the server hadn't rendered yet.

The root issue lay in treating the preview as a pure client island rather than a server pipeline. Proper validation, session gating, and model calls should be executed on the server, followed by passing a shot ID to Remotion. The server action ought to handle validation, authentication, and API calls, returning either 'VALIDATION_ERROR', 'AUTH_ERROR', or 'API_ERROR' to allow the UI to respond without exposing internal stack traces or bearer tokens.

The operational boundary required passing a real authentication provider to getServerSession(). Any non-OK response from the relay (such as a bearer token issue) should be considered terminal for that attempt. Retries must be managed in a budgeted queue, not hidden within the user-visible request. After a successful shot ID return, the UI should update an error page. The revalidatePath('/promos') function runs only after a valid shot ID is obtained to invalidate the cache and force a fresh render.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in AI

7 Claude Tricks Every Developer Must Know to Write Better Code

Most developers know that Claude can write code. It can explain Python functions. Debug JavaScript. Generate SQL queries. Review APIs. And help build applications.

  • Create a CLAUDE.md file for reusable project context
  • Use Plan Mode to propose changes without modifying files
  • Give Claude verification tasks, like writing failing tests

More from Friday 27 November →