From bce74f901c93baffb6797af5e9457a84b639a903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=A9o=20M=C3=A9vollon?= Date: Fri, 7 Jun 2024 18:37:14 +0200 Subject: [PATCH] fix: unused strapi token --- README.md | 27 --------------------------- next-app/.env | 3 +-- next-app/app/blog/[blog]/layout.tsx | 3 +-- next-app/app/blog/[blog]/page.tsx | 3 +-- next-app/app/blog/page.tsx | 3 +-- 5 files changed, 4 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index f3d7c2bf..ac2f4250 100644 --- a/README.md +++ b/README.md @@ -71,36 +71,9 @@ touch .env 3. Paste in the following. ```yaml -NEXT_PUBLIC_STRAPI_API_TOKEN=your-api-token NEXT_PUBLIC_STRAPI_API_URL=http://127.0.0.1:1337 ``` -4. Before starting our Next JS app we need to go inside our Strapi Admin and create a token that we will be using for displaying our **content**. - -Inside your Strapi Admin Panel navigate to `Settings` -> `API Tokens` and click on the `Create new API Token`. - -![api-tokens](https://user-images.githubusercontent.com/6153188/231865572-cebc5538-374c-4050-91cd-c303fae25a3d.png) - -Here are our Token Settings - -Name: Public API Token Content -Description: Access to public content. -Token duration: Unlimited -Token type: Custom - -In Permissions let's give the following access. - -| Content | Permissions | -| -------- | :--------------: | -| Article | find and findOne | -| Author | find and findOne | -| Category | find and findOne | -| Page | find and findOne | - -![permissions](https://user-images.githubusercontent.com/6153188/231865625-a3634d89-0f40-4a6d-a356-8f654abd88b9.gif) - -Once you have your token add it to your `NEXT_PUBLIC_STRAPI_API_TOKEN` variable name in the `.env` file. - 5. Start your frontend ```bash diff --git a/next-app/.env b/next-app/.env index 1665e7d9..49c0380e 100644 --- a/next-app/.env +++ b/next-app/.env @@ -1,2 +1 @@ -NEXT_PUBLIC_STRAPI_API_TOKEN=your-api-token -NEXT_PUBLIC_STRAPI_API_URL=http://127.0.0.1:1337 \ No newline at end of file +NEXT_PUBLIC_STRAPI_API_URL=http://127.0.0.1:1337 diff --git a/next-app/app/blog/[blog]/layout.tsx b/next-app/app/blog/[blog]/layout.tsx index 6ed6fd58..1948d183 100644 --- a/next-app/app/blog/[blog]/layout.tsx +++ b/next-app/app/blog/[blog]/layout.tsx @@ -14,12 +14,11 @@ export async function generateMetadata({ }: { params: { blog: string } }): Promise { - const token = process.env.NEXT_PUBLIC_STRAPI_API_TOKEN; const path = `/articles`; const urlParamsObject = { filters: { slug: params.blog }, }; - const options = { headers: { Authorization: `Bearer ${token}` } }; + const options = {}; const post = await fetchAPI(path, urlParamsObject, options); const postAttributes = post.data[0].attributes; return { diff --git a/next-app/app/blog/[blog]/page.tsx b/next-app/app/blog/[blog]/page.tsx index 2998ee68..185fec14 100644 --- a/next-app/app/blog/[blog]/page.tsx +++ b/next-app/app/blog/[blog]/page.tsx @@ -49,7 +49,6 @@ export default async function Blog({ params }) { } async function getBlogPostBySlug(slug: string) { - const token = process.env.NEXT_PUBLIC_STRAPI_API_TOKEN; const path = `/articles`; const urlParamsObject = { filters: { slug }, @@ -60,7 +59,7 @@ async function getBlogPostBySlug(slug: string) { cover: { fields: ["url", "alternativeText", "caption"] }, }, }; - const options = { headers: { Authorization: `Bearer ${token}` } }; + const options = {}; const response = await fetchAPI(path, urlParamsObject, options); const post = response.data[0]; const data = post.attributes; diff --git a/next-app/app/blog/page.tsx b/next-app/app/blog/page.tsx index 91a3893a..a3af17a9 100644 --- a/next-app/app/blog/page.tsx +++ b/next-app/app/blog/page.tsx @@ -62,7 +62,6 @@ export default async function Blog() { async function getBlogPosts() { try { - const token = process.env.NEXT_PUBLIC_STRAPI_API_TOKEN; const path = `/articles`; const urlParamsObject = { populate: { @@ -74,7 +73,7 @@ async function getBlogPosts() { }, sort: { PublishAt: "desc" }, }; - const options = { headers: { Authorization: `Bearer ${token}` } }; + const options = {}; const responseData = await fetchAPI(path, urlParamsObject, options); return responseData.data; } catch (error) {