diff --git a/backend/main.py b/backend/main.py
index 3fc2c19..bc917b0 100644
--- a/backend/main.py
+++ b/backend/main.py
@@ -114,6 +114,16 @@ class CryptoRequest(BaseModel):
@app.middleware("http")
async def cookie_set(request: Request, call_next):
response = await call_next(request)
+ for idx, header in enumerate(response.raw_headers):
+ if header[0].decode("utf-8") == "set-cookie":
+ cookie = header[1].decode("utf-8")
+ cookie_arr = cookie.split('=')
+ if cookie_arr[0] == 'user_auth':
+ if cookie_arr[1].split(';')[0] == '""':
+ response.set_cookie("isLoggedIn", False, secure=True)
+ else:
+ response.set_cookie("isLoggedIn", True, secure=True)
+ break
for idx, header in enumerate(response.raw_headers):
if header[0].decode("utf-8") == "set-cookie":
cookie = header[1].decode("utf-8")
diff --git a/frontend/cryptoviz/package.json b/frontend/cryptoviz/package.json
index 5eccf84..6d0bae1 100644
--- a/frontend/cryptoviz/package.json
+++ b/frontend/cryptoviz/package.json
@@ -7,6 +7,7 @@
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"bootswatch": "^4.4.1",
+ "js-cookie": "^2.2.1",
"react": "^16.13.0",
"react-autosuggest": "^10.0.0",
"react-bootstrap": "^1.0.0",
diff --git a/frontend/cryptoviz/src/js/components/AdvancedCharts.js b/frontend/cryptoviz/src/js/components/AdvancedCharts.js
index 6b11586..aa65939 100644
--- a/frontend/cryptoviz/src/js/components/AdvancedCharts.js
+++ b/frontend/cryptoviz/src/js/components/AdvancedCharts.js
@@ -1,13 +1,22 @@
import React from "react";
import Navbar from "./Navbar";
import { TVChartContainer } from "../../components/TVChartContainer/index";
+import Loader from "react-loader-spinner";
+import Cookie from 'js-cookie';
function AdvancedLandingPage({ match }) {
return (
-
-
-
-
+ <>
+ {(Cookie.get('isLoggedIn') && Cookie.get('isLoggedIn').toLocaleLowerCase() === 'true' && authState.isAuthenticated) ||
+ ((!Cookie.get('isLoggedIn') || Cookie.get('isLoggedIn').toLocaleLowerCase() === 'false') && !authState.isAuthenticated) ?
+
+
+
+
:
+
+
+
}
+ >
);
}
diff --git a/frontend/cryptoviz/src/js/components/App.js b/frontend/cryptoviz/src/js/components/App.js
index e1b10df..3c57036 100644
--- a/frontend/cryptoviz/src/js/components/App.js
+++ b/frontend/cryptoviz/src/js/components/App.js
@@ -13,17 +13,16 @@ import { useInterval } from "../common";
import { getCurrUser } from "../api";
import { reducer } from "../reducer";
import "../../style/App.css";
+import Cookie from 'js-cookie';
import {
GET_USER_SUCCESS,
GET_USER_FAILURE,
- ERROR_CLOSE,
- APPLICATION_MOUNTED,
+ ERROR_CLOSE
} from "../constants/auth";
import AdvancedLandingPage from "./AdvancedCharts";
export const AuthContext = createContext();
const initialState = {
- applicationMounted: false,
isAuthenticated: false,
user: {},
error: "",
@@ -34,17 +33,14 @@ function App() {
useEffect(() => {
getUserInfo();
- dispatch({
- type: APPLICATION_MOUNTED,
- });
}, []);
useInterval(() => {
getUserInfo();
- }, 500);
+ }, 1000);
const getUserInfo = () => {
- if (!state.applicationMounted || state.isAuthenticated) {
+ if (Cookie.get('isLoggedIn') && Cookie.get('isLoggedIn').toLocaleLowerCase() === 'true') {
getCurrUser()
.then((res) => {
dispatch({
diff --git a/frontend/cryptoviz/src/js/components/Credits.js b/frontend/cryptoviz/src/js/components/Credits.js
index d4299bc..834cd3c 100644
--- a/frontend/cryptoviz/src/js/components/Credits.js
+++ b/frontend/cryptoviz/src/js/components/Credits.js
@@ -3,6 +3,7 @@ import "../../style/main.css";
import Navbar from "./Navbar";
import { AuthContext } from "./App";
import Loader from "react-loader-spinner";
+import Cookie from 'js-cookie';
function Credits() {
@@ -10,7 +11,8 @@ function Credits() {
return (
- {authState.applicationMounted && ((authState.isAuthenticated && Object.keys(authState.user).length > 0) || (!authState.isAuthenticated && Object.keys(authState.user).length === 0)) ?
+ {(Cookie.get('isLoggedIn') && Cookie.get('isLoggedIn').toLocaleLowerCase() === 'true' && authState.isAuthenticated) ||
+ ((!Cookie.get('isLoggedIn') || Cookie.get('isLoggedIn').toLocaleLowerCase() === 'false') && !authState.isAuthenticated) ?
diff --git a/frontend/cryptoviz/src/js/components/CryptoLanding.js b/frontend/cryptoviz/src/js/components/CryptoLanding.js
index 87e3277..7535404 100644
--- a/frontend/cryptoviz/src/js/components/CryptoLanding.js
+++ b/frontend/cryptoviz/src/js/components/CryptoLanding.js
@@ -18,6 +18,7 @@ import { useHistory } from "react-router-dom";
import Loader from "react-loader-spinner";
import { AuthContext } from "./App";
import { updateUser } from "../api";
+import Cookie from 'js-cookie';
import { UPDATE_USER_SUCCESS, UPDATE_USER_FAILURE } from "../constants/auth";
const d = new Date();
@@ -143,7 +144,7 @@ function CryptoLanding({ match }) {
};
const displayWatchList = () => {
- if (Object.keys(authState.user).length > 0) {
+ if (authState.isAuthenticated) {
if (
authState.user.watchlist.includes(
match.params.ticker.replace("USDT", "")
@@ -202,9 +203,8 @@ function CryptoLanding({ match }) {
return (
- {authState.applicationMounted &&
- ((authState.isAuthenticated && Object.keys(authState.user).length > 0) ||
- (!authState.isAuthenticated && Object.keys(authState.user).length === 0)) ? (
+ {(Cookie.get('isLoggedIn') && Cookie.get('isLoggedIn').toLocaleLowerCase() === 'true' && authState.isAuthenticated) ||
+ ((!Cookie.get('isLoggedIn') || Cookie.get('isLoggedIn').toLocaleLowerCase() === 'false') && !authState.isAuthenticated) ? (
diff --git a/frontend/cryptoviz/src/js/components/Home.js b/frontend/cryptoviz/src/js/components/Home.js
index c38cd4f..d0a0b9f 100644
--- a/frontend/cryptoviz/src/js/components/Home.js
+++ b/frontend/cryptoviz/src/js/components/Home.js
@@ -4,6 +4,7 @@ import Table from './Table';
import Navbar from "./Navbar";
import { AuthContext } from "./App";
import Loader from "react-loader-spinner";
+import Cookie from 'js-cookie';
function Home() {
@@ -11,7 +12,8 @@ function Home() {
return (
- {authState.applicationMounted && ((authState.isAuthenticated && Object.keys(authState.user).length > 0) || (!authState.isAuthenticated && Object.keys(authState.user).length === 0)) ?
+ {(Cookie.get('isLoggedIn') && Cookie.get('isLoggedIn').toLocaleLowerCase() === 'true' && authState.isAuthenticated) ||
+ ((!Cookie.get('isLoggedIn') || Cookie.get('isLoggedIn').toLocaleLowerCase() === 'false') && !authState.isAuthenticated) ?
diff --git a/frontend/cryptoviz/src/js/components/InvalidPage.js b/frontend/cryptoviz/src/js/components/InvalidPage.js
index 30788d2..bac7302 100644
--- a/frontend/cryptoviz/src/js/components/InvalidPage.js
+++ b/frontend/cryptoviz/src/js/components/InvalidPage.js
@@ -3,6 +3,7 @@ import React, { useContext } from "react";
import Navbar from "./Navbar";
import { AuthContext } from "./App";
import Loader from "react-loader-spinner";
+import Cookie from 'js-cookie';
function InvalidPage() {
@@ -10,7 +11,8 @@ function InvalidPage() {
return (
- {authState.applicationMounted && ((authState.isAuthenticated && Object.keys(authState.user).length > 0) || (!authState.isAuthenticated && Object.keys(authState.user).length === 0)) ?
+ {(Cookie.get('isLoggedIn') && Cookie.get('isLoggedIn').toLocaleLowerCase() === 'true' && authState.isAuthenticated) ||
+ ((!Cookie.get('isLoggedIn') || Cookie.get('isLoggedIn').toLocaleLowerCase() === 'false') && !authState.isAuthenticated) ?
diff --git a/frontend/cryptoviz/src/js/components/SignIn.js b/frontend/cryptoviz/src/js/components/SignIn.js
index 5cd2322..66db4ca 100644
--- a/frontend/cryptoviz/src/js/components/SignIn.js
+++ b/frontend/cryptoviz/src/js/components/SignIn.js
@@ -7,6 +7,7 @@ import Navbar from "./Navbar";
import { login } from '../api';
import { AuthContext } from "./App";
import Loader from "react-loader-spinner";
+import Cookie from 'js-cookie';
function SignIn() {
@@ -24,7 +25,7 @@ function SignIn() {
}, 500);
const checkSignedIn = () => {
- if(authState.applicationMounted && authState.isAuthenticated) {
+ if(Cookie.get('isLoggedIn') && Cookie.get('isLoggedIn').toLocaleLowerCase() === 'true') {
history.push('/');
}
};
@@ -49,7 +50,7 @@ function SignIn() {
return (
- {authState.applicationMounted && !authState.isAuthenticated && Object.keys(authState.user).length === 0 ?
+ {((!Cookie.get('isLoggedIn') || Cookie.get('isLoggedIn').toLocaleLowerCase() === 'false') && !authState.isAuthenticated) ?