Maintain token after browser refresh

This commit is contained in:
rui hildt 2020-08-22 00:08:42 +02:00
parent fba62d4955
commit 52e04006df
3 changed files with 16 additions and 4 deletions

View File

@ -18,7 +18,7 @@ const existingToken = localStorage.getItem('token');
// const existingUser = JSON.parse(localStorage.getItem('user'));
export default function App() {
const [authToken, setAuthToken] = useState(existingToken);
const [authToken, setAuthToken] = useState(existingToken || '');
const setToken = (data) => {
localStorage.setItem('token', JSON.stringify(data));

View File

@ -1,14 +1,23 @@
import React from 'react';
import { Panel } from 'rsuite';
import { useAuth } from '../helpers/authContext';
import NavBar from '../components/Navbar/NavBar';
const boxStyle = {
margin: '50px 10px',
};
export default function Dashboard() {
const { authToken } = useAuth();
return (
<Panel header={<h3>Dashboard</h3>} bordered style={boxStyle}>
<p>This is just experimenting with stuff.</p>
</Panel>
<>
<NavBar title='Meeting Planner' />
<Panel header={<h3>Dashboard</h3>} bordered style={boxStyle}>
<p>This is just experimenting with stuff.</p>
<p>{authToken}</p>
</Panel>
</>
);
}

View File

@ -1,6 +1,7 @@
import React from 'react';
import { Panel } from 'rsuite';
import { useAuth } from '../helpers/authContext';
import NavBar from '../components/Navbar/NavBar';
const boxStyle = {
@ -8,11 +9,13 @@ const boxStyle = {
};
export default function Home() {
const { authToken } = useAuth();
return (
<>
<NavBar title='Meeting Planner' />
<Panel header={<h3>Home</h3>} bordered style={boxStyle}>
<p>This will be the home page</p>
<p>{authToken}</p>
</Panel>
</>
);