diff --git a/gql-codegen.yml b/gql-codegen.yml index 3b52604..f026b27 100644 --- a/gql-codegen.yml +++ b/gql-codegen.yml @@ -2,7 +2,7 @@ overwrite: true schema: - 'https://graphql.datocms.com/': headers: - Authorization: Bearer ${CMS_ACCESS_TOKEN} + Authorization: Bearer ${NEXT_PUBLIC_CMS_ACCESS_TOKEN} documents: './src/**/*.{gql,graphql}' generates: ./src/lib/cms/generated.ts: diff --git a/src/lib/cms/index.ts b/src/lib/cms/index.ts index 04ab3da..e383481 100644 --- a/src/lib/cms/index.ts +++ b/src/lib/cms/index.ts @@ -9,7 +9,7 @@ const cms = (preview?: boolean) => { return getSdk( new GraphQLClient(preview ? previewEndpoint : endpoint, { headers: { - Authorization: `Bearer ${process.env.CMS_ACCESS_TOKEN}` + Authorization: `Bearer ${process.env.NEXT_PUBLIC_CMS_ACCESS_TOKEN}` } }) ) diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx index 890246d..0dee6e9 100644 --- a/src/pages/blog/index.tsx +++ b/src/pages/blog/index.tsx @@ -1,5 +1,6 @@ import { PageLayout } from 'components/layout/page' import { + getBlogPosts, getBlogPosts as serverGetBlogPosts, getBlogPostsCategories as serverGetBlogPostsCategories } from 'lib/blog' @@ -17,7 +18,7 @@ import SearchBar, { SearchContainer } from '~/components/sections/blog/search' import { CategoryFragment } from '~/lib/cms/generated' -import { getHrefWithQuery, getQueryParams, makeQuery } from '~/lib/utils/router' +import { getHrefWithQuery, makeQuery } from '~/lib/utils/router' const getMatchingCategory = (categories: CategoryFragment[], c?: string) => categories.find((cat) => cat.slug === c) @@ -54,7 +55,7 @@ const BlogIndexPage = ({ return clientGetBlogPosts({ page: pageParam, - category: matchingCat?.id ?? null, + category: matchingCat?.id ?? undefined, search: queryKey[3] as string }) }, @@ -139,36 +140,31 @@ const clientGetBlogPosts = async ({ step, filterIds, category, - search, - locale + search }: { page?: number step?: number filterIds?: string[] category?: string search?: string - locale?: string }): Promise<{ pagination: { page: number - nextPage: number + nextPage: number | null totalPages: number step: number total: number } data: any[] }> => { - const searchParams = getQueryParams({ - page: page?.toString() || null, - step: step?.toString() || null, - filterIds: filterIds?.join(',') || null, - category: category || null, - search: search || null, - locale: locale || null + console.log(category, search) + const allBlogPosts = await getBlogPosts({ + page, + step, + filterIds: filterIds, + category, + search }) - const allBlogPosts = await ( - await fetch(`/api/blog-posts?${searchParams.toString()}`) - ).json() return allBlogPosts }