fix(login): call resetStore() at login
To ensure that queries which identify the user via HTTP headers (instead of GraphQL variables) are properly refetched.
This commit is contained in:
@@ -45,20 +45,9 @@ export function useCurrentUserIdentities() {
|
|||||||
|
|
||||||
const { result, error, loading } = useQuery<{
|
const { result, error, loading } = useQuery<{
|
||||||
loggedUser: Pick<ICurrentUser, "actors">;
|
loggedUser: Pick<ICurrentUser, "actors">;
|
||||||
}>(
|
}>(IDENTITIES, {}, () => ({
|
||||||
IDENTITIES,
|
enabled: enabled,
|
||||||
{
|
}));
|
||||||
// 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,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const identities = computed(() =>
|
const identities = computed(() =>
|
||||||
enabled.value ? result.value?.loggedUser?.actors : undefined
|
enabled.value ? result.value?.loggedUser?.actors : undefined
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { useCurrentUserClient } from "./user";
|
|||||||
import type { Ref } from "vue";
|
import type { Ref } from "vue";
|
||||||
import { IGroup } from "@/types/actor";
|
import { IGroup } from "@/types/actor";
|
||||||
import { GROUP_DISCUSSIONS_LIST } from "@/graphql/discussion";
|
import { GROUP_DISCUSSIONS_LIST } from "@/graphql/discussion";
|
||||||
import { useCurrentActorClient } from "./actor";
|
|
||||||
|
|
||||||
export function useGroupDiscussionsList(
|
export function useGroupDiscussionsList(
|
||||||
name: string | undefined | Ref<string | undefined>,
|
name: string | undefined | Ref<string | undefined>,
|
||||||
@@ -14,7 +13,6 @@ export function useGroupDiscussionsList(
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const { currentUser } = useCurrentUserClient();
|
const { currentUser } = useCurrentUserClient();
|
||||||
const { currentActor } = useCurrentActorClient();
|
|
||||||
|
|
||||||
const { result, error, loading, onResult, onError, refetch } = useQuery<
|
const { result, error, loading, onResult, onError, refetch } = useQuery<
|
||||||
{
|
{
|
||||||
@@ -32,12 +30,6 @@ export function useGroupDiscussionsList(
|
|||||||
GROUP_DISCUSSIONS_LIST,
|
GROUP_DISCUSSIONS_LIST,
|
||||||
() => ({
|
() => ({
|
||||||
name: unref(name),
|
name: unref(name),
|
||||||
// To ensure the request is re-executed when the actor changes,
|
|
||||||
// we include a dummy `_actor` parameter that's ignored by the server.
|
|
||||||
// This function does not depend on the actor, the server identifies them by the token.
|
|
||||||
// So without this dummy parameter, the GraphQL call is not automatically reloaded
|
|
||||||
// when the actor changes.
|
|
||||||
_actor: currentActor?.value?.id,
|
|
||||||
...options,
|
...options,
|
||||||
}),
|
}),
|
||||||
() => ({
|
() => ({
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { useCurrentUserClient } from "./user";
|
|||||||
import type { Ref } from "vue";
|
import type { Ref } from "vue";
|
||||||
import { IGroup } from "@/types/actor";
|
import { IGroup } from "@/types/actor";
|
||||||
import { GROUP_RESOURCES_LIST } from "@/graphql/resources";
|
import { GROUP_RESOURCES_LIST } from "@/graphql/resources";
|
||||||
import { useCurrentActorClient } from "./actor";
|
|
||||||
|
|
||||||
export function useGroupResourcesList(
|
export function useGroupResourcesList(
|
||||||
name: string | undefined | Ref<string | undefined>,
|
name: string | undefined | Ref<string | undefined>,
|
||||||
@@ -14,7 +13,6 @@ export function useGroupResourcesList(
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const { currentUser } = useCurrentUserClient();
|
const { currentUser } = useCurrentUserClient();
|
||||||
const { currentActor } = useCurrentActorClient();
|
|
||||||
|
|
||||||
const { result, error, loading, onResult, onError, refetch } = useQuery<
|
const { result, error, loading, onResult, onError, refetch } = useQuery<
|
||||||
{
|
{
|
||||||
@@ -32,12 +30,6 @@ export function useGroupResourcesList(
|
|||||||
GROUP_RESOURCES_LIST,
|
GROUP_RESOURCES_LIST,
|
||||||
() => ({
|
() => ({
|
||||||
name: unref(name),
|
name: unref(name),
|
||||||
// To ensure the request is re-executed when the actor changes,
|
|
||||||
// we include a dummy `_actor` parameter that's ignored by the server.
|
|
||||||
// This function does not depend on the actor, the server identifies them by the token.
|
|
||||||
// So without this dummy parameter, the GraphQL call is not automatically reloaded
|
|
||||||
// when the actor changes.
|
|
||||||
_actor: currentActor?.value?.id,
|
|
||||||
...options,
|
...options,
|
||||||
}),
|
}),
|
||||||
() => ({
|
() => ({
|
||||||
|
|||||||
@@ -134,7 +134,12 @@ import { IUser } from "@/types/current-user.model";
|
|||||||
import { saveUserData, SELECTED_PROVIDERS } from "@/utils/auth";
|
import { saveUserData, SELECTED_PROVIDERS } from "@/utils/auth";
|
||||||
import { storeUserLocationAndRadiusFromUserSettings } from "@/utils/location";
|
import { storeUserLocationAndRadiusFromUserSettings } from "@/utils/location";
|
||||||
import { NoIdentitiesException } from "@/utils/identity";
|
import { NoIdentitiesException } from "@/utils/identity";
|
||||||
import { useMutation, useLazyQuery, useQuery } from "@vue/apollo-composable";
|
import {
|
||||||
|
useMutation,
|
||||||
|
useLazyQuery,
|
||||||
|
useQuery,
|
||||||
|
useApolloClient,
|
||||||
|
} from "@vue/apollo-composable";
|
||||||
import { computed, reactive, ref, onMounted } from "vue";
|
import { computed, reactive, ref, onMounted } from "vue";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { useRoute, useRouter } from "vue-router";
|
import { useRoute, useRouter } from "vue-router";
|
||||||
@@ -151,6 +156,8 @@ const route = useRoute();
|
|||||||
|
|
||||||
const { currentUser } = useCurrentUserClient();
|
const { currentUser } = useCurrentUserClient();
|
||||||
|
|
||||||
|
const apollo = useApolloClient();
|
||||||
|
|
||||||
const configQuery = useQuery<{
|
const configQuery = useQuery<{
|
||||||
config: Pick<
|
config: Pick<
|
||||||
IConfig,
|
IConfig,
|
||||||
@@ -198,6 +205,11 @@ const loginAction = async (e: Event) => {
|
|||||||
errors.value = [];
|
errors.value = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Step 0: Call resetStore to ensure that queries which identify the user via HTTP headers
|
||||||
|
// (instead of GraphQL variables) are properly refetched.
|
||||||
|
// https://www.apollographql.com/docs/react/networking/authentication#reset-store-on-logout
|
||||||
|
apollo.client.resetStore();
|
||||||
|
|
||||||
// Step 1: login the user
|
// Step 1: login the user
|
||||||
const { data: loginData } = await loginMutation.mutate({
|
const { data: loginData } = await loginMutation.mutate({
|
||||||
email: credentials.email,
|
email: credentials.email,
|
||||||
|
|||||||
Reference in New Issue
Block a user