From d19807b212bf7b2c1fc77c6d7c0c43741cd60ab9 Mon Sep 17 00:00:00 2001 From: Akash K <57758277+amk-dev@users.noreply.github.com> Date: Fri, 22 Mar 2024 13:42:41 +0530 Subject: [PATCH] chore: split axios request options into platform (#3927) Co-authored-by: jamesgeorge007 --- .../src/helpers/teams/TeamsSearch.service.ts | 7 ++++--- packages/hoppscotch-common/src/platform/auth.ts | 10 ++++++++++ .../src/platform/auth/auth.platform.ts | 7 +++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/hoppscotch-common/src/helpers/teams/TeamsSearch.service.ts b/packages/hoppscotch-common/src/helpers/teams/TeamsSearch.service.ts index 10bf3cb3..015a611d 100644 --- a/packages/hoppscotch-common/src/helpers/teams/TeamsSearch.service.ts +++ b/packages/hoppscotch-common/src/helpers/teams/TeamsSearch.service.ts @@ -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 @@ -199,6 +200,8 @@ export class TeamSearchService extends Service { this.searchResultsRequests = {} this.expandedCollections.value = [] + const axiosPlatformConfig = platform.auth.axiosPlatformConfig?.() ?? {} + try { const searchResponse = await axios.get( `${ @@ -206,9 +209,7 @@ export class TeamSearchService extends Service { }/team-collection/search/${teamID}?searchQuery=${encodeURIComponent( query )}`, - { - withCredentials: true, - } + axiosPlatformConfig ) if (searchResponse.status !== 200) { diff --git a/packages/hoppscotch-common/src/platform/auth.ts b/packages/hoppscotch-common/src/platform/auth.ts index d2920c46..d32dce9e 100644 --- a/packages/hoppscotch-common/src/platform/auth.ts +++ b/packages/hoppscotch-common/src/platform/auth.ts @@ -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. @@ -135,6 +136,15 @@ export type AuthPlatformDef = { */ getGQLClientOptions?: () => Partial + /** + * 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. diff --git a/packages/hoppscotch-selfhost-web/src/platform/auth/auth.platform.ts b/packages/hoppscotch-selfhost-web/src/platform/auth/auth.platform.ts index c6708bc8..5c43adc0 100644 --- a/packages/hoppscotch-selfhost-web/src/platform/auth/auth.platform.ts +++ b/packages/hoppscotch-selfhost-web/src/platform/auth/auth.platform.ts @@ -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