summaryrefslogtreecommitdiff
path: root/src/clients/api_client.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/clients/api_client.ts')
-rw-r--r--src/clients/api_client.ts33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/clients/api_client.ts b/src/clients/api_client.ts
index 7d2cf34..fc2d361 100644
--- a/src/clients/api_client.ts
+++ b/src/clients/api_client.ts
@@ -1,11 +1,38 @@
-import axios from "axios";
+import axios, { AxiosResponse } from "axios";
+import Token from "../lib/token";
export class ApiClient {
readonly url = "http://localhost:3000/api";
+ token = new Token();
- async get(path: string, params?: URLSearchParams, headers?: object) {
+ async authenticatedGet(path: string) {
const request_url = `${ this.url }${ path }`;
- const response = await this.makeGetRequest(request_url, headers);
+ let request: any;
+ let options = {
+ headers: {
+ Authorization: this.token.get()
+ }
+ };
+
+ request = await this.makeGetRequest(request_url, options);
+
+ if(request.response) {
+ // Let's try with a refreshed token.
+ this.token.refresh()
+ options = {
+ headers: {
+ Authorization: this.token.getRefresh()
+ }
+ };
+ request = await this.makeGetRequest(request_url, options);
+ }
+
+ return request;
+ }
+
+ async get(path: string) {
+ const request_url = `${ this.url }${ path }`;
+ const response = await this.makeGetRequest(request_url);
return response;
}