-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Not clear that fetch
is available in hooks
#2916
Comments
My story behind this bug is the following: I was writing a Frustrated, I cloned a fresh demo app, attempted to use a global fetch and it worked. |
the same problem wanna use fetch in the handle hook for a token refresh, any workaround? |
@iwnow it's already available as a global variable |
Probably the main reason that it's global is so that it's closer to browser behaviour, and arbitrary code from other files can use |
Now documented here: https://kit.svelte.dev/docs/web-standards#fetch-apis |
Describe the bug
The docs section on the hooks doesn't mention if
fetch
is available on the server side to use inside a hook (handle()
, for example) and how to obtain a reference to it. A reference to somefetch()
is present in the sample code for theexternalFetch()
hook, but seeing as it's not a complete file, it leads to reader to believe thisfetch
might have to come from elsewhere, such asnode-fetch
installed additionally.I see several solutions to this issue:
Add a note to the documentation on hooks saying that
fetch
is globally available to use in any custom hook.Rework the way the references to
fetch
are obtained. For example, create an internal module that you could importfetch
from, so thathooks.ts
would look like this:I would prefer the second solution as it allows explicit reference to
fetch
as well as explicit typings for TypeScript. As a user of SvelteKit writing hooks, I would be more confident knowing that I can importfetch
from somewhere to use in hooks instead of hoping there's a global one.Reproduction
There is no reproduction
Logs
No response
System Info
Severity
annoyance
Additional Information
No response
The text was updated successfully, but these errors were encountered: