Files
aman-frontend/src/services/auth.ts
2022-11-04 21:04:45 +01:00

21 行
582 B
TypeScript

import axios from 'axios';
import { Configuration } from './configuration';
import { Session } from './session';
import { User } from '../types';
export class Auth {
static async user(): Promise<User | undefined> {
const token = Session.bearerToken();
if (!token) return undefined;
return axios
.get<User>(`${Configuration.resourceServer}/auth/user`, {
headers: {
Authorization: `Bearer ${sessionStorage.getItem('token')}`,
},
})
.then((response) => response.data)
.catch(() => undefined);
}
}