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

nuxt auth does not work with cloudflare pages (an by extension NuxtHub)

Open devinschumacher opened this issue 9 months ago • 7 comments

Environment


  • Operating System: Darwin
  • Node Version: v23.2.0
  • Nuxt Version: 3.15.4
  • CLI Version: 3.23.1
  • Nitro Version: 2.11.6
  • Package Manager: [email protected]
  • Builder: -
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

cant deploy through nuxthub/cf pages with auth

Describe the bug

the n.default throws an error that breaks it:

{ "wallTime": 4, "cpuTime": 3, "truncated": false, "executionModel": "stateless", "outcome": "ok", "scriptVersion": { "id": "5e4c3d51-c954-487c-a0bb-ed7c21c28fca" }, "scriptName": "pages-worker--5512482-preview", "diagnosticsChannelEvents": [], "exceptions": [], "logs": [ { "message": [ "[nuxt] [request error] [unhandled] [500]", "n.default is not a function\n" ], "level": "error", "timestamp": 1742471759976 } ], "eventTimestamp": 1742471759976, "event": { "request": { "url": "https://622be7a9.serp-wiki.pages.dev/api/auth/session", "method": "GET", "headers": { "accept": "/", "accept-encoding": "gzip, br", "accept-language": "en-US,en;q=0.9", "cf-connecting-ip": "2400:2410:3f64:7a00:14a8:5c43:e972:dd61", "cf-ipcountry": "JP", "cf-ray": "92350613debbfd43", "cf-visitor": "{"scheme":"https"}", "connection": "Keep-Alive", "host": "622be7a9.serp-wiki.pages.dev", "priority": "u=1, i", "sec-ch-ua": ""Not(A:Brand";v="99", "Google Chrome";v="133", "Chromium";v="133"", "sec-ch-ua-mobile": "?0", "sec-ch-ua-platform": ""macOS"", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-origin", "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36", "x-forwarded-proto": "https", "x-real-ip": "2400:2410:3f64:7a00:14a8:5c43:e972:dd61" }, "cf": { "requestHeaderNames": {}, "httpProtocol": "HTTP/3", "tlsCipher": "AEAD-AES128-GCM-SHA256", "continent": "AS", "asn": 17676, "clientAcceptEncoding": "gzip, deflate, br, zstd", "tlsClientExtensionsSha1": "NThlM28bxCJZ638P2eppWTILjCQ=", "verifiedBotCategory": "", "country": "JP", "tlsClientAuth": { "certIssuerDNLegacy": "", "certIssuerSKI": "", "certSubjectDNRFC2253": "", "certSubjectDNLegacy": "", "certFingerprintSHA256": "", "certNotBefore": "", "certSKI": "", "certSerial": "", "certIssuerDN": "", "certVerified": "NONE", "certNotAfter": "", "certSubjectDN": "", "certPresented": "0", "certRevoked": "0", "certIssuerSerial": "", "certIssuerDNRFC2253": "", "certFingerprintSHA1": "" }, "requestPriority": "", "tlsVersion": "TLSv1.3", "colo": "NRT", "timezone": "Asia/Tokyo", "region": "Tokyo", "longitude": "139.68990", "edgeRequestKeepAliveStatus": 1, "tlsClientRandom": "EdAXJEuaxw2c287q0kJjGWFblbB+ppWxcs3otDQPmes=", "latitude": "35.68930", "regionCode": "13", "asOrganization": "SoftBank Corp.", "tlsClientHelloLength": "1529", "pagesHostName": "622be7a9.serp-wiki.pages.dev", "botManagement": { "corporateProxy": false, "verifiedBot": false, "jsDetection": { "passed": false }, "staticResource": false, "detectionIds": {}, "score": 99 } } }, "response": { "status": 500 } }, "id": 2 }

Additional context

No response

Logs


devinschumacher avatar Mar 20 '25 11:03 devinschumacher

Hello 👋

Please provide a reproduction for this issue 🙏

How can I create a reproduction?

Please use one of the following links to reproduce your issue.

  • https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz
  • https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox

Please ensure that the reproduction is as minimal as possible. This will allow us to isolate the issue as best as possible.

Here are some more amazing posts about the importance of reproductions:

github-actions[bot] avatar Apr 03 '25 07:04 github-actions[bot]

Hi @devinschumacher. I can't unfortunately take a proper look into the issue without getting a bit more specifics. We don't deploy to CF ourselves, so I can suggest you two options:

  1. Conduct your own investigation of what goes wrong and suggest what NuxtAuth needs to do to fix your usecase, either via adding details to this issue or even opening a fix PR.
  2. Contact me privately (via email to [email protected]), so that I can request some details which you might not want to publish.

phoenix-ru avatar Apr 03 '25 07:04 phoenix-ru

I'm running into the same issue.

GitHub Issue: ns.default is not a function error with @sidebase/nuxt-auth in production

Issue Summary

When using @sidebase/nuxt-auth with Google authentication, the application works perfectly in local development but fails in production with the following error:

ERROR [request error] [unhandled] [GET] https://test.example/api/auth/session
{ message: 'ns.default is not a function', statusCode: 500 }

Environment

  • Works in: Local development environment
  • Fails in: Production environment
  • Nuxt version: 3.16.0
  • @sidebase/nuxt-auth version: 0.10.1

Configuration

Using Google OAuth with the following setup:

// server/api/auth/[...].ts
import { NuxtAuthHandler } from '#auth'
import GoogleProvider from 'next-auth/providers/google'

const config = useRuntimeConfig()

export default NuxtAuthHandler({
  debug: true,
  providers: [
    GoogleProvider.default({
      clientId: config.oauth.google.clientId,
      clientSecret: config.oauth.google.clientSecret,
      authorization: {
        params: {
          prompt: 'consent',
          access_type: 'offline',
          response_type: 'code',
        },
      },
    }),
  ],
  pages: {
    signIn: '/login',
  },
})

Reproduction steps

  1. Application runs fine locally with the above configuration
  2. When deployed to production, attempting to access the session causes a 500 error
  3. The error specifically happens when making a GET request to /api/auth/session

Additional context

  • There appears to be a module resolution conflict between next-auth and @auth/core providers
  • TypeScript shows type conflicts between these packages:
    Type 'OAuthConfig<any>' is not assignable to type 'Provider'
    Type 'OIDCConfig<any>' is not assignable to type 'Provider'
    
  • The error in production suggests that the default export from a namespace is not a function, likely related to how module exports are handled differently in production builds

Attempted solutions

  • Added transpilation for auth modules in nuxt.config.ts
  • Tried using both next-auth/providers/google and @auth/core/providers/google
  • Both have type conflicts but the application runs locally

Any help resolving this production-only issue would be greatly appreciated!

zaidmasri avatar Apr 05 '25 08:04 zaidmasri

@zaidmasri You should not be using @auth/core yet as it is incompatible with NuxtAuth yet (see #673 for progress). When you use next-auth, you need to ensure that your version is exactly 4.21.1, otherwise you wouldn't get it to work (they made breaking changes in a minor release, nothing we can do to mitigate this).

phoenix-ru avatar Apr 06 '25 18:04 phoenix-ru

@phoenix-ru & @devinschumacher

I discovered that Cloudflare Workers provide a subset of Node.js's API and not the full thing. It might be just a matter of time until they get around to it or if you find the hack please let me know.

zaidmasri avatar Apr 09 '25 05:04 zaidmasri

@zaidmasri Is there an upstream issue in the Nuxt repo or in the Cloudflare repo? Could you please link to it here?

phoenix-ru avatar Apr 10 '25 08:04 phoenix-ru

@phoenix-ru

I found a closed issue on this repo #378. Particularly, this comment & this comment.

Since nuxt-auth uses next-auth I was looking at their issues and found this.

zaidmasri avatar Apr 10 '25 11:04 zaidmasri