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

Prod builds with node adapter fail on google auth due to missing fetch #51

Open
dcaslin opened this issue Sep 13, 2021 · 4 comments
Open

Comments

@dcaslin
Copy link

dcaslin commented Sep 13, 2021

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)
@heshdotcc
Copy link

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.

@heshdotcc
Copy link

The problem also appears when trying to log in with username/email and password...

@heshdotcc
Copy link

Tried explicitly using both node-fetch and cross-fetch within lib itself w/o success...

@heshdotcc
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants