summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/form_utils.ts10
-rw-r--r--src/lib/token.ts27
2 files changed, 36 insertions, 1 deletions
diff --git a/src/lib/form_utils.ts b/src/lib/form_utils.ts
new file mode 100644
index 0000000..a4e7bff
--- /dev/null
+++ b/src/lib/form_utils.ts
@@ -0,0 +1,10 @@
+export function deleteEmptyFields(form: FormData) {
+ const trimmed_form = form;
+
+ for(const key of trimmed_form) {
+ if(trimmed_form.get(key[0]) == '')
+ trimmed_form.delete(key[0]);
+ }
+
+ return trimmed_form;
+} \ No newline at end of file
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