Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuxt 3: [GET] "/api/auth/session": 500 in production #956

Closed
Lippi99 opened this issue Dec 11, 2024 · 1 comment
Closed

Nuxt 3: [GET] "/api/auth/session": 500 in production #956

Lippi99 opened this issue Dec 11, 2024 · 1 comment
Labels
bug A bug that needs to be resolved pending An issue waiting for triage

Comments

@Lippi99
Copy link

Lippi99 commented Dec 11, 2024

Environment

I'm struggling with an issue with Nuxt 3 and auth.sidebase.io

Everything works by far in development. However, in production, I have this error when the build finishes. I've checked the docs to set up the library and yet didn't work. I'm using Cloudflare Pages and I've configured the .env

Here's the issue in production:
image

Here's my nuxt.config.ts:

export default defineNuxtConfig({
  devtools: {
    enabled: true,
  },
  runtimeConfig: {
    public: {
      authBaseURL: process.env.AUTH_ORIGIN,
    },
    authSecret: process.env.NUXT_AUTH_SECRET
  },
  nitro: {
    preset: "cloudflare-pages"
  },
  plugins: [
    {
      src: "~/plugins/confetti.client",
    },
  ],
  auth: {
    provider: {
      type: "authjs"
    },
    isEnabled: true,
    baseURL: `${process.env.AUTH_ORIGIN}/api/auth`,
    sessionRefresh: {
      enablePeriodically: true,
      enableOnWindowFocus: true,
    }
  },
  modules: [
    "@sidebase/nuxt-auth",
    "@nuxt/ui",
    "@nuxt/image",
    "@pinia/nuxt",
    "@unlok-co/nuxt-stripe",
    "@nuxt/scripts",
    "@nuxtjs/i18n",
  ],
  i18n: {
    vueI18n: "./i18n.config.ts",
    locales: ["en", "pt"],
    defaultLocale: "pt",
  },
  stripe: {
    server: {
      key: process.env.STRIPE_SERVER_SECRET_KEY,
    },
    client: {
      key: process.env.NUXT_STRIPE_PUBLIC_KEY,
    },
  },

  postcss: {
    plugins: {
      tailwindcss: {},
      autoprefixer: {},
    },
  },

  colorMode: {
    preference: "dark",
  },

  css: ["~/public/css/tailwind.css"],
  compatibilityDate: "2024-11-19",
});

and here's my ~server/api/auth/[...].ts:

import GoogleProvider from "next-auth/providers/google";
import { NuxtAuthHandler } from "#auth";

export default NuxtAuthHandler({
  secret: useRuntimeConfig().authSecret,
  providers: [
    // @ts-expect-error Use .default here for it to work during SSR.
    GoogleProvider.default({
      clientId: process.env.NUXT_GOOGLE_CLIENT_ID,
      clientSecret: process.env.NUXT_GOOGLE_SECRET,
    }),
  ],
  callbacks: {},
});

adittional information:
I thought it was a server problem, however, I created a ping route to check if the server is running and it returns 200. The problem is this endpoint specifically "/api/auth/session": 500

Package version:
"@sidebase/nuxt-auth": "^0.9.4"

Reproduction

no reproduction available.

Describe the bug

[GET] "/api/auth/session": 500 in production

Additional context

It only works in development. Production fails

Logs

Uncaught (in promise) FetchError: [GET] "/api/auth/session": 500
             
GET https://mywebsite.dev/api/auth/session 500 (Internal Server Error)
@Lippi99 Lippi99 added bug A bug that needs to be resolved pending An issue waiting for triage labels Dec 11, 2024
@zoey-kaiser
Copy link
Member

Hi @Lippi99 👋

Sadly NuxtAuth with the authjs does not run on cloudflare page as it depends on the Nuxt server. As we are still using NextAuth under the hood, this restriction cannot be resolved.

I recommend that you use one of the following packages that do support cloudflare pages:

@zoey-kaiser zoey-kaiser closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug that needs to be resolved pending An issue waiting for triage
Projects
None yet
Development

No branches or pull requests

2 participants