Skip to content

Commit

Permalink
hot fix for app service authentication issue (#1226)
Browse files Browse the repository at this point in the history
  • Loading branch information
v-saikirang authored Nov 23, 2023
1 parent c40047a commit 40d2c51
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions Source/CompanyCommunicator/ClientApp/src/apis/apiDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@

import { ROUTE_PARTS } from '../routes';
import i18n from '../i18n';
import { store } from '../store';
import { HostClientType, authentication } from '@microsoft/teams-js';

const isIOSHost = () => {
const clientType = store.getState().messages.hostClientType.payload;
return clientType === HostClientType.ios || clientType === HostClientType.ipados;
};
import { authentication } from '@microsoft/teams-js';

export class ApiDecorator {
public async getJsonResponse(url: string): Promise<any> {
return await this.handleApiCall('get', url).then((response) => {
if (response.type === 'cors' && response.status >= 401 && isIOSHost()) {
if (response.type === 'cors' && response.status >= 401) {
return this.handleApiCall('get', response.url).then((result) => result.json());
} else if (response.status >= 401) {
this.handleError(response);
Expand All @@ -26,7 +20,7 @@ export class ApiDecorator {

public async getTextResponse(url: string): Promise<any> {
return await this.handleApiCall('get', url).then((response) => {
if (response.type === 'cors' && response.status >= 401 && isIOSHost()) {
if (response.type === 'cors' && response.status >= 401) {
return this.handleApiCall('get', response.url).then((result) => result.text());
} else if (response.status >= 401) {
this.handleError(response);
Expand All @@ -38,7 +32,7 @@ export class ApiDecorator {

public async postAndGetJsonResponse(url: string, data?: any): Promise<any> {
return await this.handleApiCall('post', url, data).then((response) => {
if (response.type === 'cors' && response.status >= 401 && isIOSHost()) {
if (response.type === 'cors' && response.status >= 401) {
return this.handleApiCall('post', response.url, data).then((result) => result.json());
} else {
return response.json();
Expand All @@ -48,7 +42,7 @@ export class ApiDecorator {

public async postAndGetTextResponse(url: string, data?: any): Promise<any> {
return await this.handleApiCall('post', url, data).then((response) => {
if (response.type === 'cors' && response.status >= 401 && isIOSHost()) {
if (response.type === 'cors' && response.status >= 401) {
return this.handleApiCall('post', response.url, data).then((result) => result.text());
} else {
return response.text();
Expand All @@ -58,7 +52,7 @@ export class ApiDecorator {

public async putAndGetJsonResponse(url: string, data?: any): Promise<any> {
return await this.handleApiCall('put', url, data).then((response) => {
if (response.type === 'cors' && response.status >= 401 && isIOSHost()) {
if (response.type === 'cors' && response.status >= 401) {
return this.handleApiCall('put', response.url, data).then((result) => result.json());
} else {
return response.json();
Expand All @@ -68,7 +62,7 @@ export class ApiDecorator {

public async putAndGetTextResponse(url: string, data?: any): Promise<any> {
return await this.handleApiCall('put', url, data).then((response) => {
if (response.type === 'cors' && response.status >= 401 && isIOSHost()) {
if (response.type === 'cors' && response.status >= 401) {
return this.handleApiCall('put', response.url, data).then((result) => result.text());
} else {
return response.text();
Expand All @@ -78,7 +72,7 @@ export class ApiDecorator {

public async deleteAndGetJsonResponse(url: string): Promise<any> {
return await this.handleApiCall('delete', url).then((response) => {
if (response.type === 'cors' && response.status >= 401 && isIOSHost()) {
if (response.type === 'cors' && response.status >= 401) {
return this.handleApiCall('delete', response.url).then((result) => result.json());
} else {
return response.json();
Expand All @@ -88,7 +82,7 @@ export class ApiDecorator {

public async deleteAndGetTextResponse(url: string): Promise<any> {
return await this.handleApiCall('delete', url).then((response) => {
if (response.type === 'cors' && response.status >= 401 && isIOSHost()) {
if (response.type === 'cors' && response.status >= 401) {
return this.handleApiCall('delete', response.url).then((result) => result.text());
} else {
return response.text();
Expand Down

0 comments on commit 40d2c51

Please sign in to comment.