sk-auth
sk-auth copied to clipboard
Prod builds with node adapter fail on google auth due to missing fetch
Looks like the oauth2.ts is using native fetch:
const res = await fetch(this.config.accessTokenUrl!, {
From what I've read, this won't work in SSR Sveltekit code, where we'd need to explicitly use node-fetch or pass through the sveltekit supplied "fetch". FWIW this is in sveltekit 1.0.0-next.165
Generated default settings
ReferenceError: fetch is not defined
at GoogleOAuth2Provider.getTokens (C:\projects\531-calc\node_modules\sk-auth\dist\providers\oauth2.js:49:17)
at GoogleOAuth2Provider.callback (C:\projects\531-calc\node_modules\sk-auth\dist\providers\oauth2.base.js:37:31)
at Auth.handleProviderCallback (C:\projects\531-calc\node_modules\sk-auth\dist\auth.js:131:51)
at Auth.handleEndpoint (C:\projects\531-calc\node_modules\sk-auth\dist\auth.js:180:29)
at Auth.get (C:\projects\531-calc\node_modules\sk-auth\dist\auth.js:49:25)
at render_endpoint (file:///C:/projects/531-calc/build/middlewares.js:1098:26)
at async resolve (file:///C:/projects/531-calc/build/middlewares.js:2243:56)
at async Object.handle (file:///C:/projects/531-calc/build/middlewares.js:2498:20)
at async respond (file:///C:/projects/531-calc/build/middlewares.js:2227:12)
at async Array.<anonymous> (file:///C:/projects/531-calc/build/middlewares.js:4322:22)
The same applies to SvelteKit v1.0.0-next.195
... Here I'm not explicitly using fetch
, it seems to be done by the library itself.
The problem also appears when trying to log in with username/email and password...
Tried explicitly using both node-fetch
and cross-fetch within lib itself w/o success...
Also for the use case of localhost it works perfectly...
But adding host
parameter to SvelteKitAuth
constructor gives fetch is not defined
.
And if you don't setup host parameter your production build may not set an HTTPS redirection URI.