2021-05-09 11:18:18 +01:00
|
|
|
import { appendAPIURL, getHeaders } from "../apiUtils";
|
2021-05-07 11:53:26 +01:00
|
|
|
|
2021-05-08 00:21:58 +01:00
|
|
|
type TokenInfo = {
|
|
|
|
expire_time: string;
|
|
|
|
}
|
2021-05-07 11:53:26 +01:00
|
|
|
|
2021-05-08 00:21:58 +01:00
|
|
|
export async function lookupSelf(): Promise<TokenInfo> {
|
2021-05-07 11:53:26 +01:00
|
|
|
const request = new Request(appendAPIURL("/v1/auth/token/lookup-self"), {
|
|
|
|
headers: getHeaders(),
|
|
|
|
});
|
|
|
|
return fetch(request).then(response => {
|
|
|
|
return response.json();
|
|
|
|
}).then(data => {
|
|
|
|
if ("data" in data) {
|
|
|
|
return data.data;
|
|
|
|
} else if ("errors" in data) {
|
|
|
|
throw new Error(data.errors[0]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|