Authentication params for form GET calls

This commit is contained in:
Aarni Halinen
2020-07-24 23:13:19 +03:00
parent 140314cd89
commit 0bc8af1980
3 changed files with 12 additions and 6 deletions
+10 -4
View File
@@ -20,9 +20,12 @@ export interface SignupForm {
};
}
export async function getForms(): Promise<SignupForm[]> {
export async function getForms(auth = false): Promise<SignupForm[]> {
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<SignupForm[]> {
}
}
export async function getForm(id: number): Promise<SignupForm> {
export async function getForm(id: number, auth = false): Promise<SignupForm> {
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);
+1 -1
View File
@@ -47,7 +47,7 @@ class AdminSignupPage extends React.Component<AdminSignupPageProps, AdminSignupP
}
fetchSignupForms = async () => {
const getSignupFormsPromise = getForms();
const getSignupFormsPromise = getForms(true);
try {
const signupForms = await getSignupFormsPromise;
this.setState({
+1 -1
View File
@@ -84,7 +84,7 @@ class EventCreatePage extends React.Component<EventCreatePageProps, EventCreateP
fetchSignupForms = async () => {
try {
const signupForm = await getForms();
const signupForm = await getForms(true);
this.setState({
signupForm
})