From 880e456f9443d96d4a103b65a9232e3f0374a6ff Mon Sep 17 00:00:00 2001 From: DIYgod Date: Mon, 6 Feb 2023 18:15:28 +0000 Subject: [PATCH] fix: user role initial --- src/hooks/useUserRole.ts | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/hooks/useUserRole.ts b/src/hooks/useUserRole.ts index 88fea1c7..ce917f89 100644 --- a/src/hooks/useUserRole.ts +++ b/src/hooks/useUserRole.ts @@ -7,7 +7,10 @@ export function useUserRole(subdomain?: string) { const site = useGetSite(subdomain) const userSite = useAccountSites() - const [address] = useAccountState((s) => [s.computed.account?.address]) + const [ssrReady, address] = useAccountState(({ ssrReady, computed }) => [ + ssrReady, + computed.account?.address, + ]) const isOperator = useIsOperators({ characterId: +(site.data?.metadata?.proof || 0), @@ -15,20 +18,27 @@ export function useUserRole(subdomain?: string) { }) let role = null - if (subdomain && address) { - if (userSite.data?.find((site) => site.username === subdomain)) { - role = "owner" - } else if (isOperator.data) { - role = "operator" - } + if (subdomain) { + if (address) { + if (userSite.data?.find((site) => site.username === subdomain)) { + role = "owner" + } else if (isOperator.data) { + role = "operator" + } - return { - isSuccess: site.isSuccess && userSite.isSuccess && isOperator.isSuccess, - data: role, + return { + isSuccess: site.isSuccess && userSite.isSuccess && isOperator.isSuccess, + data: role, + } + } else { + return { + isSuccess: ssrReady, + data: null, + } } } else { return { - isSuccess: true, + isSuccess: false, data: null, } }