From 0bc8af19803d0e7fee6da9348e62fe77b8459267 Mon Sep 17 00:00:00 2001 From: Aarni Halinen Date: Fri, 24 Jul 2020 23:13:19 +0300 Subject: [PATCH] Authentication params for form GET calls --- src/models/SignupForm.ts | 14 ++++++++++---- src/pages/admin/AdminSignupPage.tsx | 2 +- src/pages/admin/EventCreatePage.tsx | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/models/SignupForm.ts b/src/models/SignupForm.ts index 4106731..b2e038b 100644 --- a/src/models/SignupForm.ts +++ b/src/models/SignupForm.ts @@ -20,9 +20,12 @@ export interface SignupForm { }; } -export async function getForms(): Promise { +export async function getForms(auth = false): Promise { try { - const resp = await axios.get(url); + const headers = auth ? { "Authorization": getAuthHeader() } : null; + const resp = await axios.get(url, { + headers + }); const { results } = resp.data; return results; } catch (err) { @@ -31,9 +34,12 @@ export async function getForms(): Promise { } } -export async function getForm(id: number): Promise { +export async function getForm(id: number, auth = false): Promise { try { - const resp = await axios.get(`${url}${id}/`); + const headers = auth ? { "Authorization": getAuthHeader() } : null; + const resp = await axios.get(`${url}${id}/`, { + headers + }); return resp.data; } catch (err) { console.error(err); diff --git a/src/pages/admin/AdminSignupPage.tsx b/src/pages/admin/AdminSignupPage.tsx index b6846f9..8fca13d 100644 --- a/src/pages/admin/AdminSignupPage.tsx +++ b/src/pages/admin/AdminSignupPage.tsx @@ -47,7 +47,7 @@ class AdminSignupPage extends React.Component { - const getSignupFormsPromise = getForms(); + const getSignupFormsPromise = getForms(true); try { const signupForms = await getSignupFormsPromise; this.setState({ diff --git a/src/pages/admin/EventCreatePage.tsx b/src/pages/admin/EventCreatePage.tsx index 9e30882..5be772d 100644 --- a/src/pages/admin/EventCreatePage.tsx +++ b/src/pages/admin/EventCreatePage.tsx @@ -84,7 +84,7 @@ class EventCreatePage extends React.Component { try { - const signupForm = await getForms(); + const signupForm = await getForms(true); this.setState({ signupForm })