use the new session management

This commit is contained in:
Sven Czarnian
2022-11-04 21:04:45 +01:00
parent acea193aa0
commit fc05ae4546
8 changed files with 44 additions and 60 deletions

View File

@@ -1,18 +1,12 @@
import axios from 'axios';
import { Configuration } from './configuration';
import { Session } from './session';
import { User } from '../types';
export class Auth {
static async user(): Promise<User> {
const token = sessionStorage.getItem('token');
if (!token) {
return {
vatsimId: '',
fullName: '',
administrator: false,
airportConfigurationAccess: [],
};
}
static async user(): Promise<User | undefined> {
const token = Session.bearerToken();
if (!token) return undefined;
return axios
.get<User>(`${Configuration.resourceServer}/auth/user`, {
@@ -21,11 +15,6 @@ export class Auth {
},
})
.then((response) => response.data)
.catch(() => ({
vatsimId: '',
fullName: '',
administrator: false,
airportConfigurationAccess: [],
}));
.catch(() => undefined);
}
}