diff --git a/frontend/src/api/auth.ts b/frontend/src/api/auth.ts index b1578519b..c46f0d5f7 100644 --- a/frontend/src/api/auth.ts +++ b/frontend/src/api/auth.ts @@ -1,5 +1,7 @@ +import 'core-js/stable/atob'; import { jwtDecode, JwtPayload } from 'jwt-decode'; import { logErr } from '../util/errors'; +import { emptyOrNullString } from '../util/types'; import { apiCall, EmptyBody } from './common'; export const refreshKey = 'refresh'; @@ -34,19 +36,23 @@ export const refreshToken = async () => { }; export const isTokenExpired = (token: string): boolean => { - if (!token || token == '') { + if (emptyOrNullString(token)) { return true; } - const claims: JwtPayload = jwtDecode(token); - if (!claims || !claims.exp) { - return true; - } - - const expirationTimeInSeconds = claims.exp * 1000; const now = new Date(); - return expirationTimeInSeconds <= now.getTime(); + try { + const claims: JwtPayload = jwtDecode(token); + if (!claims || !claims.exp) { + return true; + } + + const expirationTimeInSeconds = claims.exp * 1000; + return expirationTimeInSeconds <= now.getTime(); + } catch (e) { + return true; + } }; export const writeAccessToken = (token: string) => { diff --git a/frontend/src/api/common.ts b/frontend/src/api/common.ts index 47d6b83ea..3cd4369b4 100644 --- a/frontend/src/api/common.ts +++ b/frontend/src/api/common.ts @@ -1,3 +1,4 @@ +import { logErr } from '../util/errors'; import { parseDateTime } from '../util/text'; import { emptyOrNullString } from '../util/types'; import { @@ -126,10 +127,13 @@ export const apiCall = async < credentials: 'include', method: method.toUpperCase() }; - - const accessToken = await getAccessToken(isRefresh ?? false); - - if (accessToken != '') { + let accessToken = ''; + try { + accessToken = await getAccessToken(isRefresh ?? false); + } catch (e) { + logErr(e); + } + if (!emptyOrNullString(accessToken)) { headers['Authorization'] = `Bearer ${accessToken}`; } diff --git a/frontend/src/component/LazyTable.tsx b/frontend/src/component/LazyTable.tsx index 2ab88251e..094933def 100644 --- a/frontend/src/component/LazyTable.tsx +++ b/frontend/src/component/LazyTable.tsx @@ -213,8 +213,8 @@ export const LazyTableHeader = ({ col.sortKey != sortColumn ? 'none' : order == 'asc' - ? 'underline' - : 'overline' + ? 'underline' + : 'overline' }} variant={'button'} >