[FA-misc] Astro migration works, probably want to touchup the frontend but that can be in Phase 4
This commit is contained in:
21
fictionarchive-web-astro/src/lib/graphql/client.ts
Normal file
21
fictionarchive-web-astro/src/lib/graphql/client.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Client, cacheExchange, fetchExchange } from '@urql/core';
|
||||
import { get } from 'svelte/store';
|
||||
import { user } from '../auth/authStore';
|
||||
|
||||
export function createClient() {
|
||||
return new Client({
|
||||
url: import.meta.env.PUBLIC_GRAPHQL_URI,
|
||||
exchanges: [cacheExchange, fetchExchange],
|
||||
fetchOptions: () => {
|
||||
const currentUser = get(user);
|
||||
return {
|
||||
headers: currentUser?.access_token
|
||||
? { Authorization: `Bearer ${currentUser.access_token}` }
|
||||
: {},
|
||||
};
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Singleton for use in components
|
||||
export const client = createClient();
|
||||
Reference in New Issue
Block a user