Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Issue with Next JS SSG preview mode and `next-i18next` package causing 500 error on Netlify

6 replies
Last updated: Dec 16, 2021
Hi,I’m getting
Not authenticated - preview not available eval @ next-sanity.esm.js?c596:159
when in Preview Mode (Next JS SSG).

But actually, the live preview DOES work (Studio Pane and external window) – but only on localhost. As soon as I try in production I only ever get an Error 500…

Also, when I try to (unsuccessfully) access the Preview in production and the relevant Cookie(s) is/are set, it in turn leads to a 500 that persists, even when NOT in preview mode.
When I delete these Cookies, “Normal Mode” functions perfectly again…

Anyone experienced sth. similar or has any ideas why it would work just fine locally but not in production?

It’s a public dataset, I’ve checked all the relevant CORS settings and the environment variables are the same (if I didn’t miss anything). I tried hosting the frontend on Netlify and on Vercel – makes no difference.
Dec 15, 2021, 7:09 PM
Hi, here’s an overview 🙃

S = Sanity, 
N = NextJS, 
prod. = deployed / hosted on Netlify

S (local) + N (local) = 🟢* 
// works perfectly, but "Not authenticated" from next-sanity.esm.js

S (local) + N (prod.) = 🔴
// 500 Internal Server Error for N

S (prod.) + N (local) = 🟠 
// displays page, but doesn't apply changes live, no error 500, no "Not authenticated" error

S (prod.) + N (prod.) = 🔴
// 500 Internal Server Error for N

Dec 16, 2021, 10:38 AM
Hi, here’s an overview 🙃

S = Sanity, 
N = NextJS, 
prod. = deployed / hosted on Netlify

S (local) + N (local) = 🟢* 
// works perfectly, but "Not authenticated" from next-sanity.esm.js

S (local) + N (prod.) = 🔴
// 500 Internal Server Error for N

S (prod.) + N (local) = 🟠 
// displays page, but doesn't apply changes live, no error 500, no "Not authenticated" error

S (prod.) + N (prod.) = 🔴
// 500 Internal Server Error for N

Dec 16, 2021, 10:38 AM
Thank you for clarifying! I'll spend some time on this one today.
Dec 16, 2021, 5:33 PM
Thanks, but please don’t bother :-) I “fixed” it just now. In the end it came down to the
next-i18next
package causing problems, but only in the specific combination of either SSR or SSG-in-preview-mode on Netlify (Vercel was fine either way). This lead to an error 500 that persisted as long as the cookie was set. I’ve since switched to the
next-translate
package as I just couldn’t get
next-i18next
to work on Netlify.
Dec 16, 2021, 6:02 PM
Thanks, but please don’t bother :-) I “fixed” it just now. In the end it came down to the
next-i18next
causing problems, but only in the specific combination of either SSR or SSG-in-preview-mode on Netlify (Vercel was fine either way). This lead to an error 500 that persisted as long as the cookie was set. I’ve since switched to the
next-translate
package as I just couldn’t get
next-i18next
to work on Netlify.
Dec 16, 2021, 6:02 PM
Glad you got it figured out! Thanks so much for sharing your solution!
Dec 16, 2021, 6:10 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?