Cookies not working in next js middleware

Hi guys, why cookies value is being return null in next js middleware but the value exists in the browser's cookies

import { NextRequest, NextResponse } from 'next/server';
import { getSessionCookie } from 'better-auth';

export async function middleware(request: NextRequest) {
  const cookies = getSessionCookie(request);
  console.log({ cookies });
  if (!cookies) {
    return NextResponse.redirect(new URL('/', request.url));
  }
  return NextResponse.next();
}

export const config = {
  matcher: ['/dashboard'],
};
Was this page helpful?