add more backend services
This commit is contained in:
31
src/services/auth.ts
Normal file
31
src/services/auth.ts
Normal 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: [],
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Airport } from "./airport";
|
||||
import { Auth } from './auth';
|
||||
import { Configuration } from "./configuration";
|
||||
import { System } from './system';
|
||||
|
||||
export { Airport, Configuration };
|
||||
export { Airport, Auth, Configuration, System };
|
||||
|
||||
18
src/services/system.ts
Normal file
18
src/services/system.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import axios from 'axios';
|
||||
import { Configuration } from './configuration';
|
||||
|
||||
export class System {
|
||||
static async timestamp(): Promise<number> {
|
||||
const token = sessionStorage.getItem('token');
|
||||
if (!token) return 0;
|
||||
|
||||
return axios
|
||||
.get<number>(`${Configuration.resourceServer}/system/timestamp`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
.then((response) => response.data)
|
||||
.catch(() => 0);
|
||||
}
|
||||
}
|
||||
Fai riferimento in un nuovo problema
Block a user