From cbebedd51e1b4a2f709341b792dd073bac83f15d Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Fri, 12 May 2023 23:01:55 -0600 Subject: Añadido formulario de edición de cuenta MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/token.ts | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/lib/token.ts') 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 -- cgit v1.2.3