Skip to content

Commit

Permalink
fix: fixed http call
Browse files Browse the repository at this point in the history
  • Loading branch information
mbret committed Feb 23, 2024
1 parent 32c690d commit c310169
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
8 changes: 2 additions & 6 deletions packages/web/src/auth/useSignIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@ export const useSignIn = () => {
switchMap((authResponse) => authResponse.user.getIdToken()),
switchMap((token) =>
from(
httpClient.fetch({
httpClient.post({
url: `${API_URI}/signin`,
method: "post",
body: JSON.stringify({
body: {
token
}),
headers: {
"Content-Type": "application/json"
}
})
)
Expand Down
31 changes: 24 additions & 7 deletions packages/web/src/http/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ export class HttpClientError extends Error {
}
}

type FetchParams = NonNullable<Parameters<typeof fetch>[1]>

class HttpClient {
fetch = async ({
url,
...params
}: Parameters<typeof fetch>[1] & {
}: FetchParams & {
url: string
}) => {
const authState = authStateSignal.getValue()
Expand All @@ -42,11 +44,27 @@ class HttpClient {
return { data }
}

post = async (
options: Omit<FetchParams, "body" | "method"> & {
url: string
body: Record<string, unknown>
}
) => {
return this.fetch({
...options,
method: "post",
body: JSON.stringify(options.body),
headers: {
"Content-Type": "application/json",
...options.headers
}
})
}

refreshMetadata = (bookId: string, credentials?: { [key: string]: any }) =>
this.fetch({
this.post({
url: `${API_URI}/refresh-metadata`,
body: JSON.stringify({ bookId }),
method: "post",
body: { bookId },
headers: {
"oboku-credentials": JSON.stringify(credentials)
}
Expand All @@ -56,10 +74,9 @@ class HttpClient {
dataSourceId: string,
credentials?: { [key: string]: any }
) =>
this.fetch({
this.post({
url: `${API_URI}/sync-datasource`,
method: "post",
body: JSON.stringify({ dataSourceId }),
body: { dataSourceId },
headers: {
"oboku-credentials": JSON.stringify(credentials)
}
Expand Down

0 comments on commit c310169

Please sign in to comment.