check if the token is valid

This commit is contained in:
Sven Czarnian
2022-11-04 22:58:13 +01:00
parent c23fcb3ea5
commit 3b81106334

View File

@@ -4,6 +4,20 @@ import { Session } from './session';
import { User } from '../types'; import { User } from '../types';
export class Auth { 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> { static async user(): Promise<User | undefined> {
const token = Session.bearerToken(); const token = Session.bearerToken();
if (!token) return undefined; if (!token) return undefined;