Skip to content

Commit

Permalink
add files
Browse files Browse the repository at this point in the history
  • Loading branch information
choden-dev committed Mar 12, 2024
1 parent b93253f commit 60a5f03
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
23 changes: 23 additions & 0 deletions client/src/services/OpenApiFetchClient.ts
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
7 changes: 7 additions & 0 deletions client/src/services/Queries.ts
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()
})
11 changes: 11 additions & 0 deletions client/src/services/QueryClient.ts
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

0 comments on commit 60a5f03

Please sign in to comment.