getSessionCookie is broken in Next.js middleware
I have to manually check my cookies in middleware, which works just fine. But getSessionCookie never returns.
import { type NextRequest, NextResponse } from "next/server"
export async function middleware(request: NextRequest) {
// const sessionCookie = getSessionCookie(request) // Broken
if (!request.cookies.has("better-auth.session_token")) {
const redirectTo = request.nextUrl.pathname + request.nextUrl.search
return NextResponse.redirect(new URL(`/auth/sign-in?redirectTo=${redirectTo}`, request.url))
}
return NextResponse.next()
}
export const config = {
matcher: ["/auth/settings"]
}