summaryrefslogtreecommitdiff
path: root/src/clients/api_client.ts
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-05-11 19:28:47 -0600
committerHombreLaser <sebastian-440@live.com>2023-05-11 19:28:47 -0600
commit385606ee05a8ceb9073169639eb1a311f81cac10 (patch)
treeac8af50a15ce3e834009afef773988213c961cdb /src/clients/api_client.ts
parentab540055c99074c1c67fd65b45d0afb785ca5a0b (diff)
Añade información a la vista de usuario
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;
}