Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove token feature #35

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading