pl-fe: Disable some queries when unauthenticated

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2024-10-25 20:41:14 +02:00
parent e546d787f0
commit d3b5078030
3 changed files with 7 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import * as v from 'valibot';
import { Entities } from 'pl-fe/entity-store/entities';
import { useEntity } from 'pl-fe/entity-store/hooks/useEntity';
import { useClient } from 'pl-fe/hooks/useClient';
import { useLoggedIn } from 'pl-fe/hooks/useLoggedIn';
import type { Relationship } from 'pl-api';
@ -12,13 +13,14 @@ interface UseRelationshipOpts {
const useRelationship = (accountId: string | undefined, opts: UseRelationshipOpts = {}) => {
const client = useClient();
const { isLoggedIn } = useLoggedIn();
const { enabled = false } = opts;
const { entity: relationship, ...result } = useEntity<Relationship>(
[Entities.RELATIONSHIPS, accountId!],
() => client.accounts.getRelationships([accountId!]),
{
enabled: enabled && !!accountId,
enabled: enabled && isLoggedIn && !!accountId,
schema: v.pipe(v.any(), v.transform(arr => arr[0])),
},
);