From a6555ff346b8834a23c10928c7e9cb63891dd48a Mon Sep 17 00:00:00 2001 From: ekzyis Date: Thu, 12 Sep 2024 19:18:03 +0200 Subject: [PATCH] Always reload page on switch --- components/account.js | 52 ++----------------------------------------- 1 file changed, 2 insertions(+), 50 deletions(-) diff --git a/components/account.js b/components/account.js index 9ece68141c..edd03b39a9 100644 --- a/components/account.js +++ b/components/account.js @@ -113,56 +113,8 @@ const AccountListRow = ({ account, ...props }) => { setMeAnon(account.id === USER_ID.anon) } - // account changes on some pages require a hard reload - // 1) anons don't have access to some pages - // ( search for 'authRequired: true' to find all such pages ) - const privatePages = ['/notifications', '/territory', '/items/[id]/edit', '/referrals', '/satistics', '/settings', '/wallet', '/~/edit'] - if (anonRow && privatePages.some(p => router.pathname.startsWith(p))) { - router.reload() - return - } - - const authPages = ['/signup', '/login'] - // 2) if we're on /signup or /login, reload so we get redirected to the callback url - if (!anonRow && authPages.some(p => router.pathname.startsWith(p))) { - router.reload() - return - } - - // 3) not everyone has access to every item - if (router.asPath.startsWith('/items')) { - const itemId = router.asPath.split('/')[2] - // check if we have access to the item - const { item } = client.cache.readQuery({ - query: ITEM_FULL, - variables: { id: itemId } - }) - - const isMine = item.userId === account.id - const isPrivate = item.invoice && item.invoice.actionState !== 'PAID' - - if (!isMine && isPrivate) { - router.reload() - return - } - } - - await client.refetchQueries({ - include: 'active', - onQueryUpdated: async (query) => { - try { - return await query.refetch() - } catch (err) { - const code = err.graphQLErrors?.[0]?.extensions?.code - if ([E_FORBIDDEN, E_UNAUTHENTICATED, E_BAD_INPUT].includes(code)) { - return - } - - // never throw but log unexpected errors - console.error(err) - } - } - }) + // reload whatever page we're on to avoid any bugs due to missing authorization etc. + router.reload() } return (