-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b93253f
commit 60a5f03
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import createClient, { Middleware } from "openapi-fetch" | ||
import type { paths } from "models/__generated__/schema" | ||
|
||
let accessToken: string | undefined | ||
|
||
const authMiddleware: Middleware = { | ||
async onRequest(req) { | ||
// TODO: Handle Auth | ||
if (!accessToken) { | ||
accessToken = "placeholder" | ||
} | ||
req.headers.set("Authorization", `Bearer ${accessToken}`) | ||
return req | ||
} | ||
} | ||
|
||
const fetchClient = createClient<paths>({ | ||
baseUrl: import.meta.env.VITE_BACKEND_BASE_URL | ||
}) | ||
|
||
fetchClient.use(authMiddleware) | ||
|
||
export default fetchClient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useQuery } from "@tanstack/react-query" | ||
import UserService from "./UserService" | ||
|
||
export const useUsers = useQuery({ | ||
queryKey: ["allUsers"], | ||
queryFn: () => UserService.getUsers() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { QueryClient } from "@tanstack/react-query" | ||
|
||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
notifyOnChangeProps: ["data"] | ||
} | ||
} | ||
}) | ||
|
||
export default queryClient |