NextJS Middleware localhost

I deployed a NextJS app on Render. I’m using a middleware to redirect logged out users to my login page (based on Supabase Auth with Next.js | Supabase Docs). However, when I’m deployed on Render, the host URL and port seem incorrect:

Mar 17 10:20:23 AM    req: {
Mar 17 10:20:23 AM    cookies: RequestCookies {},
Mar 17 10:20:23 AM    geo: {},
Mar 17 10:20:23 AM    ip: undefined,
Mar 17 10:20:23 AM    nextUrl: {
Mar 17 10:20:23 AM    href: 'http://localhost:10000/',
Mar 17 10:20:23 AM    origin: 'http://localhost:10000',
Mar 17 10:20:23 AM    protocol: 'http:',
Mar 17 10:20:23 AM    username: '',
Mar 17 10:20:23 AM    password: '',
Mar 17 10:20:23 AM    host: 'localhost:10000',
Mar 17 10:20:23 AM    hostname: 'localhost',
Mar 17 10:20:23 AM    port: '10000',
Mar 17 10:20:23 AM    pathname: '/',
Mar 17 10:20:23 AM    search: '',
Mar 17 10:20:23 AM    searchParams: URLSearchParams {  },
Mar 17 10:20:23 AM    hash: ''
Mar 17 10:20:23 AM  },

Based on the discussion in Hostname of request object in middleware is always 'localhost' · Issue #37536 · vercel/next.js · GitHub, it seems like I can rewrite the host (and the port) – is this the recommended way of dealing with this? I didn’t have the problem on Vercel and am wondering how to handle this more gracefully.

Seems like you need to tell the middleware the URL of your site so it directs to that instead of localhost - does https://supabase.com/docs/guides/auth/auth-helpers/nextjs#set-up-environment-variables help in anyway?

Regards,

John B

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.