import decode from "jwt-decode" ; const SKEW_TOLERANCE = 300 ; export interface Claims { jti ? : string ; exp ? : number ; } export function parseAccessTokenClaims < T = { } > ( accessToken ) { try { const claims = decode < Claims & T > ( accessToken ) ; if ( ! claims . jti || typeof claims . jti !== "string" ) { delete claims . jti ; } if ( ! claims . exp || typeof claims . exp !== "number" ) { delete claims . exp ; } return claims ; } catch ( err ) { console . error ( "access token can not be parsed:" , err ) ; return null ; } } param expiredAt export function computeExpiresIn ( expiredAt ) { const expiresIn = expiredAt * 1000 - Date . now ( ) ; if ( expiresIn + SKEW_TOLERANCE <= 0 ) { return null ; } return expiresIn ; }