From e1eaa0c9547053e55c0e0f9d4d2b9c59034defb4 Mon Sep 17 00:00:00 2001 From: christinaroise Date: Tue, 27 Aug 2024 08:55:47 +0200 Subject: [PATCH] remove unused and update token variable --- studioShared/lib/fetchWithToken.ts | 38 ------------------------------ studioShared/lib/token.ts | 8 +++---- 2 files changed, 4 insertions(+), 42 deletions(-) delete mode 100644 studioShared/lib/fetchWithToken.ts diff --git a/studioShared/lib/fetchWithToken.ts b/studioShared/lib/fetchWithToken.ts deleted file mode 100644 index c101c8b79..000000000 --- a/studioShared/lib/fetchWithToken.ts +++ /dev/null @@ -1,38 +0,0 @@ -/** - * fetchWithToken - * - * Utility function to securely fetch data from the server using an API route. - * This function sends a POST request to the /api/fetchData route with a GROQ query - * and optional parameters. It returns the fetched data as a Promise of type T. - * - * This function should be used in client-side components where data needs to be - * fetched securely using the server-side token without exposing it in the client code. - * - * @template T - The expected return type of the fetched data. - * @param {string} query - The GROQ query string to be executed on the server. - * @param {Record} [params] - Optional parameters to be passed along with the query. - * @returns {Promise} - A promise that resolves to the fetched data of type T. - * - * @throws Will throw an error if the fetch operation fails or if the response is not ok. - * - * @example - * const data = await fetchWithToken("*[_type == 'myType']", { param1: 'value' }); - */ -export const fetchWithToken = async ( - query: string, - params?: Record, -): Promise => { - const response = await fetch("/api/fetchData", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ query, params }), - }); - - if (!response.ok) { - throw new Error("Failed to fetch data"); - } - - return await response.json(); -}; diff --git a/studioShared/lib/token.ts b/studioShared/lib/token.ts index 24a9ff676..79eaa5c08 100644 --- a/studioShared/lib/token.ts +++ b/studioShared/lib/token.ts @@ -5,19 +5,19 @@ import { experimental_taintUniqueValue } from "react"; export const token = process.env.NODE_ENV === "development" - ? process.env.SANITY_API_TOKEN_DEV - : process.env.SANITY_API_TOKEN_PROD; + ? process.env.SANITY_SHARED_API_TOKEN_DEV + : process.env.SANITY_SHARED_API_TOKEN_PROD; if (!token) { throw new Error( `Missing SANITY_API_TOKEN for ${ process.env.NODE_ENV === "development" ? "development" : "production" - } environment`, + } environment` ); } experimental_taintUniqueValue( "Do not pass the sanity API read token to the client.", process, - token, + token );