Skip to content

Commit

Permalink
fix(sitemap): fetch Sanity data with token
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Sep 9, 2024
1 parent b363ccf commit 1c8e6aa
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import type { MetadataRoute } from "next";
import { client } from "../../studio/lib/client";
import { Slug } from "../../studio/lib/payloads/global";
import { token } from "../../studio/lib/token";

interface SitemapDocument {
slug: Slug;
_updatedAt: string;
}

const clientWithToken = client.withConfig({ token });

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const documents = await client.fetch<SitemapDocument[]>(`*[defined(slug)]`);
const documents =
await clientWithToken.fetch<SitemapDocument[]>(`*[defined(slug)]`);

return documents.map((s) => ({
url: new URL(s.slug.current, process.env.NEXT_PUBLIC_URL).toString(),
Expand Down

0 comments on commit 1c8e6aa

Please sign in to comment.