forked from aec-coding-club/AEC-Coding-Club-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dashboard-Secure.jsx
58 lines (52 loc) · 1.55 KB
/
Dashboard-Secure.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import axios from "axios";
import { Api } from "../backend";
import DashboadComponent from "./Components/User-Secure-Route/Dashboad";
import "./styles/Home.css";
import Base from "../Base";
const Home = ({ tokenChecker }) => {
const [auth, setAuth] = useState(false);
const [successDecision, setSuccessDecision] = useState(false);
const [userdata, setUserdata] = useState({});
let navigate = useNavigate();
async function fetchdata() {
const authToken = localStorage.getItem("token");
const parseddata = await axios.get(`${Api}dashboard`, {
withCredentials: true,
headers: { Authorization: `Bearer ${authToken}` },
});
if (!parseddata.data.token) {
//// console.log("Navigating1");
navigate("/");
}
//// console.log(Api);
//// console.log("Parsed data :- ", parseddata);
setUserdata({
userInfo: parseddata.data.user_data,
});
setAuth(parseddata.data.token);
setSuccessDecision(parseddata.data.success);
if (!parseddata.data.success) {
//// console.log("Navigating2");
navigate("/verify");
}
}
useEffect(() => {
fetchdata();
//// console.log("Token" , auth);
//// console.log("Success", successDecision);
}, []);
return (
<>
<Base>
{auth && successDecision ? (
<DashboadComponent details={userdata} tokenChecker={tokenChecker} />
) : (
<h1></h1>
)}
</Base>
</>
);
};
export default Home;