Maintain token after browser refresh
This commit is contained in:
parent
fba62d4955
commit
52e04006df
@ -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));
|
||||
|
@ -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>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
@ -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>
|
||||
</>
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user