Untitled
unknown
tsx
2 years ago
1.4 kB
10
Indexable
import { useEffect, useState } from "react";
import { Navigate } from "react-router-dom";
import Cookies from 'universal-cookie';
import jwt_decode from "jwt-decode";
const Dashboard = () => {
const cookies = new Cookies();
const [cookieExist] = useState(cookies.get('NOTEAPI_USER'));
const [note, setNote] = useState(null);
const token = cookies.get("NOTEAPI_USER");
const { id }: any = jwt_decode(token); // Decoding token
const notes: any = async () => {
// getNotes endpoint
const result = await fetch('http://localhost:5000/note', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({ userid: id })
});
setNote(await result.json());
}
useEffect(() => {
notes()
}, []);
console.log(note)
if (!cookieExist) {
return <Navigate replace to="/login" />;
} else {
return (
<div>
{/* {note.length > 0 && (
<ul>
{note.map(n => (
<li key={n.id}>{n.name}</li>
))}
</ul>
)} */}
</div>
);
}
};
export default Dashboard;Editor is loading...