From 6fb00b377755cd4e592c5130eb060819184805df Mon Sep 17 00:00:00 2001 From: Massedil Date: Sat, 28 Jun 2025 18:40:27 +0200 Subject: [PATCH] fix(login): IDENTITIES GraphQL queries are refetched when the user is changed Related to #1806 --- src/composition/apollo/actor.ts | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/composition/apollo/actor.ts b/src/composition/apollo/actor.ts index c2c401a73..b9236cffa 100644 --- a/src/composition/apollo/actor.ts +++ b/src/composition/apollo/actor.ts @@ -23,11 +23,19 @@ export function useCurrentActorClient() { } export function useLazyCurrentUserIdentities() { + const { currentUser } = useCurrentUserClient(); return useLazyQuery<{ loggedUser: Pick; }>( IDENTITIES, - {}, + { + // To ensure the request is re-executed when the user changes, + // we include a dummy `_user` parameter that's ignored by the server. + // This function does not depend on the user, the server identifies them by the token. + // So without this dummy parameter, the GraphQL call is not automatically reloaded + // when the actor changes. + _user: currentUser?.value?.id, + }, { fetchPolicy: "network-only", } @@ -46,9 +54,21 @@ export function useCurrentUserIdentities() { const { result, error, loading } = useQuery<{ loggedUser: Pick; - }>(IDENTITIES, {}, () => ({ - enabled: enabled, - })); + }>( + IDENTITIES, + { + // To ensure the request is re-executed when the user changes, + // we include a dummy `_user` parameter that's ignored by the server. + // This function does not depend on the user, the server identifies them by the token. + // So without this dummy parameter, the GraphQL call is not automatically reloaded + // when the actor changes. + _user: currentUser?.value?.id, + }, + () => ({ + enabled: enabled, + fetchPolicy: "network-only", + }) + ); const identities = computed(() => enabled.value ? result.value?.loggedUser?.actors : null