Skip to main content

Nextjs App Router

Nextjs 13 app router best practices.

Static paid content

// middleware.ts
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { decrypt } from './your-auth-system';

export function middleware(req: NextRequest) {
// E.g store the payment status directly in the session token
// Or call an API like Stripe
const sessionToken = req.cookies().get('session')?.value;
const session = decrypt(session);
if (!session?.isPaid) {
return NextResponse.redirect('/subscribe', new URL(req.url));
}
return NextResponse.next();
}

export const config = {
matcher: '/(.*)',
};

Caching

Work in progress to nail down the caching strategy.

tRPC

Simple Typesafe APIs

Source code

Props

Passing promises as props.