nuxt-nhost icon indicating copy to clipboard operation
nuxt-nhost copied to clipboard

Cannot access datas in production

Open Corentin7301 opened this issue 2 years ago • 8 comments

Cannot access Nhost datas in production on Netlify

Error messages :

In production, in the browser console, have :

  • 404 POST error : https://PRODUCTION_URL/api/_nhost/session

Tests carried out

  • With Nuxt 2 and Nhost JS SDK is working
  • With Nuxt 3 and Nhost JS SDK is working

Solution ?

I think the problem comes from that we recover the URL of the site (front-end) and not from the API. Maybe expecting : POST https://API_URL/api/_nhost/session ?

Is working with local build but no longer works in production.

Technos / versions / config : 
- Nuxt 3 : 3.0.0-rc.8
    - ssr : false
- nuxt-nhost : ^1.1.0

Corentin7301 avatar Sep 07 '22 11:09 Corentin7301

Could it be related to ssr: false? If you generate a static build, /api/_nhost/session won't be included. This route is part of the SSR build and persists the auth session, so you can reload the page without losing it (in the SSR context).

pk992 avatar Sep 07 '22 11:09 pk992

Mmh okay... I'm not yet completely comfortable with the SSR... What would be the solution? To pass SSR in True? What will it change?

Corentin7301 avatar Sep 07 '22 12:09 Corentin7301

I've test with SRR : true but I've the same error...

Corentin7301 avatar Sep 07 '22 12:09 Corentin7301

Are you using the netlify-edge or netlify nitro preset? I think you need the edge one for SSR. If you remove the nitro preset from the config and simply run yarn build and yarn preview, does it work?

For me, it currently works fine in dev and the NodeJS & Cloudflare Worker prod build.

I will try my build on Netlify this week to find the problem.

pk992 avatar Sep 07 '22 22:09 pk992

Mmh... I don't no if I used netlify-edge or nitro but I don't have change Netlify base configuration (except build & domain)

Thanks for your test build!

Corentin7301 avatar Sep 09 '22 09:09 Corentin7301

I will try my build on Netlify this week to find the problem.

Hi! Were you able to test to find the problem ?

Corentin7301 avatar Sep 12 '22 15:09 Corentin7301

I have a solution! I've update Nuxt to 3.0.0-rc.9 (but I don't no if is that) I've build my app in CSR (and not static like before)

Now is working BUT the session is broken when I refresh the page... Have you a solution?

Corentin7301 avatar Sep 12 '22 15:09 Corentin7301

Have you had a look at #2? This should be the solution, at least for now.

pk992 avatar Sep 29 '22 12:09 pk992