Open pragmatic-recursion opened 1 month ago
I encountered this as well. Reverting to
"@auth/core": "^0.35.0",
"@auth/sveltekit": "1.5.3",
works as expected. Maybe this is an issue with the new customFetch
that @balazsorban44 added recently?
Here's the more-useful trace I get running locally with the newer releases:
TypeError: Illegal invocation: function called with incorrect `this` reference. See https://developers.cloudflare.com/workers/observability/errors/#illegal-invocation-errors for details.
at Object.apply
(file:///Users/jakemoves/projects/mixtape-project/mixtape/.wrangler/tmp/bundle-YxKLIk/checked-fetch.js:28:18)
at Object.apply
(file:///Users/jakemoves/projects/mixtape-project/mixtape/.wrangler/tmp/bundle-ul11C8/checked-fetch.js:28:18)
at null.<anonymous>
(file:///Users/jakemoves/projects/mixtape-project/mixtape/node_modules/.pnpm/@auth+core@0.36.0/node_modules/@auth/core/lib/actions/callback/oauth/callback.js:65:52)
at authenticatedRequest
... and the linked docs from Cloudflare at https://developers.cloudflare.com/workers/observability/errors/#illegal-invocation-errors
@jakemoves You're a life saver. I can finally ship. 🥹
Hmm. Unless you override customFetch, (which you really shouldn't in 99+% of the cases) we fall back to the globally available fetch
No clue why this would break Cloudflare yet...
This happened to me too, not using @auth/sveletekit. This is running locally in Miniflare (Cloudflare simulator) using wrangler.
I logged all of the values in the custom fetch function in case something there rings a bell:
provider = {
id: 'github',
name: 'GitHub',
type: 'oauth',
authorization: { url: [URL], request: undefined, conform: undefined },
token: { url: [URL] },
userinfo: {
url: [URL],
request: [AsyncFunction: request],
conform: undefined
},
profile: [Function: profile],
style: { bg: '#24292f', text: '#fff' },
clientId: '...',
clientSecret: '...',
issuer: undefined,
signinUrl: 'http://localhost:8787/auth/signin/github',
callbackUrl: 'http://localhost:8787/auth/callback/github',
redirectProxyUrl: undefined,
checks: [ 'pkce' ],
account: [Function: defaultAccount],
[Symbol(custom-fetch)]: undefined
}
o.customFetch = Symbol()
customFetch = Symbol(custom-fetch)
fetch = [Function: fetch]
X [ERROR] [auth][error] CallbackRouteError: Read more at https://errors.authjs.dev#callbackrouteerror
[auth][cause]: TypeError: Illegal invocation: function called with
incorrect `this` reference. See
https://developers.cloudflare.com/workers/observability/errors/#illegal-invocation-errors
for details.
at Object.apply
(file:///C:/.../.wrangler/tmp/bundle-ZruFbV/checked-fetch.js:28:18)
at null.<anonymous>
(file:///C:/.../node_modules/.pnpm/@auth+core@0.37.0/node_modules/@auth/core/lib/actions/callback/oauth/callback.js:116:52)
at authenticatedRequest
(file:///C:/.../node_modules/.pnpm/oauth4webapi@3.1.1/node_modules/oauth4webapi/src/index.ts:3094:37)
at async tokenEndpointRequest
(file:///C:/.../node_modules/.pnpm/oauth4webapi@3.1.1/node_modules/oauth4webapi/src/index.ts:3136:20)
[auth][details]: {
"provider": "github"
}
jakemoves
This works perfectly. Appreciate it!
same here, can confirm the issue and downgrading resolving it.
We're seeing a related but slightly different manifestation of this issue in standard Vite SSR (not Cloudflare Workers).
The error occurs during Vite's SSR module evaluation:
SyntaxError: [vite] The requested module '@auth/core' does not provide an export named 'customFetch'
at analyzeImportedModDifference (vite/dist/node/chunks/dep-Cyk9bIUq.js:52042:15)
Our version compatibility findings:
@auth/sveltekit@1.4.2
with @auth/core@0.31.0
@auth/sveltekit@1.7.2
with @auth/core@0.37.2
(missing export error)@auth/sveltekit@1.7.2
with @auth/core@0.31.0
(version mismatch)The fact that this manifests both in Cloudflare Workers (as an illegal invocation) and in standard Vite SSR (as a missing export) suggests there might be a broader issue with how customFetch
is being exported and consumed.
Technical details:
@auth/core@0.37.2
, customFetch
is defined in lib/symbols.js
and re-exported in index.js
Environment:
Environment
Reproduction URL
https://github.com/pragmatic-recursion/auth-bug
Describe the issue
Running on Cloudflare Workers, not Pages! Works locally.
Server error
There is a problem with the server configuration.
Check the server logs for more information.
How to reproduce
1) Install Svelte https://developers.cloudflare.com/workers/frameworks/framework-guides/svelte/ npm create cloudflare@latest my-svelte-app -- --framework=svelte --experimental
2) Install @auth/sveltekit https://authjs.dev/reference/sveltekit npm install @auth/sveltekit
3) Add GitHub as a Provider
4) Deploy to Cloudflare Worker (Free)
It works locally but not when deployed
Expected behavior
Should be logged in