Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getUserInfo: async () => {
const appContext = AppContextAccessor.getAppContext();
if (appContext.authenticationInfo.authenticated && !appContext.user) {
const user = await AccountApi.get();
AppContextAccessor.setAppContext({ ...AppContextAccessor.getAppContext(), user: user });
}
}
};
getUserInfo: async () => {
const appContext = AppContextAccessor.getAppContext();
if (appContext.authenticationInfo.authenticated && !appContext.user) {
const user = await AccountApi.get();
AppContextAccessor.setAppContext({ ...AppContextAccessor.getAppContext(), user: user });
}
}
};
isAuthorized: (userRole?: UserRole) => {
var appContext = AppContextAccessor.getAppContext();
return (
appContext.authenticationInfo.authenticated &&
(userRole === undefined ||
(appContext.user !== undefined && appContext.user.role === userRole))
);
}
};
function getHeaders(contentType?: string | undefined): Record {
let headers: Record = {};
let appContext = AppContextAccessor.getAppContext();
if (appContext.authenticationInfo.authenticated && appContext.authenticationInfo.access_token) {
headers["Authorization"] = `Bearer ${appContext.authenticationInfo.access_token}`;
}
headers["Content-Type"] = contentType ? contentType : "application/json";
return headers;
}
checkAndRenewAccessToken: async (): Promise => {
let appContext = AppContextAccessor.getAppContext();
if (appContext.authenticationInfo.authenticated) {
if (accessTokenIsExpired(appContext.authenticationInfo.expiry_date)) {
const tokenResponse = await IdentityApi.refreshToken(
appContext.authenticationInfo.refresh_token
);
if (renewFailed(tokenResponse)) {
AuthenticationService.clearAuthenticationInfo(true);
return false;
}
AppContextAccessor.setAppContext(appContext => {
return {
...appContext,