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: [], | ||||
|       })); | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user