Vercel and Next.js Error - Session Does Not Match Project Host

16 replies
Last updated: May 18, 2021
Hey Sanity family, we are currently in a bit of a weird spot where we are receiving an error on our production server (Vercel) but not locally. I've searched around looking for information on the error message/code and have found nothing. I'm hoping that the Sanity Team can help shed some light on this. Here's the error:
body: {
  errorCode: 'SIO-401-AWH',
  message: 'Session does not match project host',
  statusCode: 401,
  error: 'Unauthorized'
},
This is occurring only when we're using the Preview client. Again, everything works perfectly locally. Screenshots in thread
๐Ÿ‘‰
The web client is running on
Nextjs and we're hosting on Vercel for what it's worth.
May 18, 2021, 5:39 PM
Locally:
May 18, 2021, 5:42 PM
If you open the Functions tab in Vercel then hit this page again, does it offer any insight?
May 18, 2021, 5:47 PM
Yes, do you want me to post the full error?
May 18, 2021, 5:48 PM
Sure.
May 18, 2021, 5:48 PM
user A

b4df-4b68-bb11-5361dcc083f5	ERROR	Error: Failed to load /500
    at loadComponents (/var/task/node_modules/next/dist/next-server/server/load-components.js:1:1554)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Server.findPageComponents (/var/task/node_modules/next/dist/next-server/server/next-server.js:76:257)
    at async Server.renderErrorToHTML (/var/task/node_modules/next/dist/next-server/server/next-server.js:138:198)
    at async Server.renderToHTML (/var/task/node_modules/next/dist/next-server/server/next-server.js:137:1629)
    at async Server.render (/var/task/node_modules/next/dist/next-server/server/next-server.js:74:255)
    at async Object.fn (/var/task/node_modules/next/dist/next-server/server/next-server.js:58:672)
    at async Router.execute (/var/task/node_modules/next/dist/next-server/server/router.js:25:67)
    at async Server.run (/var/task/node_modules/next/dist/next-server/server/next-server.js:68:1042)
    at async Server.handleRequest (/var/task/node_modules/next/dist/next-server/server/next-server.js:32:504)
2021-05-18T17:30:55.793Z	88563306-b4df-4b68-bb11-5361dcc083f5	ERROR	ClientError: Unauthorized - Session does not match project host
    at onResponse (/var/task/node_modules/@sanity/client/lib/http/request.js:27:13)
    at applyMiddleware (/var/task/node_modules/get-it/lib-node/util/middlewareReducer.js:14:23)
    at onResponse (/var/task/node_modules/get-it/lib-node/index.js:81:22)
    at /var/task/node_modules/get-it/lib-node/index.js:48:55
    at callback (/var/task/node_modules/get-it/lib-node/request/node-request.js:57:46)
    at /var/task/node_modules/get-it/lib-node/request/node-request.js:141:14
    at DestroyableTransform.<anonymous> (/var/task/node_modules/simple-concat/index.js:8:13)
    at Object.onceWrapper (events.js:421:28)
    at DestroyableTransform.emit (events.js:327:22)
    at endReadableNT (/var/task/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:1010:12) {
  response: {
    body: {
      errorCode: 'SIO-401-AWH',
      message: 'Session does not match project host',
      statusCode: 401,
      error: 'Unauthorized'
    },
    url: "<https://r3ka18qi.api.sanity.io/v2021-03-25/data/query/production?query=*%5B_type%20%3D%3D%20%22post%22%20%26%26%20slug.current%20%3D%3D%20%24slug%5D%20%7C%20order(_updatedAt%20desc)%20%7B%20%22mapData%22%3A%20%22singlePost%22%2C%20title%2C%20%22slug%22%3A%20%22%2F%22%20%2B%20slug.current%2C%20seo%20%7B%20...%2C%20seoImage%20%7B%20...%2C%20asset-%3E%20%7D%20%7D%2C%20%22defaultSeo%22%20%3A%20%7B%20title%2C%20excerpt%2C%20%22content%22%3A%20select(%20_type%20%3D%3D%20'pageTemplateHome'%20%3D%3E%20heroContent%2C%20content%20)%2C%20components%5B%5D%20%7B%20heading%2C%20content%2C%20%22table%22%20%3A%20rows%5B%5D.cells%5B%5D%20%7D%2C%20%22address%22%20%3A%20address.label%20%7D%20%2C%20'cardMedia'%3A%20''%2C%20%7D&%24slug=%22get-out-side-a-natural-play-phenomenon%22>",
    method: 'GET',
    headers: {
      date: 'Tue, 18 May 2021 17:30:55 GMT',
      'content-type': 'application/json; charset=utf-8',
      'x-ratelimit-limit-second': '500',
      'x-ratelimit-remaining-second': '499',
      'ratelimit-remaining': '499',
      'ratelimit-limit': '500',
      'ratelimit-reset': '1',
      'content-length': '115',
      vary: 'Origin',
      xkey: 'project-r3ka18qi, project-r3ka18qi-production',
      via: '1.1 google',
      'alt-svc': 'clear',
      connection: 'close'
    },
    statusCode: 401,
    statusMessage: 'Unauthorized'
  },
  statusCode: 401,
  responseBody: '{\n' +
    '  "errorCode": "SIO-401-AWH",\n' +
    '  "message": "Session does not match project host",\n' +
    '  "statusCode": 401,\n' +
    '  "error": "Unauthorized"\n' +
    '}'
}
RequestId: 88563306-b4df-4b68-bb11-5361dcc083f5 Error: Runtime exited with error: exit status 1
Runtime.ExitError
May 18, 2021, 5:48 PM
Locally:
May 18, 2021, 5:42 PM
Anything else I can provide?
May 18, 2021, 6:08 PM
Have you tried generating a new token to ensure Vercel has the right one?
May 18, 2021, 6:11 PM
Yes, we did that with no luck.
May 18, 2021, 6:12 PM
Wait. We just did it again and it might have worked...
May 18, 2021, 6:14 PM
Standby...
May 18, 2021, 6:14 PM
It works now ๐Ÿ™ƒ
May 18, 2021, 6:16 PM
I think it was a space at the end of the token.
May 18, 2021, 6:16 PM
Thanks for the help ๐Ÿ™ ๐ŸŽ‰
May 18, 2021, 6:17 PM
Awesome!
May 18, 2021, 6:17 PM
Youโ€™re welcome!
May 18, 2021, 6:17 PM

Sanityโ€“ build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?