Skip to content

Commit

Permalink
feat(user): redirect to home when user is not logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristiaanScheermeijer committed Aug 2, 2021
1 parent d671de8 commit eb35cc3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/screens/User/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Exit from '../../icons/Exit';
import { useFavorites } from '../../stores/FavoritesStore';
import { AccountStore } from '../../stores/AccountStore';
import { addQueryParam } from '../../utils/history';
import LoadingOverlay from '../../components/LoadingOverlay/LoadingOverlay';

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

Expand All @@ -29,7 +30,7 @@ const User = (): JSX.Element => {
const { t } = useTranslation('user');
const breakpoint = useBreakpoint();
const isLargeScreen = breakpoint >= Breakpoint.md;
const { user: customer, subscription } = AccountStore.useState((state) => state);
const { user: customer, subscription, loading } = AccountStore.useState((state) => state);

const updateBlurImage = useBlurImageUpdater();
const { clearList: clearFavorites } = useFavorites();
Expand All @@ -51,8 +52,14 @@ const User = (): JSX.Element => {

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

useEffect(() => {
if (!loading && !customer) {
history.replace('/');
}
}, [history, customer, loading]);

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

return (
Expand Down

0 comments on commit eb35cc3

Please sign in to comment.