Selaa lähdekoodia

check if the token is valid

Sven Czarnian 2 vuotta sitten
vanhempi
commit
3b81106334
1 muutettua tiedostoa jossa 14 lisäystä ja 0 poistoa
  1. 14 0
      src/services/auth.ts

+ 14 - 0
src/services/auth.ts

@@ -4,6 +4,20 @@ import { Session } from './session';
 import { User } from '../types';
 
 export class Auth {
+  static async tokenIsValid(): Promise<boolean> {
+    const token = Session.bearerToken();
+    if (!token) return false;
+
+    return axios
+      .get<void>(`${Configuration.resourceServer}/auth/validate`, {
+        headers: {
+          Authorization: `Bearer ${token}`,
+        },
+      })
+      .then(() => true)
+      .catch(() => false);
+  }
+
   static async user(): Promise<User | undefined> {
     const token = Session.bearerToken();
     if (!token) return undefined;