fix: refresh search token after library (#2924)

creation for course creator access

  When a course creator creates a new library, the cached JWT token for
  Meilisearch needs to be refreshed to include the new library's access_id.
  Without this, newly added components won't appear in search results until
  the page is refreshed.

  This works in conjunction with the backend fix that creates SearchAccess
  records immediately on library creation.

  The fix invalidates the content_search query, triggering React Query to
  refetch the token with updated access permissions.
This commit is contained in:
Muhammad Waleed
2026-03-05 14:17:27 +05:00
committed by GitHub
parent 5c1cdcf01c
commit abcef4a502
2 changed files with 5 additions and 0 deletions

View File

@@ -63,6 +63,9 @@ describe('create library apiHooks', () => {
expect(invalidateQueriesSpy).toHaveBeenCalledWith({
queryKey: libraryAuthoringQueryKeys.contentLibraryList(),
});
expect(invalidateQueriesSpy).toHaveBeenCalledWith({
queryKey: ['content_search'],
});
});
});

View File

@@ -23,6 +23,8 @@ export const useCreateLibraryV2 = () => {
mutationFn: createLibraryV2,
onSettled: () => {
queryClient.invalidateQueries({ queryKey: libraryAuthoringQueryKeys.contentLibraryList() });
// Invalidate the search token to refresh with the new library's access_id
queryClient.invalidateQueries({ queryKey: ['content_search'] });
},
});
};