Skip to content

Commit

Permalink
fix: force user to login only on account dependent page (#1045)
Browse files Browse the repository at this point in the history
* fix: redirect unlogged user from home to explore

* fix: prompt user to login on logged only pages

* fix: clear notifications cache on logout

---------

Co-authored-by: Less <[email protected]>
  • Loading branch information
wa0x6e and bonustrack authored Dec 11, 2024
1 parent 3b0eeab commit be5fb73
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions apps/ui/src/stores/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export const useNotificationsStore = defineStore('notifications', () => {
} else if (!followedSpacesIds.length && refreshNotificationInterval) {
clearInterval(refreshNotificationInterval);
refreshNotificationInterval = 0;
notifications.value = [];
}
},
{ immediate: true }
Expand Down
8 changes: 2 additions & 6 deletions apps/ui/src/views/My/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const PROPOSALS_LIMIT = 20;
useTitle('Home');
const metaStore = useMetaStore();
const { modalAccountWithoutDismissOpen } = useModal();
const router = useRouter();
const followedSpacesStore = useFollowedSpacesStore();
const { web3 } = useWeb3();
const { loadVotes } = useAccount();
Expand Down Expand Up @@ -113,15 +113,11 @@ watch(
[() => web3.value.account, () => web3.value.authLoading],
([account, authLoading]) => {
if (!account && !authLoading) {
modalAccountWithoutDismissOpen.value = true;
router.replace({ name: 'my-explore' });
}
},
{ immediate: true }
);
onUnmounted(() => {
modalAccountWithoutDismissOpen.value = false;
});
</script>

<template>
Expand Down
18 changes: 16 additions & 2 deletions apps/ui/src/views/My/Notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { _rt } from '@/helpers/utils';
const notificationsStore = useNotificationsStore();
const { modalAccountWithoutDismissOpen } = useModal();
const { web3 } = useWeb3();
const { setTitle } = useTitle();
watchEffect(async () => {
Expand All @@ -11,13 +13,25 @@ watchEffect(async () => {
});
watch(
() => notificationsStore.unreadNotificationsCount,
() => {
[
() => web3.value.account,
() => web3.value.authLoading,
() => notificationsStore.unreadNotificationsCount
],
([account, authLoading]) => {
if (!account && !authLoading) {
modalAccountWithoutDismissOpen.value = true;
}
notificationsStore.refreshLastUnreadTs();
},
{ immediate: true }
);
onUnmounted(() => {
modalAccountWithoutDismissOpen.value = false;
});
onUnmounted(() => notificationsStore.markAllAsRead());
</script>

Expand Down
17 changes: 16 additions & 1 deletion apps/ui/src/views/Settings.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<script setup lang="ts">
const { web3Account } = useWeb3();
const { web3, web3Account } = useWeb3();
const { modalAccountWithoutDismissOpen } = useModal();
watch(
[() => web3.value.account, () => web3.value.authLoading],
([account, authLoading]) => {
if (!account && !authLoading) {
modalAccountWithoutDismissOpen.value = true;
}
},
{ immediate: true }
);
onUnmounted(() => {
modalAccountWithoutDismissOpen.value = false;
});
</script>

<template>
Expand Down

0 comments on commit be5fb73

Please sign in to comment.