amrnn90 / breeze-nuxt

An application / authentication starter kit frontend in Nuxt3 for Laravel Breeze.
MIT License
198 stars 33 forks source link

useEvent is not defined #23

Closed carlosvaldesweb closed 11 months ago

carlosvaldesweb commented 12 months ago

Hello, when i make npm run build to test app like to deploy, and node .output/server/index.mjs i'm getting 500 useEvent is not defined, from $larafetch.

Captura de pantalla 2023-12-02 a la(s) 6 09 20 p m

I'm looking that in nuxt.config.ts we have

export default defineNuxtConfig({
  modules: ["@nuxtjs/tailwindcss"],
  runtimeConfig: {
    public: {
      backendUrl: "http://localhost:8000",
      frontendUrl: "http://localhost:3000",
    },
  },
  imports: {
    dirs: ["./utils"],
  },
  experimental: {
    asyncContext: true,
  }
});

And in the useEvent nitro docs says that we need nitro key in nuxt.config.ts, but it doesn't work yet:

export default defineNuxtConfig({
  nitro: {
    experimental: {
      asyncContext: true
    }
  }
})

If i remove all 'event' references from $larafetch it works correctly.

let token = useCookie(CSRF_COOKIE).value;
    // on client initiate a csrf request and get it from the cookie set by laravel
    if (
      process.client &&
      ["post", "delete", "put", "patch"].includes(
        options?.method?.toLowerCase() ?? "",
      )
    ) {
      token = await initCsrf();
    }

    let headers: any = {
      accept: "application/json",
      ...options?.headers,
      ...(token && { [CSRF_HEADER]: token }),
    };

    if (process.server) {
      const cookieString = useRequestHeaders(["cookie"]).cookie;

      headers = {
        ...headers,
        ...(cookieString && { cookie: cookieString }),
        referer: frontendUrl,
      };
    }
amrnn90 commented 11 months ago

hmm, apparently after build process.nitro is true whether you are in SSR or in a server api route, but during dev it differentiates between the two so I thought I could count on it. Not sure how to check if in a context of server api routes now.