From f55976a2c3acad52119236637206f67f755cf896 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Tue, 9 Aug 2022 13:29:51 -0400 Subject: [PATCH] Pass down client custom headers to native (#6556) --- app/client/rest/base.ts | 11 +++++++++++ app/client/rest/users.ts | 18 +++++++++++++++--- types/api/client.d.ts | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/client/rest/base.ts b/app/client/rest/base.ts index 0c800853e..cafe5f88d 100644 --- a/app/client/rest/base.ts +++ b/app/client/rest/base.ts @@ -256,6 +256,17 @@ export default class ClientBase { requestOptions.timeoutInterval = options.timeoutInterval; } + if (options.headers) { + if (requestOptions.headers) { + requestOptions.headers = { + ...requestOptions.headers, + ...options.headers, + }; + } else { + requestOptions.headers = options.headers; + } + } + let response: ClientResponse; try { response = await request!(url, requestOptions); diff --git a/app/client/rest/users.ts b/app/client/rest/users.ts index 47d1a9264..eada89f63 100644 --- a/app/client/rest/users.ts +++ b/app/client/rest/users.ts @@ -169,7 +169,12 @@ const ClientUsers = (superclass: any) => class extends superclass { const {data} = await this.doFetch( `${this.getUsersRoute()}/login`, - {method: 'post', body}, + { + method: 'post', + body, + headers: {'Cache-Control': 'no-store'}, + }, + false, ); return data; @@ -341,14 +346,21 @@ const ClientUsers = (superclass: any) => class extends superclass { getSessions = async (userId: string) => { return this.doFetch( `${this.getUserRoute(userId)}/sessions`, - {method: 'get'}, + { + method: 'get', + headers: {'Cache-Control': 'no-store'}, + }, ); }; checkUserMfa = async (loginId: string) => { return this.doFetch( `${this.getUsersRoute()}/mfa`, - {method: 'post', body: {login_id: loginId}}, + { + method: 'post', + body: {login_id: loginId}, + headers: {'Cache-Control': 'no-store'}, + }, ); }; diff --git a/types/api/client.d.ts b/types/api/client.d.ts index e99bfb8d6..fca3e7882 100644 --- a/types/api/client.d.ts +++ b/types/api/client.d.ts @@ -8,6 +8,7 @@ type ClientOptions = { method?: string; noRetry?: boolean; timeoutInterval?: number; + headers?: Record; }; interface ClientErrorProps extends Error {