aboutsummaryrefslogtreecommitdiff
path: root/src/index.tsx
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-06-25 21:56:33 +0300
committereug-vs <eug-vs@keemail.me>2020-06-25 21:56:33 +0300
commit2c6946b35aa2a756230bb96e69302c08fd8068ee (patch)
tree2ba034a7460a1933aa8845330658b3ca777a51ee /src/index.tsx
parentcc91abb0ca403b7d7180b0e24fe126bd35ce20ab (diff)
downloadwhich-ui-2c6946b35aa2a756230bb96e69302c08fd8068ee.tar.gz
fix: clear storage correctly
Diffstat (limited to 'src/index.tsx')
-rw-r--r--src/index.tsx14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/index.tsx b/src/index.tsx
index 2747bfa..a321cf4 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -55,7 +55,7 @@ const App: React.FC = () => {
}
};
- const logIn = (username: string, password: string, remember?: boolean): Promise<boolean> => {
+ const logIn = (username: string, password: string, remember = true): Promise<boolean> => {
return post('/authentication', {
strategy: 'local',
username,
@@ -65,22 +65,22 @@ const App: React.FC = () => {
const token = response.data.accessToken;
setUser(me);
navigate('profile', me._id);
- if (remember) {
- localStorage.setItem('userId', me._id);
- localStorage.setItem('token', token);
- }
+ localStorage.setItem('userId', me._id);
+ localStorage.setItem('token', token);
+ if (!remember) localStorage.setItem('shouldClear', 'true');
return true;
}).catch(() => false);
};
- const logOut = () => {
+ const logOut = (redirect = true) => {
setUser(undefined);
localStorage.removeItem('userId');
localStorage.removeItem('token');
- navigate('auth');
+ if (redirect) navigate('auth');
};
useEffect(() => {
+ if (localStorage.getItem('shouldClear')) logOut(false);
const userId = localStorage.getItem('userId');
if (userId) {
get(`/users/${userId}`).then(response => {