diff options
Diffstat (limited to 'src/index.tsx')
-rw-r--r-- | src/index.tsx | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/index.tsx b/src/index.tsx index 9139e4b..49c177b 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -55,7 +55,7 @@ const App: React.FC = () => { } }; - const logIn = (username: string, password: string): Promise<boolean> => { + const logIn = (username: string, password: string, remember = true): Promise<boolean> => { return post('/authentication', { strategy: 'local', username, @@ -64,9 +64,10 @@ const App: React.FC = () => { const me = response.data.user; const token = response.data.accessToken; setUser(me); + navigate('profile', me._id); localStorage.setItem('userId', me._id); localStorage.setItem('token', token); - navigate('profile', me._id); + if (!remember) localStorage.setItem('shouldClear', 'true'); return true; }).catch(() => false); }; @@ -79,6 +80,9 @@ const App: React.FC = () => { }; useEffect(() => { + if (localStorage.getItem('shouldClear')) { + localStorage.clear(); + } const userId = localStorage.getItem('userId'); if (userId) { get(`/users/${userId}`).then(response => { |