diff options
-rw-r--r-- | src/index.tsx | 14 |
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 => { |