Setting a cookie in a middleware and passing to the next middleware in the chain

I have a _middleware.js file with a few middleware functions in it.
One of the functions needs to set (or clear) a specific cookie in a specific use case. Since that’s the only thing it needs to do (and the only thing it knows), I want to call next() to have the next middleware run, as opposed to creating a response object and set the set-cookie header on it and return the response object.

Im using next-intl for internationalization with NextJS 13 App router and Supabase for backend. Next-intl working fine but I wanna add a feature : when a user is connected, rather than using the language of the browser or the Accept-Language header, use the user preferred language which is stored in the supabase database Okay there is my actual middleware.ts :

import { createMiddlewareClient } from '@supabase/auth-helpers-nextjs'
import { NextRequest, NextResponse } from 'next/server'
import createIntlMiddleware from 'next-intl/middleware'
import { User } from './types/type.user';

const locales = ['en', 'fr'];

const intlMiddleware = createIntlMiddleware({
  defaultLocale: 'en',
  localePrefix: 'never',

export async function middleware(req: NextRequest) {
  const res =
  const supabase = createMiddlewareClient({ req, res })
  const { data: { session } } = await supabase.auth.getSession();
  const { data: user } = await supabase.from('user').select('*').eq('id', session? as { data: User }
  if (user) {
        name: 'NEXT_LOCALE',
        value: user.language,
        maxAge: 365 * 24 * 60 * 60,
        path: '/',
        sameSite: 'strict',
        priority: 'medium'
  return intlMiddleware(req);

export const config = {
  matcher: ['/((?!api|_next|_vercel|.*\\..*).*)']

The problem is the cookie is never set if the user exist. Why ? Idk but if I do return (res) against return intlMiddleware(req) is working (but I loose the intlMiddleware so isnt the solution. So how can we set a cookie before calling intMiddelware.