TanStackT
TanStack2y ago
19 replies
slow-yellow

Invalidate didnt work

I have mutation
  const { mutate, isPending } = useMutation({
    mutationFn: (values: SignInUser) => signIn(values),
    onSuccess: async (data) => {
      if (data.ok) {
        await queryClient.invalidateQueries({
          queryKey: ["userSession"],
        });
        await queryClient.refetchQueries({
          queryKey: ["userSession"],
        });
        router.push("/");
      }
    },
  });

and i have in navbar query

  const { data: userSession = null, ...rest } = useQuery({
    queryKey: ["userSession"],
    queryFn: () => session(),
    gcTime: cacheTime,
  });


after successfully login my userSession is still null and i must refresh page by f5
image.png
Was this page helpful?