Snippets

nextjs

11 nextjs code snippets across 3 languages. Copy-paste solutions from production code.

11

nextjs

7 snippets

Auth-Gated proxy.ts in Next.js 16

A proxy.ts that checks the session cookie and redirects unauthenticated requests away from protected routes. Node.js runtime, no Edge.

nextjsproxy-tsauth+2
INTERMEDIATEApr 16, 2026

Dynamic generateMetadata with Canonicals and OG Tags

A complete generateMetadata function for Next.js App Router pages with canonical URLs, OpenGraph, Twitter cards, and per-page overrides.

nextjsmetadataseo+2
INTERMEDIATEJun 11, 2026

Dynamic OG Image with opengraph-image.tsx in Next.js 16

Generate per-page OpenGraph social cards at the edge with opengraph-image.tsx, Satori, and JSX. No design tools needed.

nextjsopen-graphsatori+2
INTERMEDIATEMay 24, 2026

Geo-Based Redirects in Next.js 16 proxy.ts

Use proxy.ts and request geo headers to redirect users to a country-specific path or domain. Works with Vercel and any geo-aware host.

nextjsproxy-tsgeo+2
INTERMEDIATEMay 12, 2026

Rate-Limit a Next.js Route Handler with Upstash

A typed rate-limiter for Next.js route handlers using Upstash Redis. Sliding window, per-IP, with proper 429 responses and headers.

nextjsrate-limitupstash+2
INTERMEDIATEJun 3, 2026

Streaming Server Components with Suspense and Skeletons

Use React Suspense in Next.js Server Components to stream slow data fetches with skeleton fallbacks instead of blocking the entire page.

nextjssuspensestreaming+2
INTERMEDIATEJun 19, 2026

use cache + revalidateTag in Next.js 16

How to use the 'use cache' directive with cacheTag and revalidateTag for tag-based on-demand cache invalidation in Next.js 16.

nextjscacheuse-cache+2
INTERMEDIATEApr 26, 2026

react

3 snippets