check if the token is valid
This commit is contained in:
@@ -4,6 +4,20 @@ import { Session } from './session';
|
|||||||
import { User } from '../types';
|
import { User } from '../types';
|
||||||
|
|
||||||
export class Auth {
|
export class Auth {
|
||||||
|
static async tokenIsValid(): Promise<boolean> {
|
||||||
|
const token = Session.bearerToken();
|
||||||
|
if (!token) return false;
|
||||||
|
|
||||||
|
return axios
|
||||||
|
.get<void>(`${Configuration.resourceServer}/auth/validate`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then(() => true)
|
||||||
|
.catch(() => false);
|
||||||
|
}
|
||||||
|
|
||||||
static async user(): Promise<User | undefined> {
|
static async user(): Promise<User | undefined> {
|
||||||
const token = Session.bearerToken();
|
const token = Session.bearerToken();
|
||||||
if (!token) return undefined;
|
if (!token) return undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user