Skip to content

Commit

Permalink
feat(project): implement logout
Browse files Browse the repository at this point in the history
  • Loading branch information
royschut committed Aug 2, 2021
1 parent d671de8 commit 2e920eb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/screens/User/User.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { Redirect, Route, Switch, useHistory } from 'react-router-dom';
import { Redirect, Route, Switch, useHistory, useLocation } from 'react-router-dom';
import type { PlaylistItem } from 'types/playlist';
import { useTranslation } from 'react-i18next';

Expand All @@ -19,13 +19,14 @@ import Favorite from '../../icons/Favorite';
import BalanceWallet from '../../icons/BalanceWallet';
import Exit from '../../icons/Exit';
import { useFavorites } from '../../stores/FavoritesStore';
import { AccountStore } from '../../stores/AccountStore';
import { AccountStore, logout } from '../../stores/AccountStore';
import { addQueryParam } from '../../utils/history';

import styles from './User.module.scss';

const User = (): JSX.Element => {
const history = useHistory();
const location = useLocation();
const { t } = useTranslation('user');
const breakpoint = useBreakpoint();
const isLargeScreen = breakpoint >= Breakpoint.md;
Expand All @@ -51,6 +52,13 @@ const User = (): JSX.Element => {

useEffect(() => updateBlurImage(''), [updateBlurImage]);

useEffect(() => {
if (location.pathname === '/u/logout') {
logout();
history.push('/');
}
}, [location, history]);

if (!customer) {
return <div className={styles.user}>Please login first</div>;
}
Expand Down

0 comments on commit 2e920eb

Please sign in to comment.