fix(ui): assist credential call with authorization

This commit is contained in:
Shekar Siri 2024-11-07 11:46:07 +01:00
parent 6b7a1499af
commit 1232ab5b57
3 changed files with 22 additions and 23 deletions

View file

@ -58,17 +58,13 @@ export default class APIClient {
private onUpdateJwt: (data: { jwt?: string, spotJwt?: string }) => void;
private refreshingTokenPromise: Promise<string> | null = null;
constructor(jwt?: string | null) {
constructor() {
this.init = {
headers: new Headers({
Accept: 'application/json',
'Content-Type': 'application/json'
})
};
if (jwt) {
this.setJwt(jwt);
}
}
setJwt(jwt: string | null): void {

View file

@ -15,6 +15,7 @@ import { useLocation } from 'react-router-dom';
import { toast } from 'react-toastify';
import { useStore } from 'App/mstore';
import { observer } from 'mobx-react-lite';
import { sessionService } from 'App/services';
interface Props {
customSession?: Session;
@ -54,26 +55,11 @@ function LivePlayer({
name: userName,
},
};
if (isEnterprise) {
new APIClient(userStore.jwt)
.get('/config/assist/credentials')
.then((r) => r.json())
.then(({ data }) => {
const [player, store] = createLiveWebPlayer(
sessionWithAgentData,
data,
userId,
projectId,
(state) => makeAutoObservable(state),
toast
);
setContextValue({ player, store });
playerInst = player;
});
} else {
const initPlayer = async (credentials = null) => {
const [player, store] = createLiveWebPlayer(
sessionWithAgentData,
null,
credentials,
userId,
projectId,
(state) => makeAutoObservable(state),
@ -81,6 +67,12 @@ function LivePlayer({
);
setContextValue({ player, store });
playerInst = player;
};
if (isEnterprise) {
sessionService.getAssistCredentials().then(initPlayer);
} else {
void initPlayer();
}
return () => {

View file

@ -121,4 +121,15 @@ export default class SettingsService {
.then((j) => j.data || {})
.catch(Promise.reject);
}
async getAssistCredentials(): Promise<any> {
try {
const r = await this.client
.get('/config/assist/credentials');
const j = await r.json();
return j.data || {};
} catch (reason) {
return Promise.reject(reason);
}
}
}