chore: fix lint issues
This commit is contained in:
@@ -10,18 +10,25 @@ function getToken(): string {
|
||||
return tokenState ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all the headers for the app.
|
||||
*
|
||||
* @returns {Headers} the headers.
|
||||
*/
|
||||
function getHeaders(): Headers {
|
||||
const csrfToken = document.cookie.split('; ').find(row => row.startsWith('XSRF-TOKEN='))?.split('=')[1];
|
||||
const csrfToken = document.cookie.split('; ').find((row: string) => row.startsWith('XSRF-TOKEN='))?.split('=')[1];
|
||||
|
||||
return new Headers({
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${getToken()}`,
|
||||
Authorization: `Bearer ${getToken()}`,
|
||||
'X-XSRF-TOKEN': csrfToken || ''
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle errors for the AJAX HTTPS requests.
|
||||
*
|
||||
* @param {number} httpStatusCode The HTTP response status code.
|
||||
*/
|
||||
function handleError(httpStatusCode: number) {
|
||||
if (httpStatusCode === 400) {
|
||||
@@ -92,7 +99,7 @@ const api = {
|
||||
method: 'DELETE',
|
||||
mode: 'cors',
|
||||
credentials: 'include',
|
||||
headers: getHeaders(),
|
||||
headers: getHeaders()
|
||||
});
|
||||
if (response.status === 204) {
|
||||
return true;
|
||||
|
||||
@@ -2,10 +2,10 @@ import React, { useContext } from 'react';
|
||||
import {
|
||||
Button, Col, Container, Row
|
||||
} from 'react-bootstrap';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { env } from '../../env';
|
||||
import AuthContext from '../../context/AuthContext';
|
||||
import './style.css';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
/**
|
||||
* Footer component.
|
||||
|
||||
@@ -16,7 +16,6 @@ function Task(): JSX.Element {
|
||||
const [formInvalid, setFormInvalid] = useState<boolean>(false);
|
||||
const [errorMessage, setErrorMessage] = useState<string>('');
|
||||
const [tasks, setTasks] = useState<TaskResponse[]>([]);
|
||||
const [csrfToken, setCsrfToken] = useState<string>('');
|
||||
|
||||
const handleError = (e: unknown): void => {
|
||||
if (typeof e === 'string') {
|
||||
@@ -37,18 +36,6 @@ function Task(): JSX.Element {
|
||||
}
|
||||
};
|
||||
|
||||
const getCsrfToken = async (): Promise<void> => {
|
||||
try {
|
||||
const response = await api.getJSON(ApiConfig.csrfTokenUrl);
|
||||
console.log('response token obj', response);
|
||||
console.log('response token value', response.token);
|
||||
console.log('response date', new Date());
|
||||
setCsrfToken(response.token);
|
||||
} catch (e) {
|
||||
handleError(e)
|
||||
}
|
||||
};
|
||||
|
||||
const addTask = async (desc: string, url?: string): Promise<boolean> => {
|
||||
const payload: TaskNoteRequest = {
|
||||
description: desc,
|
||||
|
||||
Reference in New Issue
Block a user