Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: split axios request options into platform #3927

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -15,6 +15,7 @@ import { TeamRequest } from "./TeamRequest"
import { Service } from "dioc"
import axios from "axios"
import { Ref } from "vue"
import { platform } from "~/platform"

type CollectionSearchMeta = {
isSearchResult?: boolean
Expand Down Expand Up @@ -199,16 +200,16 @@ export class TeamSearchService extends Service {
this.searchResultsRequests = {}
this.expandedCollections.value = []

const axiosPlatformConfig = platform.auth.axiosPlatformConfig?.() ?? {}

try {
const searchResponse = await axios.get(
`${
this.endpoint
}/team-collection/search/${teamID}?searchQuery=${encodeURIComponent(
query
)}`,
{
withCredentials: true,
}
axiosPlatformConfig
)

if (searchResponse.status !== 200) {
Expand Down
10 changes: 10 additions & 0 deletions packages/hoppscotch-common/src/platform/auth.ts
Expand Up @@ -3,6 +3,7 @@ import { Observable } from "rxjs"
import { Component } from "vue"
import { getI18n } from "~/modules/i18n"
import * as E from "fp-ts/Either"
import { AxiosRequestConfig } from "axios"

/**
* A common (and required) set of fields that describe a user.
Expand Down Expand Up @@ -135,6 +136,15 @@ export type AuthPlatformDef = {
*/
getGQLClientOptions?: () => Partial<ClientOptions>

/**
* called by the platform to provide additional/different config options when
* sending requests with axios
* eg: SH needs to include cookies in the request, while Central doesn't and throws a cors error if it does
*
* @returns AxiosRequestConfig
*/
axiosPlatformConfig?: () => AxiosRequestConfig

/**
* Returns the string content that should be returned when the user selects to
* copy auth token from Developer Options.
Expand Down
Expand Up @@ -211,6 +211,13 @@ export const def: AuthPlatformDef = {
}
},

axiosPlatformConfig() {
return {
// for including cookies in the request
withCredentials: true,
}
},

/**
* it is not possible for us to know if the current cookie is expired because we cannot access http-only cookies from js
* hence just returning if the currentUser$ has a value associated with it
Expand Down