Switch to ky

This commit is contained in:
Alex Gleason 2024-10-08 21:38:58 -05:00
parent f3b607e609
commit 5df511a784
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
3 changed files with 26 additions and 0 deletions

View File

@ -114,6 +114,7 @@
"intl-messageformat": "10.5.11", "intl-messageformat": "10.5.11",
"intl-pluralrules": "^2.0.0", "intl-pluralrules": "^2.0.0",
"isomorphic-dompurify": "^2.3.0", "isomorphic-dompurify": "^2.3.0",
"ky": "^1.7.2",
"leaflet": "^1.8.0", "leaflet": "^1.8.0",
"lexical": "^0.18.0", "lexical": "^0.18.0",
"line-awesome": "^1.3.0", "line-awesome": "^1.3.0",

20
src/hooks/useClient.ts Normal file
View File

@ -0,0 +1,20 @@
import ky, { KyInstance } from 'ky';
import { useAppSelector } from './useAppSelector';
import { useOwnAccount } from './useOwnAccount';
export function useClient(): KyInstance {
const { account } = useOwnAccount();
const accessToken = useAppSelector((state) => account ? state.auth.users.get(account.url)?.access_token : undefined);
const headers: Record<string, string> = {};
if (accessToken) {
headers.Authorization = `Bearer ${accessToken}`;
}
return ky.create({
prefixUrl: account ? new URL(account.url).origin : undefined,
headers,
});
}

View File

@ -5938,6 +5938,11 @@ known-css-properties@^0.29.0:
resolved "https://registry.yarnpkg.com/known-css-properties/-/known-css-properties-0.29.0.tgz#e8ba024fb03886f23cb882e806929f32d814158f" resolved "https://registry.yarnpkg.com/known-css-properties/-/known-css-properties-0.29.0.tgz#e8ba024fb03886f23cb882e806929f32d814158f"
integrity sha512-Ne7wqW7/9Cz54PDt4I3tcV+hAyat8ypyOGzYRJQfdxnnjeWsTxt1cy8pjvvKeI5kfXuyvULyeeAvwvvtAX3ayQ== integrity sha512-Ne7wqW7/9Cz54PDt4I3tcV+hAyat8ypyOGzYRJQfdxnnjeWsTxt1cy8pjvvKeI5kfXuyvULyeeAvwvvtAX3ayQ==
ky@^1.7.2:
version "1.7.2"
resolved "https://registry.yarnpkg.com/ky/-/ky-1.7.2.tgz#b97d9b997ba51ff1e152f0815d3d27b86513eb1c"
integrity sha512-OzIvbHKKDpi60TnF9t7UUVAF1B4mcqc02z5PIvrm08Wyb+yOcz63GRvEuVxNT18a9E1SrNouhB4W2NNLeD7Ykg==
kysely@^0.27.3: kysely@^0.27.3:
version "0.27.3" version "0.27.3"
resolved "https://registry.yarnpkg.com/kysely/-/kysely-0.27.3.tgz#6cc6c757040500b43c4ac596cdbb12be400ee276" resolved "https://registry.yarnpkg.com/kysely/-/kysely-0.27.3.tgz#6cc6c757040500b43c4ac596cdbb12be400ee276"