- {state.stocks.map((stock) => {
+ {[].map((stock) => {
return (
Stock: {stock.ticker}
diff --git a/frontend/src/components/Profile.js b/frontend/src/components/Profile.js
index c497cee..8746721 100644
--- a/frontend/src/components/Profile.js
+++ b/frontend/src/components/Profile.js
@@ -2,18 +2,6 @@ import React, { useState, useEffect } from "react";
import "./assets/Portfolio.css";
const Profile = (props) => {
- const [state, setState] = useState({});
- useEffect(() => {
- callAPI();
- });
-
- const callAPI = () => {
- fetch("http://localhost:9000/FETCHURL")
- .then((res) => res.text())
- .then((res) => setState(res))
- .catch((err) => err);
- };
-
return (
Profile
diff --git a/frontend/src/components/ProtectedRoute.js b/frontend/src/components/ProtectedRoute.js
index d348fa0..366e9de 100644
--- a/frontend/src/components/ProtectedRoute.js
+++ b/frontend/src/components/ProtectedRoute.js
@@ -6,19 +6,52 @@ const ProtectedRoute = ({ component: Component, ...rest }) => {
try {
const requestOptions = {
method: "GET",
- headers: { Authorization: `JWT ${localStorage.getItem("token")}` },
+ headers: { Authorization: `Bearer ${localStorage.getItem("token")}` },
};
const response = await fetch(
`${process.env.REACT_APP_API_ENDPOINT}/profile`,
requestOptions
);
+ console.log(`Checking status! ${response.status}`);
if (response.status === 200) {
return true;
} else {
+ const requestOptions = {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: { refresh: localStorage.getItem("refresh") },
+ };
+ const response = await fetch(
+ `${process.env.REACT_APP_API_ENDPOINT}/token/refresh/`,
+ requestOptions
+ );
+
+ const data = response.json();
+
+ localStorage.setItem("token", data.access);
+
return false;
}
} catch (e) {
+ const requestOptions = {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: { refresh: localStorage.getItem("refresh") },
+ };
+ const response = await fetch(
+ `${process.env.REACT_APP_API_ENDPOINT}/token/refresh/`,
+ requestOptions
+ );
+
+ const data = response.json();
+
+ localStorage.setItem("token", data.access);
+
return false;
}
};
@@ -33,7 +66,7 @@ const ProtectedRoute = ({ component: Component, ...rest }) => {
return (
{
};
try {
const response = await fetch(
- `${process.env.REACT_APP_API_ENDPOINT}/token`,
+ `${process.env.REACT_APP_API_ENDPOINT}/token/`,
requestOptions
);
const data = await response.json();
- localStorage.setItem("token", data.token);
+ localStorage.setItem("token", data.access);
+ localStorage.setItem("refresh", data.refresh);
history.push("/");
} catch (e) {
console.error(e);