{
removeToken();
history.push(ROUTE_LOGIN);
},
},
],
}}
>
{intl.formatMessage({ id: 'common.user' })}
);
};
export async function getInitialState() {
const token: string = getToken();
const { pathname } = history.location;
if (!token) {
if (pathname !== ROUTE_LOGIN) {
history.push(`${ROUTE_LOGIN}?redirect=${pathname}`);
} else {
history.push(ROUTE_LOGIN);
}
return {};
}
const parsed = parseJwt(token);
if (!parsed) {
removeToken();
if (pathname !== ROUTE_LOGIN) {
history.push(`${ROUTE_LOGIN}?redirect=${pathname}`);
} else {
history.push(ROUTE_LOGIN);
}
return {};
}
const { sub, exp } = parsed;
const now = Math.floor(Date.now() / 1000);
const oneHour = 60 * 60;
if (exp - now < oneHour) {
console.warn('Token expired or nearly expired, redirecting...');
removeToken();
if (pathname !== ROUTE_LOGIN) {
history.push(`${ROUTE_LOGIN}?redirect=${pathname}`);
} else {
history.push(ROUTE_LOGIN);
}
return {};
}
return {
currentUser: sub,
exp,
};
}
export const layout: RunTimeLayoutConfig = (initialState) => {
return {
title: 'SMT Production Management',
fixedHeader: true,
contentWidth: 'Fluid',
navTheme: 'light',
splitMenus: true,
menu: {
locale: true,
},
contentStyle: {
padding: 0,
margin: 0,
paddingInline: 0,
},
avatarProps: {
size: 'small',
render: () =>