Skip to content

Commit

Permalink
Remove token feature
Browse files Browse the repository at this point in the history
Remove token feature and allow the browser to do basic auth
  • Loading branch information
callumforrester committed Jun 5, 2024
1 parent a158147 commit 654068b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 38 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
43 changes: 5 additions & 38 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ThemeProvider } from "@emotion/react";
import { useEffect, useState, useReducer, useMemo, useRef } from "react";
import { useEffect, useState, useReducer, useMemo } from "react";
import Log_Menu from "./components/Log_Menu.tsx";
import { theme } from "./theme";
import BoxBasic from "./components/Box";
Expand Down Expand Up @@ -27,9 +27,7 @@ import { log_levels } from "./schema/Log_Levels.ts";

function App() {
// Initialize information for Queries and Auth
const username = useRef("");
const apiURL = "/api/views/search/sync";
const password = "token";
const query: QueryString = {};

// Hard-code Actions for Reducer Function
Expand Down Expand Up @@ -97,21 +95,10 @@ function App() {

useEffect(() => {
// POSTS API Call at Stores Response For Front-End
async function fetchData(
url: string,
username: string,

password: string,
payload: object,
): Promise<undefined> {
async function fetchData(url: string, payload: object): Promise<undefined> {
try {
// Creating a basic authentication header
const headers = new Headers();
headers.append(
"Authorization",
"Basic " + btoa(`${username}:${password}`),
);
// Adding required headers for API Call
const headers = new Headers();
headers.append("Content-Type", "application/json");
headers.append("X-Requested-By", "XMLHttpRequest");

Expand Down Expand Up @@ -139,19 +126,9 @@ function App() {
// Calls file for auth and calls POST API call
(async () => {
try {
await readFile().then(content => {
username.current = content;
// Run API call using parameters
(async () => {
try {
await fetchData(apiURL, username.current, password, payload);
} catch (error) {
console.error("Error:", error);
}
})();
});
await fetchData(apiURL, payload);
} catch (error) {
console.error("Error collecting password:", error);
console.error("Error:", error);
}
})();
}, [logPayload, EmptyLogRecord]);
Expand Down Expand Up @@ -277,16 +254,6 @@ function getMessage(logging: JSON): LogRecord | undefined {
};
}

// Function to call API token for authentication (kept locally and to be replaced)
async function readFile(): Promise<string> {
const filePath = "src/token.txt";
const response = await fetch(filePath);
if (!response.ok) {
throw new Error(`Failed to read file: ${filePath}`);
}
return await response.text();
}

// Select colour of log row based off log level
const getColor = (level: number) => {
// yellow = #d1a317
Expand Down

0 comments on commit 654068b

Please sign in to comment.