Menu

Better Auth on Next.js 16: the three setup gotchas that bite
📰

Better Auth on Next.js 16: the three setup gotchas that bite

DEV Community: nextjs·Shipwright·about 10 hours ago
#6EZVJkLv
#devtonextjs#devto#dev#auth#better
Reading 0:00
15s threshold

Better Auth is genuinely quick to stand up — an instance, a Drizzle adapter, email and password, done. The friction is not the setup; it is three things specific to Next.js 16 that do not announce themselves, and each one fails in a way that looks like something else. Here they are, from the kit's actual auth wiring.

The proxy can only do an optimistic check

Next.js 16 renamed middleware to the "proxy," and it forbids slow work there — no database-backed session validation. So the proxy does the one cheap thing it is allowed to: look for the session cookie and bounce anyone without it to sign-in. It does not, and cannot, verify that the cookie is valid.

export function proxy ( request : NextRequest ) { const sessionCookie = getSessionCookie ( request ) ; if ( ! sessionCookie ) { const signIn = new URL ( "/sign-in" , request . url ) ; signIn . searchParams . set ( "redirect" , request . nextUrl . pathname ) ; return NextResponse . redirect ( signIn ) ; } return NextResponse .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.