diff options
Diffstat (limited to 'src/lib/token.ts')
-rw-r--r-- | src/lib/token.ts | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/lib/token.ts b/src/lib/token.ts index 05de87e..93ec0cf 100644 --- a/src/lib/token.ts +++ b/src/lib/token.ts @@ -1,4 +1,4 @@ -import { ApiClient } from "../clients/api_client"; +import jwt_decode from "jwt-decode"; import axios from "axios"; export default class Token { @@ -42,4 +42,29 @@ export default class Token { this.logout(); } } + + getEmail() { + return this.decode()?.data; + } + + getRole() { + return this.decode()?.aud; + } + + getJTI() { + return this.decode()?.jti; + } + + getExpirationDate() { + return this.decode()?.exp; + } + + private decode(): { data: string; aud: string; jti: string; exp: number; } | null { + const token = this.get(); + + if(token != null) + return jwt_decode(token); + + return null; + } }
\ No newline at end of file |