21 行
582 B
TypeScript
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);
|
|
}
|
|
}
|