You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
volume24h/app/utils/jwt.ts

38 lines
675 B

// src/utils/jwt.ts
import dayjs from 'dayjs'
import jwtDecode from 'jwt-decode'
export interface JwtHeader {
alg: string
typ: string
}
export interface JwtToken {
exp: number
orig_iat: number
sub: string
scope: string
pid: string | undefined
}
export const decode = (token: string) => ({
header: jwtDecode<JwtHeader>(token, { header: true }),
payload: jwtDecode<JwtToken>(token),
})
export const getExpire = (token: string) => {
const { payload } = decode(token)
return dayjs.unix(payload.exp)
}
export const getJwtTokenObj = (token: string) => {
return jwtDecode<JwtToken>(token)
}
export default {
getJwtTokenObj,
getExpire,
decode,
}