Confirm user logout
This commit is contained in:
parent
72d502d0b7
commit
f84171de83
|
@ -17,6 +17,7 @@ function App() {
|
|||
const [token, setToken] = useState(localStorage.getItem('token', ''));
|
||||
const [user, setUser] = useState(JSON.parse(localStorage.getItem('user', 'false')));
|
||||
const [refreshCount, refreshUser] = useReducer(x => x + 1, 0);
|
||||
const [yousure, setYousure] = useState(false);
|
||||
|
||||
function setTokenCache(x) {
|
||||
setToken(x);
|
||||
|
@ -40,8 +41,13 @@ function App() {
|
|||
}, [token, refreshCount]);
|
||||
|
||||
function logout() {
|
||||
if (yousure) {
|
||||
setTokenCache('');
|
||||
setUserCache(false);
|
||||
setYousure(false);
|
||||
} else {
|
||||
setYousure(true);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -110,7 +116,7 @@ function App() {
|
|||
|
||||
{user && <Menu.Menu position='right'>
|
||||
<Menu.Item
|
||||
content='Logout'
|
||||
content={yousure ? 'You Sure?' : 'Log Out'}
|
||||
onClick={logout}
|
||||
icon='cancel'
|
||||
as={Link}
|
||||
|
|
|
@ -14,7 +14,8 @@ export function LoginForm(props) {
|
|||
|
||||
const handleSubmit = (e) => {
|
||||
setLoading(true);
|
||||
requester('/rest-auth/login/', 'POST', '', input)
|
||||
const data = { ...input, username: input.username.toLowerCase() };
|
||||
requester('/rest-auth/login/', 'POST', '', data)
|
||||
.then(res => {
|
||||
setError({});
|
||||
props.setTokenCache(res.key);
|
||||
|
|
Loading…
Reference in New Issue
Block a user