diff --git a/.vscode/launch.json b/.vscode/launch.json
index 0345b3f..73ba4fa 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -9,7 +9,8 @@
"type": "chrome",
"request": "launch",
"url": "http://localhost:6969",
- "webRoot": "${workspaceRoot}/react-backend/client/src"
+ // "webRoot": "${workspaceRoot}/react-backend/client/src"
+ "port": 9223
},
{
"type": "node",
diff --git a/client/src/components/Accounts.jsx b/client/src/components/Accounts.jsx
index 7f3ba3b..0e74f62 100644
--- a/client/src/components/Accounts.jsx
+++ b/client/src/components/Accounts.jsx
@@ -1,10 +1,29 @@
-import React from "react";
+import React, { useState, useEffect } from "react";
import MTable from "./accountTable";
+import axios from "axios";
function Accounts() {
+ const readCookie = async () => {
+ try {
+ const res = await axios.get("/readCookie");
+
+ if (res.data === "No Cookie Set") {
+ document.location = "/"
+ // this.props.history.push('/accounts');
+ }
+ } catch (e) {
+ // setScreen("auth");
+ console.log(e);
+ }
+ };
+
+ useEffect(() => {
+ readCookie();
+ }, []);
+
return (
-
+
);
}
diff --git a/client/src/components/AddAccount.jsx b/client/src/components/AddAccount.jsx
index 511c526..063f388 100644
--- a/client/src/components/AddAccount.jsx
+++ b/client/src/components/AddAccount.jsx
@@ -42,6 +42,11 @@ class AddAccount extends Component {
.then((res) => {
console.log(res);
console.log(res.data);
+ if (res.data.includes('Added successfully')) {
+ document.location = "/accounts";
+ } else {
+ document.location = "/AddAccount";
+ }
});
};
diff --git a/client/src/components/Home.jsx b/client/src/components/Home.jsx
index aade38f..cf0ad3f 100644
--- a/client/src/components/Home.jsx
+++ b/client/src/components/Home.jsx
@@ -3,42 +3,17 @@ import ReactDOM from "react-dom";
import axios from "axios";
-function View(props) {
- const { screen, setScreen } = props;
-
- const [data, setData] = useState();
-
+function App() {
const deleteCookie = async () => {
try {
await axios.get("/readCookie/clear");
- setScreen("auth");
+
} catch (e) {
console.log(e);
}
};
- const getData = async () => {
- try {
- const res = await axios.get("/get-data");
- console.log(res.data);
- setData(res.data);
- } catch (e) {
- console.log(e);
- }
- };
-
- return (
-
-
{screen}
-
{data}
-
-
-
- );
-}
-
-function App() {
- const [username, setUsername] = useState();
+ const [username, setUsername] = useState();
const [password, setPassword] = useState();
const auth = async () => {
@@ -46,49 +21,28 @@ function App() {
const res = await axios.get("/login", {
auth: { username, password },
});
-
- if (res.data !== undefined) {
- // setScreen('/about');
+ if (res.data.auth === "Success") {
+ document.location = "/accounts";
}
} catch (e) {
console.log(e);
}
};
- const readCookie = async () => {
- try {
- const res = await axios.get("/readCookie");
-
- if (res.data !== "No Cookie Set") {
- // document.location = "/accounts"
- // this.props.history.push('/accounts');
- }
- } catch (e) {
- // setScreen("auth");
- console.log(e);
- }
- };
-
- useEffect(() => {
- readCookie();
- }, []);
-
return (
);
}
diff --git a/client/src/data.js b/client/src/data.js
deleted file mode 100644
index b327711..0000000
--- a/client/src/data.js
+++ /dev/null
@@ -1,44 +0,0 @@
-export const data = [
- {
- id: 1,
- title: 'The Hunger Games',
- authors: 'Suzanne Collins',
- num_pages: 374,
- rating: 4.33
- },
- {
- id: 2,
- title: 'Harry Potter and the Order of the Phoenix',
- authors: 'J.K. Rowling',
- num_pages: 870,
- rating: 4.48
- },
- {
- id: 3,
- title: 'To Kill a Mockingbird',
- authors: 'Harper Lee',
- num_pages: 324,
- rating: 4.27
- },
- {
- id: 4,
- title: 'Pride and Prejudice',
- authors: 'Jane Austen',
- num_pages: 279,
- rating: 4.25
- },
- {
- id: 5,
- title: 'Twilight',
- authors: 'Stephenie Meyer',
- num_pages: 498,
- rating: 3.58
- },
- {
- id: 6,
- title: 'The Book Thief',
- authors: 'Markus Zusak',
- num_pages: 552,
- rating: 4.36
- }
-];
\ No newline at end of file
diff --git a/routes/login.js b/routes/login.js
index 795964f..d8b0193 100644
--- a/routes/login.js
+++ b/routes/login.js
@@ -18,9 +18,9 @@ router.get('/', function (req, res, next) {
res.cookie('user', 3, options)
}
} catch (error) {
- res.render('index', { title: 'No Auth' });
+ res.send({ auth: 'Fail' });
}
- res.render('index', { title: 'Express' });
+ res.send({ auth: 'Success' });
});
module.exports = router;