Skip to content

Instantly share code, notes, and snippets.

@ahmedghazi
Created December 14, 2022 15:18
Show Gist options
  • Save ahmedghazi/72c32792983ed4cc048d42fb6e612ff7 to your computer and use it in GitHub Desktop.
Save ahmedghazi/72c32792983ed4cc048d42fb6e612ff7 to your computer and use it in GitHub Desktop.
import sanityClient from "@sanity/client";
const client = sanityClient({
projectId: process.env.GATSBY_SANITY_PROJECT_ID,
dataset: process.env.GATSBY_SANITY_PROJECT_DATASET,
apiVersion: "2021-08-29",
useCdn: false,
withCredentials: true,
token: process.env.GATSBY_SANITY_READ_TOKEN,
});
export default async function handler(req, res) {
res.setHeader("Access-Control-Allow-Origin", "*");
const body = JSON.parse(req.body);
const { password } = body;
const types = ["pageModulaire"];
const query = `*[_type in $types
&& !(_id in path("drafts.**"))
&& password == $password
]
{ title, _type } | order(_createdAt asc)`;
// console.log(query);
const params = { password: password, types: types };
try {
const data = await client.fetch(query, params);
console.log(data);
const granted = data.length > 0;
res.status(200).json({ granted });
} catch (error) {
res.status(500).json({ message: error });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment