Confirm user logout

This commit is contained in:
Tanner Collin 2020-01-21 23:45:54 +00:00
parent 72d502d0b7
commit f84171de83
2 changed files with 11 additions and 4 deletions

View File

@ -17,6 +17,7 @@ function App() {
const [token, setToken] = useState(localStorage.getItem('token', '')); const [token, setToken] = useState(localStorage.getItem('token', ''));
const [user, setUser] = useState(JSON.parse(localStorage.getItem('user', 'false'))); const [user, setUser] = useState(JSON.parse(localStorage.getItem('user', 'false')));
const [refreshCount, refreshUser] = useReducer(x => x + 1, 0); const [refreshCount, refreshUser] = useReducer(x => x + 1, 0);
const [yousure, setYousure] = useState(false);
function setTokenCache(x) { function setTokenCache(x) {
setToken(x); setToken(x);
@ -40,8 +41,13 @@ function App() {
}, [token, refreshCount]); }, [token, refreshCount]);
function logout() { function logout() {
if (yousure) {
setTokenCache(''); setTokenCache('');
setUserCache(false); setUserCache(false);
setYousure(false);
} else {
setYousure(true);
}
} }
return ( return (
@ -110,7 +116,7 @@ function App() {
{user && <Menu.Menu position='right'> {user && <Menu.Menu position='right'>
<Menu.Item <Menu.Item
content='Logout' content={yousure ? 'You Sure?' : 'Log Out'}
onClick={logout} onClick={logout}
icon='cancel' icon='cancel'
as={Link} as={Link}

View File

@ -14,7 +14,8 @@ export function LoginForm(props) {
const handleSubmit = (e) => { const handleSubmit = (e) => {
setLoading(true); setLoading(true);
requester('/rest-auth/login/', 'POST', '', input) const data = { ...input, username: input.username.toLowerCase() };
requester('/rest-auth/login/', 'POST', '', data)
.then(res => { .then(res => {
setError({}); setError({});
props.setTokenCache(res.key); props.setTokenCache(res.key);