fix: user role initial
This commit is contained in:
+21
-11
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user