summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/form_utils.ts15
-rw-r--r--src/lib/session.ts4
-rw-r--r--src/lib/token.ts4
3 files changed, 19 insertions, 4 deletions
diff --git a/src/lib/form_utils.ts b/src/lib/form_utils.ts
index 43fe0fa..c7abb1e 100644
--- a/src/lib/form_utils.ts
+++ b/src/lib/form_utils.ts
@@ -6,6 +6,21 @@ export interface FormError {
message: string;
}
+export function deleteEmptyParams(params: URLSearchParams) {
+ const to_delete = [];
+ const trimmed_params = params;
+
+ for(const [key, value] of params.entries()) {
+ if(value == '')
+ to_delete.push(key);
+ }
+
+ for(const key of to_delete)
+ trimmed_params.delete(key);
+
+ return trimmed_params;
+}
+
export function deleteEmptyFields(form: FormData) {
const trimmed_form = new FormData();
diff --git a/src/lib/session.ts b/src/lib/session.ts
index 28284ed..e3d4784 100644
--- a/src/lib/session.ts
+++ b/src/lib/session.ts
@@ -6,9 +6,9 @@ export function isUserAuthenticated() {
return session.get() != null && !session.expired();
}
-export function refreshIfExpired() {
+export async function refreshIfExpired() {
if(!isUserAuthenticated())
- return session.refresh();
+ return await session.refresh();
return true;
}
diff --git a/src/lib/token.ts b/src/lib/token.ts
index 68765d7..a92d242 100644
--- a/src/lib/token.ts
+++ b/src/lib/token.ts
@@ -27,7 +27,7 @@ export default class Token {
sessionStorage.removeItem("refresh");
}
- refresh() {
+ async refresh() {
const options = {
headers: {
Authorization: `Bearer ${this.getRefresh()}`
@@ -35,7 +35,7 @@ export default class Token {
}
try {
- const response = axios.post('/refresh_tokens', null, options);
+ const response = await axios.post('http://localhost:3000/api/refresh_tokens', null, options);
this.setRefresh(response.data.refresh);
this.set(response.data.token);