Browse Source

check if the token is valid

Sven Czarnian 2 years ago
parent
commit
3b81106334
1 changed files with 14 additions and 0 deletions
  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;