import jwtDecode from 'jwt-decode' ; export enum AppStorageKey { TOKEN = 'token' , REFRESH_TOKEN = 'refresh-token' , REFRESH_TOKEN_EXP = 'rt-exp' } interface ItokenDecode { id ? : string ; iat : number ; exp : number ; } param token param refreshToken export function setToken ( token , refreshToken ) { sessionStorage . setItem ( AppStorageKey . TOKEN , token ) ; setRefreshToken ( refreshToken ) ; const rtExp = ( jwtDecode ( refreshToken ) as ItokenDecode ) ?. exp * 1000 ; setRTExp ( rtExp ) ; } export function getToken ( ) { return sessionStorage . getItem ( AppStorageKey . TOKEN ) ; } export function setRefreshToken ( refreshToken ) { sessionStorage . setItem ( AppStorageKey . REFRESH_TOKEN , refreshToken ) ; } export function getRefreshToken ( ) { return sessionStorage . getItem ( AppStorageKey . REFRESH_TOKEN ) ; } export function setRTExp ( exp ) { sessionStorage . setItem ( AppStorageKey . REFRESH_TOKEN_EXP , `${ exp }` ) ; } export function getRTExp ( ) { const rtExpStr = sessionStorage . getItem ( AppStorageKey . REFRESH_TOKEN_EXP ) ; return rtExpStr ? Number ( rtExpStr ) : 0 ; } export function clearAll ( ) { sessionStorage . clear ( ) ; }