Host name error on NextJS api route

I am trying to deploy a NextJS app using the next-on-netlify plugin. I am using Auth0 for authentication and when my app goes to the api route to login (/api/login) I get an error that says The "host" request header is not available.

I am guessing it’s because the API is redirecting to Auth0 to show their Login page. Do I need some custom headers config? Anyone else seen this and resolved it?

Thanks

Hard to say exactly what is happening since that is not a Netlify error message (must be either in your code or from the remote service). Could you describe the path your request takes in higher detail? I’m looking for something like this:

  1. request comes in from browser, POST to /api/login
  2. that is proxy’d to a netlify function at path /.netlify/functions/auth0
  3. that function contacts auth0, and that error message comes from their service

Once we know that, we’ll be able to hopefully give some better advice :slight_smile:

Thanks for the help. I found that the place where my function is getting the error. See below

Looks like my API route is trying to create a cookie before it redirects to Auth0. For some reason though req.headers.host does not have a value when it’s being processed in the Netlify function.

I am using the Next-on-Netlify lib for this.

Thanks

Gus

Hi @gushiguera,

I’m not familiar with your code but the only time I can think of where a request won’t have a host header from your browser would be if it was an OPTION request (where it’s not a GET or a POST). If a request is initiated by a website, the browser will first send an OPTION request before the ‘real’ request. Perhaps you’ll need to make sure you handle OPTION requests explicitly. Hope that helps.