add more backend services

This commit is contained in:
Sven Czarnian
2022-11-04 15:28:29 +01:00
parent ecc01fbb8c
commit 7807c2784c
3 changed files with 52 additions and 1 deletions

31
src/services/auth.ts Normal file
View File

@@ -0,0 +1,31 @@
import axios from 'axios';
import { Configuration } from './configuration';
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: [],
};
}
return axios
.get<User>(`${Configuration.resourceServer}/auth/user`, {
headers: {
Authorization: `Bearer ${sessionStorage.getItem('token')}`,
},
})
.then((response) => response.data)
.catch(() => ({
vatsimId: '',
fullName: '',
administrator: false,
airportConfigurationAccess: [],
}));
}
}