<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Theodore Kelechukwu Onyejiaku on Medium]]></title>
        <description><![CDATA[Stories by Theodore Kelechukwu Onyejiaku on Medium]]></description>
        <link>https://medium.com/@theodoreonyejiaku?source=rss-9323ef8b74c9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MIW4ltAbMA_revmvYJpr8w.jpeg</url>
            <title>Stories by Theodore Kelechukwu Onyejiaku on Medium</title>
            <link>https://medium.com/@theodoreonyejiaku?source=rss-9323ef8b74c9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 00:34:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@theodoreonyejiaku/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Test blog]]></title>
            <link>https://medium.com/@theodoreonyejiaku/test-blog-a0a7e02c30e1?source=rss-9323ef8b74c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0a7e02c30e1</guid>
            <dc:creator><![CDATA[Theodore Kelechukwu Onyejiaku]]></dc:creator>
            <pubDate>Tue, 22 Sep 2026 15:38:56 GMT</pubDate>
            <atom:updated>2026-09-22T15:38:56.819Z</atom:updated>
            <content:encoded><![CDATA[<p>this is a test blog</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0a7e02c30e1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a Company Website with Bolt.new and Strapi 5 — Part 2]]></title>
            <link>https://medium.com/strapi/build-a-company-website-with-bolt-new-and-strapi-5-part-2-6df2a2c23b06?source=rss-9323ef8b74c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/6df2a2c23b06</guid>
            <category><![CDATA[strapi]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[bolt]]></category>
            <category><![CDATA[vibe-coding]]></category>
            <dc:creator><![CDATA[Theodore Kelechukwu Onyejiaku]]></dc:creator>
            <pubDate>Mon, 17 Nov 2025 10:58:01 GMT</pubDate>
            <atom:updated>2025-11-17T10:58:01.959Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build a Company Website with Bolt.new and Strapi 5 — Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2pO3ldCkd_7CwAhw-uDAwQ.png" /></figure><h3>Introduction</h3><p>In the first part of this tutorial series, we generated the initial version of our company website’s frontend using Bolt.new and explored how vibe coding helps speed up UI development.</p><p>We also set up our Strapi 5 backend on <a href="https://strapi.io/cloud">Strapi Cloud</a> and prepared the project structure for integration.</p><p>Now, let’s finish this tutorial. We will take the next big step:</p><ul><li>Versioning and safeguarding your Bolt.new project</li><li>Installing and configuring the Strapi client in your frontend</li><li>Fetching data from Strapi (blogs, slugs, dynamic zones)</li><li>Debugging common Bolt.new errors</li><li>Further Enhancements</li><li>Deploying through GitHub → Netlify</li><li>Best Practices for Prompting in Bolt</li></ul><h3>Tutorial Parts</h3><p>This tutorial is divided into two parts:</p><ul><li><a href="https://strapi.io/blog/build-a-company-website-with-bolt-new-and-strapi5-part-1">Part 1 — Planning and Building the Frontend: Using Bolt.new and Strapi 5</a></li><li>Part 2 — Connecting Bolt.new to Strapi API and Deploying to Netlify</li></ul><h3>Prompt 4 — Versioning Your Bolt App and Connecting to Strapi</h3><p>Now that our Strapi backend is fully set up, we can connect it to the frontend we generated with Bolt.new.</p><p>Before doing that, it’s a good idea to save the current state of our project in case we need to revert during the integration process.</p><h3>Versioning Your Bolt.new Project</h3><p>Bolt.new automatically versions your project as you work, but it’s still good practice to confirm that your latest stable state is saved.</p><p>To view your versions:</p><ul><li>Click your Project Name in the top-left corner.</li><li>Select Version History.</li><li>You’ll see a list of automatically saved versions that you can restore at any time.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oaFkXGAYwHTQjzQT.png" /></figure><p>This built-in history is especially useful when you want to integrate external APSs or make major changes.</p><h3>Connecting Bolt.new to Your Strapi Backend</h3><p>With the Strapi backend deployed and available via a public API URL, we can now instruct Bolt to install the <a href="https://docs.strapi.io/cms/api/client">@strapi/client</a> and configure our application for backend communication.</p><p>To integrate properly, Bolt.new needs to:</p><ul><li>Install the official Strapi client: @strapi/client</li><li>Initialize and export a reusable Strapi SDK instance</li><li>Provide a utility function for accessing the base URL of your Strapi Cloud project</li></ul><p>We’ll use the Plan Mode for this step so Bolt understands the task and executes it precisely.</p><pre>Now connect to Strapi v5. I want to use it as my backend.</pre><pre>1. Install Strapi Client:<br>npm install @strapi/client</pre><pre>2. Create a file: src/data/strapi-sdk.ts with this exact code:</pre><pre>import { strapi } from &#39;@strapi/client&#39;;<br>import { getStrapiURL } from &quot;@/lib/utils&quot;;</pre><pre>const BASE_API_URL = getStrapiURL() + &quot;/api&quot;;<br>export const sdk = strapi({ baseURL: BASE_API_URL });<br></pre><pre>3. Update src/lib/utils.ts: </pre><pre>export function getStrapiURL() { <br>return process.env.VITE_STRAPI_URL || &quot;https://superb-freedom-8531c68dfe.strapiapp.com/&quot;; <br>}</pre><p>Ensure you click the implement.</p><p>After pasting this into Bolt.new, make sure to click Implement Plan.</p><p>Bolt will then:</p><ul><li>Install @strapi/client</li><li>Add the strapi-sdk.ts file</li><li>Update your utility file</li><li>Rebuild your project with the new dependencies</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ODA2zqYyHhNr6nE9.png" /></figure><p>With the Strapi SDK configured, we’re ready to fetch real content from our CMS.</p><h3>Prompt 5 — Fetching and Displaying Content from Strapi</h3><p>With the Strapi client SDK now installed and configured in your Bolt.new project, the next step is to fetch real content from your Strapi backend and display it in the UI.</p><p>This is where your project transitions from a static prototype into a dynamic, CMS-driven application.</p><h3>(Optional) Generate OpenAPI Specification of your Project</h3><p>To give Bolt.new additional context about your available endpoints, you can generate an <a href="https://docs.strapi.io/cms/api/openapi">OpenAPI specification</a> for your Strapi project.</p><p>This documentation describes all of your API routes, request parameters, and response structures without requiring source code access.</p><p>This step is optional, but helpful if your content types are complex.</p><p>Run the command to generate the JSON OpenAPI specification</p><pre>npm run strapi openapi generate<br># or <br>yarn strapi openapi generate</pre><p>Because Bolt.new has a limited <a href="https://support.bolt.new/building/intro-llms">context window</a>, providing the entire OpenAPI file may consume unnecessary tokens for this tutorial.</p><p>Feel free to skip it unless you need deep endpoint documentation inside Bolt.</p><h3>Fetching Basic Data from Strapi</h3><p>Let’s begin by fetching our Blog content from Strapi. When you hit your Strapi API directly, a response will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dFomTVXwSBZqkxOI.png" /></figure><p>For this tutorial, we will fetch:</p><ol><li>All Blogs (Blog collection type): (with related entities from Dynamic Zones, banners, authors, categories, tags, and SEO metadata)</li></ol><pre>/blogs?populate[dynamic_zone][on][dynamic-zone.faq-block][populate][faqs]=true&amp;populate[banner]=true&amp;populate[author]=true&amp;populate[category]=true&amp;populate[tags]=true&amp;populate[seo]=true</pre><ol><li>A Single Blog by Slug</li></ol><pre>/blogs?filters[slug][$eq]=slug-value</pre><p>These two endpoints are enough to build a blog listing page and a blog details page. Feel free to add more.</p><h3>Prompting Bolt.new to Implement Blog Fetching</h3><p>Now that the API endpoints are ready, we’ll instruct Bolt.new to:</p><ul><li>Create a dedicated API file</li><li>Add getBlogs() and getBlogBySlug() functions</li><li>Use the Strapi SDK we configured earlier</li><li>Update the blog page to consume real data</li><li>Keep the existing dummy data for fallback purposes</li></ul><p>Switch to Plan Mode, and then paste this prompt:</p><pre>Using the previously created SDK in data/strapi-sdk.ts<br><br>create a new file inside data/api.ts<br>Add the function:<br>- getBlogs(): fetch `/blogs?populate[dynamic_zone][on][dynamic-zone.faq-block][populate][faqs]=true&amp;populate[banner]=true&amp;populate[author]=true&amp;populate[category]=true&amp;populate[tags]=true&amp;populate[seo]=true`<br>- getBlogBySlug(slug): fetch `/blogs?filters[slug][$eq]=slug-value)`<br>Use async/await and return typed JSON. <br>Update the blog page with the new data. Leave the dummy data as it is.</pre><p>Keeping the dummy data ensures your app remains functional even if the Strapi server is cold-starting (common on the free tier) or temporarily unreachable.</p><h3>Fixing Errors in Bolt.new</h3><p>Once Bolt.new implements the Strapi fetching logic, you may run into errors.</p><p>This is normal, especially when combining AI-generated code with a live backend. The key is learning how to debug efficiently without falling into infinite “Fix this” loops, which can quickly burn tokens and break working code.</p><p>Here’s the error we encountered when Bolt attempted to fetch Blog data from the Strapi backend:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dAbGCCknOpMSO3-1.png" /></figure><p>We can use 3 ways to resolve this issue:</p><ul><li>Discuss the error directly with Bolt</li><li>Use the Highlight tool to target exactly where the fix is needed</li><li>Fix the issue manually in your code when Bolt gets stuck</li></ul><p>Let’s walk through how each one helped (and sometimes didn’t).</p><h3>1. Discuss the Error with Bolt</h3><p>The first attempt was to paste the error message directly into Bolt and ask it to resolve it.</p><p>Bolt responded, but suggested using Bolt Database, its built-in backend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OpSkIpiWv6z4emFN.png" /></figure><p>This wasn’t helpful, because our goal is to use Strapi, not Bolt Database.</p><p>This is common: when Bolt doesn’t understand the source of a backend error, it sometimes defaults to suggesting its internal database.</p><h3>2. Use the Highlight Tool for Targeted Fixes</h3><p>The next approach was to use Bolt.new’s Highlight tool.</p><p>This allows you to mark a specific line or file and tell Bolt exactly what to fix, instead of letting it rewrite unrelated parts of your project.</p><p>We highlighted the import where the Strapi Client was used and asked Bolt to reinstall or repair it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*M-F0EPuyUuHG3W_v.png" /></figure><p>This is one of the most reliable debugging techniques in Bolt because it prevents the AI from over-correcting or introducing new regressions.</p><h3>3. When Bolt Gets Stuck: Manual Fix + Refresh</h3><p>Even after discussing the error and using Highlights, the issue persisted.</p><p>This happens occasionally because Bolt runs in a browser environment and can sometimes get stuck in an inconsistent state.</p><p>A page reload of the Bolt IDE resolved it.</p><h3>Final Results</h3><p>After reviewing the generated code, I noticed the root cause. Bolt had used Strapi v4 response formatting instead of the new flat Strapi 5 response format, specifically, the Strapi 4 <a href="https://strapi.io/blog/what-is-new-for-developers-in-strapi-5-top-10-changes">deprecated</a> .attributes field.</p><p>Strapi v5 no longer wraps content in .attributes, so any code referencing it will break.</p><p>We highlighted the incorrect usage and asked Bolt to remove it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5JMqZGOaiPlv0-Oj.png" /></figure><pre>Please remove the .attributes as we are using Strapi v5 and not v4.</pre><p>Once Bolt applied the fix, the blog data loaded correctly:</p><p><em>Fetched Data from Strapi Backend</em></p><blockquote><em>💡 NOTE Bolt implemented the </em><em>getBlogBySlug(slug) but did not create the Blog details page. You’ll need to explicitly prompt Bolt to add these.</em></blockquote><h3>Refining Your App (Dynamic Zones, Responsiveness, and UI Enhancements)</h3><p>With our Strapi integration working, the next step is to refine the UI and ensure the frontend correctly renders the dynamic content coming from the CMS.</p><h3>1. Handling Strapi Dynamic Zones and Components</h3><p>When navigating to a blog details page (via its slug), Bolt automatically uses the data coming from your Strapi dynamic zones, such as the FAQBlock.</p><p>In the demo below, you can see that:</p><ul><li>The FAQ entries from the dynamic zone are rendered correctly</li><li>The author’s email and other relational fields are pulled directly from Strapi</li><li>Bolt correctly uses the structured response returned by the Strapi CMS</li></ul><p><em>FAQ from Dynamic Zone</em></p><p>This is a major advantage of using Strapi’s modeling system. Bolt can generate UI components that map directly to your content types.</p><p>At this point, you can continue enhancing the UI by prompting Bolt to:</p><ul><li>Fetch and display global settings (from the GlobalSettings single type)</li><li>Add loaders for slow Strapi Cloud cold starts</li><li>Improve layout, typography, spacing, or animations</li><li>Build custom sections that adapt to the fields defined in Strapi</li></ul><p>Dynamic content gives your Bolt-generated site structure, and your prompts give it polish.</p><h3>2. Responsiveness</h3><p>Bolt-generated UIs sometimes look great on desktop but break or overlap on mobile. To fix this, use the Inspect or Highlight tools to point to exact elements that need adjustments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W8hQuzTZgHFvL9ZJ.png" /></figure><p>You can then provide targeted prompts such as:</p><pre>Make this section fully responsive for mobile and tablet.<br>Use Tailwind responsive utilities to adjust spacing, stacking, and font sizes.</pre><h3>3. Ask Bolt for Additional Features</h3><p>Once the core UI works, you can ask Bolt for improvement ideas. Using Plan Mode or Discussion Mode, ask:</p><pre>What features can improve this company website?</pre><p>Bolt may suggest enhancements such as:</p><ul><li>Interactive Demo and Playground Section</li><li>Community and Newsletter section</li><li>Resource Center</li><li>Built-in Chatbot and so on.</li></ul><h3>4. Using the Terminal</h3><p>Bolt.new includes an inline terminal that allows you to:</p><ul><li>Install dependencies (npm install swiper, etc.)</li><li>Run build or lint commands</li><li>Inspect logs during development</li></ul><p>This terminal is useful especially when installing third-party packages that Bolt doesn’t add automatically.</p><h3>5. Downloading your Code</h3><p>Before deploying or shipping your project, download your full codebase. This lets you:</p><ul><li>Review the architecture</li><li>Apply some security best practices</li><li>Clean up unused components or dependencies</li><li>Fix edge-case bugs</li><li>Customize the code beyond what Bolt can autogenerate</li><li>Commit to GitHub for version control</li></ul><p>Bolt.new is excellent for prototyping, but manual review ensures your final app is production-ready.</p><h3>Publishing Your Bolt.new Project</h3><p>Once everything looks good, you can publish directly from Bolt.new by clicking the Publish button at the top-right corner of the interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r0_nc70VTA0OPCq5.png" /></figure><p>Bolt will:</p><ul><li>Run a security audit</li><li>Check dependencies</li><li>Attempt to build and deploy your project</li><li>Generate a live, shareable link if successful</li></ul><p>If issues are detected, Bolt will suggest fixes, and you can attempt fixing them directly using Plan Mode or the Highlight tool.</p><p>Bolt will run a security audit. And if any issue is found, you will be advised to ask Bolt to fix it. If successful, Bolt will generate a shareable link to your live project.</p><h3>When Bolt Fails to Publish</h3><p>In some cases, Bolt may fail to publish your project. For example, my build failed due to a Turbopack limitation that commonly affects browser-based IDEs, and probably because Bolt.new generated my app in Next.js 13.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*atOtzs_Wa9WZuzP9.png" /></figure><p>If this happens, don’t worry, you still have a reliable deployment path using GitHub and Netlify.</p><h3>Connecting Your Project to GitHub</h3><p>Bolt.new provides a built-in GitHub integration that allows you to export your project directly into a new repository.</p><ul><li>Click the GitHub icon in the top-right corner.</li><li>Bolt will prompt you to authorize access to your GitHub account.</li><li>Choose a name for the new repository.</li><li>Bolt will push your complete project into GitHub.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kB90MNgYk1iUl_uo.png" /></figure><p>After authorization, Bolt asks you to name the repo:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QKDDYjflcreFSKUx.png" /></figure><p>Once the repo is created, you’re ready to deploy.</p><h3>Deploying Your Project on Netlify</h3><p>With the GitHub repository now available, deployment through Netlify becomes simple:</p><ol><li>Log in to Netlify.</li><li>Click <em>Add new project → Deploy from Git → Import an exising project</em>.</li><li>Select GitHub and choose the repository Bolt created.</li><li>Name your project (e.g., company-website-example).</li><li>Keep the default build settings for a Next.js app (Netlify auto-detects them).</li><li>Click Deploy.</li></ol><p>A few moments later, your site will be live! :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XdM3n57Xpenurx9B.png" /></figure><h3>Bolt Prompting Best Practices</h3><p>Getting great results from Bolt.new is all about how you prompt. Below are the most effective best practices to help you build faster, avoid unnecessary token usage, and maintain consistent app quality.</p><ul><li>Start with a plan and build the foundation (Context): Begin with a clear blueprint and focus on the first component, such as defining a hero section with specific elements, so that Bolt establishes a consistent design foundation before adding other sections.</li><li>Break work into small, iterative steps (Step-wise): Divide complex builds into small tasks by adding components and styling in stages and verifying each change, so you can easily adjust or roll back individual parts rather than a large, mixed prompt.</li><li>Use precise design language and be explicit: Rather than vague descriptors like “make the text bigger,” use professional design terms such as “increase font weight” or “raise line height,” and specify margins, padding, or z‑index settings.</li><li>Leverage Bolt’s feedback (Chain-of-thought) and targeting tools: Use features such as Discussion Mode, the “Enhance prompt” option, multiple first‑draft prompts, and file/element targeting to refine your prompts and direct Bolt to work on only the intended sections</li><li>Reuse, customize, and ask Bolt to teach you: Store high‑performing prompts in the Prompt Library, set project or system prompts with consistent instructions, and have Bolt generate cheat sheets or enhanced prompts to expand your vocabulary and creative ideas.</li></ul><p>For more prompting strategies, check out Bolt’s official guide: <a href="https://bolt.new/blog/prompting-tips-for-bolt">👉 Prompting Tips for Bolt</a></p><h3>Pain Points of Using Bolt</h3><p>Bolt.new is a powerful tool for rapid prototyping and AI-assisted development, but it also comes with limitations you should be aware of, especially if you’re building more complex, full-stack applications.</p><h3>1. Free Tier Limitations</h3><p>The free plan works well for simple, one-shot prompts and small projects, as tokens are limited.</p><p>For full-stack apps or frontend + backend integrations, you’ll likely need to upgrade.</p><h3>2. Context Loss</h3><p>Refreshing Bolt’s IDE or inactive sessions can sometimes cause the AI to lose context, which means:</p><ul><li>The agent may forget recent decisions</li><li>You may need to re-explain your instructions</li><li>Some prompts must be repeated</li></ul><p>Using Plan Mode, file locking, and targeted prompts helps reduce this problem, but it still happens occasionally.</p><h3>3. Occasional Hallucinations or Context Drift</h3><p>Bolt sometimes forgets previous constraints or introduces inconsistencies. For example, suggesting Bolt Database instead of your actual backend (Strapi).</p><p>When this happens, using the Highlight tool or reverting via Version History is the best approach.</p><h3>4. Dependency or Version Mismatches</h3><p>In some cases, Bolt may install a different dependency version than requested.</p><p>For example, it generated the project using Next.js 13 even after specifying Next.js 15.</p><p>Always verify:</p><ul><li>package.json</li><li>Framework versions</li><li>Tailwind/TypeScript configs</li></ul><p>Before continuing with your build.</p><h3>5. Build Issues Inside the Browser IDE</h3><p>Because Bolt runs in a browser-based environment, not all toolchains are fully supported. For example, I upgraded to Next.js 16, but this triggered a Turbopack error:</p><pre>Error: `turbo.createProject` is not supported by the wasm bindings.</pre><p>This appears to be a limitation of running Turbopack inside a WebAssembly environment. Fortunately, Bolt’s Version History allowed rolling back to a working version.</p><h3>6. Recommendations for Bolt Database</h3><p>When Bolt encounters backend-related errors, it sometimes suggests switching to Bolt Database, even when you’re intentionally using a custom backend like Strapi.</p><p>This isn’t harmful, but it can derail your debugging if you don’t catch it early.</p><h3>GitHub Repo, Live App, and Bolt Project Links</h3><ul><li>GitHub Repo: <a href="https://github.com/Theodore-Kelechukwu-Onyejiaku/company-website">https://github.com/Theodore-Kelechukwu-Onyejiaku/company-website</a></li><li>Live App on Netlify: <a href="https://company-website-example.netlify.app/">https://company-website-example.netlify.app/</a></li><li>Bolt Project Link: <a href="https://bolt.new/~/sb1-epr7g8v7">https://bolt.new/~/sb1-epr7g8v7</a></li></ul><p><em>Project Demo</em></p><blockquote><em>👋 NOTE: We used the free version of Strapi Cloud. So, give some time before the Blog data load as your Strapi server spins up.</em></blockquote><h3>Final Thoughts</h3><p>Suppose there is one lesson from this project. It would be that Bolt works best when you work in small, controlled steps.</p><p>That way, you can easily revert, update, and maintain your code without consuming too many tokens.</p><p>You can use the Free plan for experimentation, UI generation, or quick prototypes, but full-stack or multi-page applications benefit heavily from the paid tiers.</p><p>But for production-grade, enterprise-level projects, I will always take ownership of the core business logic, security patterns, API integrations, and performance considerations.</p><p>Bolt speeds up the work. It doesn’t replace the work.</p><h3>Conclusion</h3><p>In this two-part series, you learned how to use vibe coding principles and Bolt.new’s interface, modes, and prompting techniques to generate a full UI scaffold and connect it to a real Strapi backend. You also fetched dynamic content, debugged common issues, and deployed the final application using GitHub and Netlify.</p><p>Here are some next steps for your project:</p><ul><li>Ask Bolt to fetch the Global Data (GlobalSettings single type) of the company website in your Strapi backend:</li></ul><pre>/global-setting?populate[0]=footer&amp;populate[1]=footer.links&amp;populate[2]=header&amp;populate[3]=header.links&amp;populate[4]=defaultSEO&amp;populate[5]=socialLinks&amp;populate[6]=address</pre><ul><li>Ask Bolt to implement Light, Dark, and System Modes.</li><li>Set up the <a href="https://docs.strapi.io/cms/features/preview">frontend preview</a> in your Strapi backend</li><li>Ask Bolt to update or create data inside Strapi</li><li>Export your code locally and improve it.</li></ul><p>Bolt.new is a great platform. However, it’s not a full replacement for human designers and developers, at least not yet. The platform should be best used for experimentation, concept generation, and quick MVPs rather than enterprise-ready sites.</p><p>If you’re ready to explore the future of website building, Bolt.new is an exciting place to start, but keep your creative and technical instincts close by.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6df2a2c23b06" width="1" height="1" alt=""><hr><p><a href="https://medium.com/strapi/build-a-company-website-with-bolt-new-and-strapi-5-part-2-6df2a2c23b06">Build a Company Website with Bolt.new and Strapi 5 — Part 2</a> was originally published in <a href="https://medium.com/strapi">Strapi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a Company Website with Bolt.new and Strapi 5 — Part 2]]></title>
            <link>https://medium.com/@theodoreonyejiaku/build-a-company-website-with-bolt-new-and-strapi-5-part-2-d7c0c13270c2?source=rss-9323ef8b74c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7c0c13270c2</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[bolt]]></category>
            <category><![CDATA[strapi]]></category>
            <category><![CDATA[vibe-coding]]></category>
            <dc:creator><![CDATA[Theodore Kelechukwu Onyejiaku]]></dc:creator>
            <pubDate>Fri, 14 Nov 2025 17:26:31 GMT</pubDate>
            <atom:updated>2025-11-14T17:26:31.186Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build a</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2pO3ldCkd_7CwAhw-uDAwQ.png" /></figure><h3>Introduction</h3><p>In the first part of this tutorial series, we generated the initial version of our company website’s frontend using Bolt.new and explored how vibe coding helps speed up UI development.</p><p>We also set up our Strapi 5 backend on <a href="https://strapi.io/cloud">Strapi Cloud</a> and prepared the project structure for integration.</p><p>Now, let’s finish this tutorial. We will take the next big step:</p><ul><li>Versioning and safeguarding your Bolt.new project</li><li>Installing and configuring the Strapi client in your frontend</li><li>Fetching data from Strapi (blogs, slugs, dynamic zones)</li><li>Debugging common Bolt.new errors</li><li>Further Enhancements</li><li>Deploying through GitHub → Netlify</li><li>Best Practices for Prompting in Bolt</li></ul><h3>Tutorial Parts</h3><p>This tutorial is divided into two parts:</p><ul><li><a href="https://strapi.io/blog/build-a-company-website-with-bolt-new-and-strapi5-part-1">Part 1 — Planning and Building the Frontend: Using Bolt.new and Strapi 5</a></li><li>Part 2 — Connecting Bolt.new to Strapi API and Deploying to Netlify</li></ul><h3>Prompt 4 — Versioning Your Bolt App and Connecting to Strapi</h3><p>Now that our Strapi backend is fully set up, we can connect it to the frontend we generated with Bolt.new.</p><p>Before doing that, it’s a good idea to save the current state of our project in case we need to revert during the integration process.</p><h3>Versioning Your Bolt.new Project</h3><p>Bolt.new automatically versions your project as you work, but it’s still good practice to confirm that your latest stable state is saved.</p><p>To view your versions:</p><ul><li>Click your Project Name in the top-left corner.</li><li>Select Version History.</li><li>You’ll see a list of automatically saved versions that you can restore at any time.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i9YqXbzT3Y8aWXZV.png" /></figure><p>This built-in history is especially useful when you want to integrate external APSs or make major changes.</p><h3>Connecting Bolt.new to Your Strapi Backend</h3><p>With the Strapi backend deployed and available via a public API URL, we can now instruct Bolt to install the <a href="https://docs.strapi.io/cms/api/client">@strapi/client</a> and configure our application for backend communication.</p><p>To integrate properly, Bolt.new needs to:</p><ul><li>Install the official Strapi client: @strapi/client</li><li>Initialize and export a reusable Strapi SDK instance</li><li>Provide a utility function for accessing the base URL of your Strapi Cloud project</li></ul><p>We’ll use the Plan Mode for this step so Bolt understands the task and executes it precisely.</p><pre>Now connect to Strapi v5. I want to use it as my backend.</pre><pre>1. Install Strapi Client:<br>npm install @strapi/client</pre><pre>2. Create a file: src/data/strapi-sdk.ts with this exact code:</pre><pre>import { strapi } from &#39;@strapi/client&#39;;<br>import { getStrapiURL } from &quot;@/lib/utils&quot;;</pre><pre>const BASE_API_URL = getStrapiURL() + &quot;/api&quot;;<br>export const sdk = strapi({ baseURL: BASE_API_URL });<br></pre><pre>3. Update src/lib/utils.ts: </pre><pre>export function getStrapiURL() { <br>return process.env.VITE_STRAPI_URL || &quot;https://superb-freedom-8531c68dfe.strapiapp.com/&quot;; <br>}</pre><p>Ensure you click the implement.</p><p>After pasting this into Bolt.new, make sure to click Implement Plan.</p><p>Bolt will then:</p><ul><li>Install @strapi/client</li><li>Add the strapi-sdk.ts file</li><li>Update your utility file</li><li>Rebuild your project with the new dependencies</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-lJRvHyoJ_rDMS2A.png" /></figure><p>With the Strapi SDK configured, we’re ready to fetch real content from our CMS.</p><h3>Prompt 5 — Fetching and Displaying Content from Strapi</h3><p>With the Strapi client SDK now installed and configured in your Bolt.new project, the next step is to fetch real content from your Strapi backend and display it in the UI.</p><p>This is where your project transitions from a static prototype into a dynamic, CMS-driven application.</p><h3>(Optional) Generate OpenAPI Specification of your Project</h3><p>To give Bolt.new additional context about your available endpoints, you can generate an <a href="https://docs.strapi.io/cms/api/openapi">OpenAPI specification</a> for your Strapi project.</p><p>This documentation describes all of your API routes, request parameters, and response structures without requiring source code access.</p><p>This step is optional, but helpful if your content types are complex.</p><p>Run the command to generate the JSON OpenAPI specification</p><pre>npm run strapi openapi generate<br># or <br>yarn strapi openapi generate</pre><p>Because Bolt.new has a limited <a href="https://support.bolt.new/building/intro-llms">context window</a>, providing the entire OpenAPI file may consume unnecessary tokens for this tutorial.</p><p>Feel free to skip it unless you need deep endpoint documentation inside Bolt.</p><h3>Fetching Basic Data from Strapi</h3><p>Let’s begin by fetching our Blog content from Strapi. When you hit your Strapi API directly, a response will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7ebRfCqtycF_h-jo.png" /></figure><p>For this tutorial, we will fetch:</p><ol><li>All Blogs (Blog collection type): (with related entities from Dynamic Zones, banners, authors, categories, tags, and SEO metadata)</li></ol><pre>/blogs?populate[dynamic_zone][on][dynamic-zone.faq-block][populate][faqs]=true&amp;populate[banner]=true&amp;populate[author]=true&amp;populate[category]=true&amp;populate[tags]=true&amp;populate[seo]=true</pre><ol><li>A Single Blog by Slug</li></ol><pre>/blogs?filters[slug][$eq]=slug-value</pre><p>These two endpoints are enough to build a blog listing page and a blog details page. Feel free to add more.</p><h3>Prompting Bolt.new to Implement Blog Fetching</h3><p>Now that the API endpoints are ready, we’ll instruct Bolt.new to:</p><ul><li>Create a dedicated API file</li><li>Add getBlogs() and getBlogBySlug() functions</li><li>Use the Strapi SDK we configured earlier</li><li>Update the blog page to consume real data</li><li>Keep the existing dummy data for fallback purposes</li></ul><p>Switch to Plan Mode, and then paste this prompt:</p><pre>Using the previously created SDK in data/strapi-sdk.ts</pre><pre>create a new file inside data/api.ts</pre><pre>Add the function:</pre><pre>- getBlogs(): fetch `/blogs?populate[dynamic_zone][on][dynamic-zone.faq-block][populate][faqs]=true&amp;populate[banner]=true&amp;populate[author]=true&amp;populate[category]=true&amp;populate[tags]=true&amp;populate[seo]=true`</pre><pre>- getBlogBySlug(slug): fetch `/blogs?filters[slug][$eq]=slug-value)`</pre><pre>Use async/await and return typed JSON. </pre><pre>Update the blog page with the new data. Leave the dummy data as it is.</pre><p>Keeping the dummy data ensures your app remains functional even if the Strapi server is cold-starting (common on the free tier) or temporarily unreachable.</p><h3>Fixing Errors in Bolt.new</h3><p>Once Bolt.new implements the Strapi fetching logic, you may run into errors.</p><p>This is normal, especially when combining AI-generated code with a live backend. The key is learning how to debug efficiently without falling into infinite “Fix this” loops, which can quickly burn tokens and break working code.</p><p>Here’s the error we encountered when Bolt attempted to fetch Blog data from the Strapi backend:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Td4DykfYCOIb_13d.png" /></figure><p>We can use 3 ways to resolve this issue:</p><ul><li>Discuss the error directly with Bolt</li><li>Use the Highlight tool to target exactly where the fix is needed</li><li>Fix the issue manually in your code when Bolt gets stuck</li></ul><p>Let’s walk through how each one helped (and sometimes didn’t).</p><h3>1. Discuss the Error with Bolt</h3><p>The first attempt was to paste the error message directly into Bolt and ask it to resolve it.</p><p>Bolt responded, but suggested using Bolt Database, its built-in backend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JiQIdclrXjqI3NJe.png" /></figure><p>This wasn’t helpful, because our goal is to use Strapi, not Bolt Database.</p><p>This is common: when Bolt doesn’t understand the source of a backend error, it sometimes defaults to suggesting its internal database.</p><h3>2. Use the Highlight Tool for Targeted Fixes</h3><p>The next approach was to use Bolt.new’s Highlight tool.</p><p>This allows you to mark a specific line or file and tell Bolt exactly what to fix, instead of letting it rewrite unrelated parts of your project.</p><p>We highlighted the import where the Strapi Client was used and asked Bolt to reinstall or repair it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0GgSHF03DRrunWwb.png" /></figure><p>This is one of the most reliable debugging techniques in Bolt because it prevents the AI from over-correcting or introducing new regressions.</p><h3>3. When Bolt Gets Stuck: Manual Fix + Refresh</h3><p>Even after discussing the error and using Highlights, the issue persisted.</p><p>This happens occasionally because Bolt runs in a browser environment and can sometimes get stuck in an inconsistent state.</p><p>A page reload of the Bolt IDE resolved it.</p><h3>Final Results</h3><p>After reviewing the generated code, I noticed the root cause. Bolt had used Strapi v4 response formatting instead of the new flat Strapi 5 response format, specifically, the Strapi 4 <a href="https://strapi.io/blog/what-is-new-for-developers-in-strapi-5-top-10-changes">deprecated</a> .attributes field.</p><p>Strapi v5 no longer wraps content in .attributes, so any code referencing it will break.</p><p>We highlighted the incorrect usage and asked Bolt to remove it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hlJPIUHUxH6AQ-4Z.png" /></figure><pre>Please remove the .attributes as we are using Strapi v5 and not v4.</pre><p>Once Bolt applied the fix, the blog data loaded correctly:</p><p><em>Fetched Data from Strapi Backend</em></p><blockquote><em>💡 NOTE Bolt implemented the </em><em>getBlogBySlug(slug) but did not create the Blog details page. You’ll need to explicitly prompt Bolt to add these.</em></blockquote><h3>Refining Your App (Dynamic Zones, Responsiveness, and UI Enhancements)</h3><p>With our Strapi integration working, the next step is to refine the UI and ensure the frontend correctly renders the dynamic content coming from the CMS.</p><h3>1. Handling Strapi Dynamic Zones and Components</h3><p>When navigating to a blog details page (via its slug), Bolt automatically uses the data coming from your Strapi dynamic zones, such as the FAQBlock.</p><p>In the demo below, you can see that:</p><ul><li>The FAQ entries from the dynamic zone are rendered correctly</li><li>The author’s email and other relational fields are pulled directly from Strapi</li><li>Bolt correctly uses the structured response returned by the Strapi CMS</li></ul><p><em>FAQ from Dynamic Zone</em></p><p>This is a major advantage of using Strapi’s modeling system. Bolt can generate UI components that map directly to your content types.</p><p>At this point, you can continue enhancing the UI by prompting Bolt to:</p><ul><li>Fetch and display global settings (from the GlobalSettings single type)</li><li>Add loaders for slow Strapi Cloud cold starts</li><li>Improve layout, typography, spacing, or animations</li><li>Build custom sections that adapt to the fields defined in Strapi</li></ul><p>Dynamic content gives your Bolt-generated site structure, and your prompts give it polish.</p><h3>2. Responsiveness</h3><p>Bolt-generated UIs sometimes look great on desktop but break or overlap on mobile. To fix this, use the Inspect or Highlight tools to point to exact elements that need adjustments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cOklFeAME5GNrzF9.png" /></figure><p>You can then provide targeted prompts such as:</p><pre>Make this section fully responsive for mobile and tablet.<br>Use Tailwind responsive utilities to adjust spacing, stacking, and font sizes.</pre><h3>3. Ask Bolt for Additional Features</h3><p>Once the core UI works, you can ask Bolt for improvement ideas. Using Plan Mode or Discussion Mode, ask:</p><pre>What features can improve this company website?</pre><p>Bolt may suggest enhancements such as:</p><ul><li>Interactive Demo and Playground Section</li><li>Community and Newsletter section</li><li>Resource Center</li><li>Built-in Chatbot and so on.</li></ul><h3>4. Using the Terminal</h3><p>Bolt.new includes an inline terminal that allows you to:</p><ul><li>Install dependencies (npm install swiper, etc.)</li><li>Run build or lint commands</li><li>Inspect logs during development</li></ul><p>This terminal is useful especially when installing third-party packages that Bolt doesn’t add automatically.</p><h3>5. Downloading your Code</h3><p>Before deploying or shipping your project, download your full codebase. This lets you:</p><ul><li>Review the architecture</li><li>Apply some security best practices</li><li>Clean up unused components or dependencies</li><li>Fix edge-case bugs</li><li>Customize the code beyond what Bolt can autogenerate</li><li>Commit to GitHub for version control</li></ul><p>Bolt.new is excellent for prototyping, but manual review ensures your final app is production-ready.</p><h3>Publishing Your Bolt.new Project</h3><p>Once everything looks good, you can publish directly from Bolt.new by clicking the Publish button at the top-right corner of the interface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nCqDd7g1BDpQu3bz.png" /></figure><p>Bolt will:</p><ul><li>Run a security audit</li><li>Check dependencies</li><li>Attempt to build and deploy your project</li><li>Generate a live, shareable link if successful</li></ul><p>If issues are detected, Bolt will suggest fixes, and you can attempt fixing them directly using Plan Mode or the Highlight tool.</p><p>Bolt will run a security audit. And if any issue is found, you will be advised to ask Bolt to fix it. If successful, Bolt will generate a shareable link to your live project.</p><h3>When Bolt Fails to Publish</h3><p>In some cases, Bolt may fail to publish your project. For example, my build failed due to a Turbopack limitation that commonly affects browser-based IDEs, and probably because Bolt.new generated my app in Next.js 13.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cAO-6qHnHMp_6Cz-.png" /></figure><p>If this happens, don’t worry, you still have a reliable deployment path using GitHub and Netlify.</p><h3>Connecting Your Project to GitHub</h3><p>Bolt.new provides a built-in GitHub integration that allows you to export your project directly into a new repository.</p><ul><li>Click the GitHub icon in the top-right corner.</li><li>Bolt will prompt you to authorize access to your GitHub account.</li><li>Choose a name for the new repository.</li><li>Bolt will push your complete project into GitHub.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6S4xHJDW5jSTFAtL.png" /></figure><p>After authorization, Bolt asks you to name the repo:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*t8us1qNThiXuD0dA.png" /></figure><p>Once the repo is created, you’re ready to deploy.</p><h3>Deploying Your Project on Netlify</h3><p>With the GitHub repository now available, deployment through Netlify becomes simple:</p><ol><li>Log in to Netlify.</li><li>Click <em>Add new project → Deploy from Git → Import an exising project</em>.</li><li>Select GitHub and choose the repository Bolt created.</li><li>Name your project (e.g., company-website-example).</li><li>Keep the default build settings for a Next.js app (Netlify auto-detects them).</li><li>Click Deploy.</li></ol><p>A few moments later, your site will be live! :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4cMy9Q23Gl5SjaWi.png" /></figure><h3>Bolt Prompting Best Practices</h3><p>Getting great results from Bolt.new is all about how you prompt. Below are the most effective best practices to help you build faster, avoid unnecessary token usage, and maintain consistent app quality.</p><ul><li>Start with a plan and build the foundation (Context): Begin with a clear blueprint and focus on the first component, such as defining a hero section with specific elements, so that Bolt establishes a consistent design foundation before adding other sections.</li><li>Break work into small, iterative steps (Step-wise): Divide complex builds into small tasks by adding components and styling in stages and verifying each change, so you can easily adjust or roll back individual parts rather than a large, mixed prompt.</li><li>Use precise design language and be explicit: Rather than vague descriptors like “make the text bigger,” use professional design terms such as “increase font weight” or “raise line height,” and specify margins, padding, or z‑index settings.</li><li>Leverage Bolt’s feedback (Chain-of-thought) and targeting tools: Use features such as Discussion Mode, the “Enhance prompt” option, multiple first‑draft prompts, and file/element targeting to refine your prompts and direct Bolt to work on only the intended sections</li><li>Reuse, customize, and ask Bolt to teach you: Store high‑performing prompts in the Prompt Library, set project or system prompts with consistent instructions, and have Bolt generate cheat sheets or enhanced prompts to expand your vocabulary and creative ideas.</li></ul><p>For more prompting strategies, check out Bolt’s official guide: <a href="https://bolt.new/blog/prompting-tips-for-bolt">👉 Prompting Tips for Bolt</a></p><h3>Pain Points of Using Bolt</h3><p>Bolt.new is a powerful tool for rapid prototyping and AI-assisted development, but it also comes with limitations you should be aware of, especially if you’re building more complex, full-stack applications.</p><h3>1. Free Tier Limitations</h3><p>The free plan works well for simple, one-shot prompts and small projects, as tokens are limited.</p><p>For full-stack apps or frontend + backend integrations, you’ll likely need to upgrade.</p><h3>2. Context Loss</h3><p>Refreshing Bolt’s IDE or inactive sessions can sometimes cause the AI to lose context, which means:</p><ul><li>The agent may forget recent decisions</li><li>You may need to re-explain your instructions</li><li>Some prompts must be repeated</li></ul><p>Using Plan Mode, file locking, and targeted prompts helps reduce this problem, but it still happens occasionally.</p><h3>3. Occasional Hallucinations or Context Drift</h3><p>Bolt sometimes forgets previous constraints or introduces inconsistencies. For example, suggesting Bolt Database instead of your actual backend (Strapi).</p><p>When this happens, using the Highlight tool or reverting via Version History is the best approach.</p><h3>4. Dependency or Version Mismatches</h3><p>In some cases, Bolt may install a different dependency version than requested.</p><p>For example, it generated the project using Next.js 13 even after specifying Next.js 15.</p><p>Always verify:</p><ul><li>package.json</li><li>Framework versions</li><li>Tailwind/TypeScript configs</li></ul><p>Before continuing with your build.</p><h3>5. Build Issues Inside the Browser IDE</h3><p>Because Bolt runs in a browser-based environment, not all toolchains are fully supported. For example, I upgraded to Next.js 16, but this triggered a Turbopack error:</p><pre>Error: `turbo.createProject` is not supported by the wasm bindings.</pre><p>This appears to be a limitation of running Turbopack inside a WebAssembly environment. Fortunately, Bolt’s Version History allowed rolling back to a working version.</p><h3>6. Recommendations for Bolt Database</h3><p>When Bolt encounters backend-related errors, it sometimes suggests switching to Bolt Database, even when you’re intentionally using a custom backend like Strapi.</p><p>This isn’t harmful, but it can derail your debugging if you don’t catch it early.</p><h3>GitHub Repo, Live App, and Bolt Project Links</h3><ul><li>GitHub Repo: <a href="https://github.com/Theodore-Kelechukwu-Onyejiaku/company-website">https://github.com/Theodore-Kelechukwu-Onyejiaku/company-website</a></li><li>Live App on Netlify: <a href="https://company-website-example.netlify.app/">https://company-website-example.netlify.app/</a></li><li>Bolt Project Link: <a href="https://bolt.new/~/sb1-epr7g8v7">https://bolt.new/~/sb1-epr7g8v7</a></li></ul><blockquote><em>👋 NOTE: We used the free version of Strapi Cloud. So, give some time before the Blog data load as your Strapi server spins up.</em></blockquote><h3>Final Thoughts</h3><p>Suppose there is one lesson from this project. It would be that Bolt works best when you work in small, controlled steps.</p><p>That way, you can easily revert, update, and maintain your code without consuming too many tokens.</p><p>You can use the Free plan for experimentation, UI generation, or quick prototypes, but full-stack or multi-page applications benefit heavily from the paid tiers.</p><p>But for production-grade, enterprise-level projects, I will always take ownership of the core business logic, security patterns, API integrations, and performance considerations.</p><p>Bolt speeds up the work. It doesn’t replace the work.</p><h3>Conclusion</h3><p>In this two-part series, you learned how to use vibe coding principles and Bolt.new’s interface, modes, and prompting techniques to generate a full UI scaffold and connect it to a real Strapi backend. You also fetched dynamic content, debugged common issues, and deployed the final application using GitHub and Netlify.</p><p>Here are some next steps for your project:</p><ul><li>Ask Bolt to fetch the Global Data (GlobalSettings single type) of the company website in your Strapi backend:</li></ul><pre>/global-setting?populate[0]=footer&amp;populate[1]=footer.links&amp;populate[2]=header&amp;populate[3]=header.links&amp;populate[4]=defaultSEO&amp;populate[5]=socialLinks&amp;populate[6]=address</pre><ul><li>Ask Bolt to implement Light, Dark, and System Modes.</li><li>Set up the <a href="https://docs.strapi.io/cms/features/preview">frontend preview</a> in your Strapi backend</li><li>Ask Bolt to update or create data inside Strapi</li><li>Export your code locally and improve it.</li></ul><p>Bolt.new is a great platform. However, it’s not a full replacement for human designers and developers, at least not yet. The platform should be best used for experimentation, concept generation, and quick MVPs rather than enterprise-ready sites.</p><p>If you’re ready to explore the future of website building, Bolt.new is an exciting place to start, but keep your creative and technical instincts close by.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7c0c13270c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a Company Website with Bolt.new and Strapi 5 - Part 1]]></title>
            <link>https://medium.com/strapi/build-a-company-website-with-bolt-new-and-strapi-5-part-1-db0bbab14956?source=rss-9323ef8b74c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/db0bbab14956</guid>
            <category><![CDATA[vibe-coding]]></category>
            <category><![CDATA[strapi]]></category>
            <category><![CDATA[bolt]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Theodore Kelechukwu Onyejiaku]]></dc:creator>
            <pubDate>Fri, 14 Nov 2025 17:11:59 GMT</pubDate>
            <atom:updated>2025-11-14T17:11:59.352Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build a Company Website with Bolt.new and Strapi 5 — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IT2cIn0LGOqiQYjBelwjUw.png" /></figure><h3>Introduction</h3><p>If you’ve ever sat back and watched your AI write code for you, you’re not alone. This practice is often called vibe coding, a term popularized by Andrej Karpathy that captures AI-assisted development.</p><p>AI-assisted development tools like Bolt.new, v0 by Vercel, Lovable, and so on can speed up your app development from “idea” to “live prototype” in minutes.</p><p>In this guide, you’ll learn how to combine Bolt.new and Strapi 5 to build a full-stack app that fetches content from a real CMS, using Next.js as the frontend framework, giving you hands-on experience with vibe coding.</p><h3>Tutorial Parts</h3><p>This tutorial is divided into two parts:</p><ul><li>Part 1 — Planning and Building the Frontend: Using Bolt.new and Strapi 5.</li><li><a href="https://strapi.io/blog/build-a-company-website-with-bolt-new-and-strapi5-part-2">Part 2 — Connecting Bolt.new to Strapi API and Deploying to Netlify</a>.</li></ul><h3>What We will Build</h3><p>We will build a company website using Bolt.new. And by the end of this tutorial, you will have:</p><ul><li>A website that fetches dynamic content from a real Strapi backend.</li><li>A practical understanding of how to prompt, refine and structure AI-generated code with Bolt.new</li><li>A clean foundation you can extend to any web application.</li></ul><p><a href="https://delicate-dawn-ac25646e6d.media.strapiapp.com/Pages_Created_By_Bolt_d86141aab4.mp4">https://delicate-dawn-ac25646e6d.media.strapiapp.com/Pages_Created_By_Bolt_d86141aab4.mp4</a></p><p><em>Project Demo</em></p><h3>Prerequisites</h3><p>To follow along, make sure you have:</p><ul><li>Basic Familiarity with HTML, CSS, and JavaScript: Knowing how to work with basic HTML, CSS, and JavaScript will help you understand how the generated code works.</li><li>Experience with Next.js. You can learn more about Next.js by building a real-life project in <a href="https://strapi.io/blog/epic-next-js-15-tutorial-part-1-learn-next-js-by-building-a-real-life-project">this tutorial series</a>.</li><li>A <a href="https://bolt.new/">Bolt account</a>.</li></ul><h3>What is Vibe Coding?</h3><p>Vibe coding is a term coined by <a href="https://en.wikipedia.org/wiki/Andrej_Karpathy">Andrej Karpathy</a>, in a famous <a href="https://strapi.io/blog/build-a-company-website-with-bolt-new-and-strapi5-part-1">Twitter post</a>, to describe the trend of letting AI “take the wheel” when writing code.</p><p>Vibe coding means collaborating with AI tools by giving them intent and refining the results through iteration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VG9uZU12E3Wvejii.png" /></figure><p>This doesn’t mean outsourcing your thinking, but about using AI as a pair programmer that can help accelerate your ideation, prototyping and debugging.</p><h3>What is Bolt?</h3><p>Bolt is an AI-powered builder for creating web and mobile apps directly from natural language prompts.</p><p>It allows developers to:</p><ul><li>Generate full-stack apps in real time with no external editor required.</li><li>Integrate with design tools like Figma for UI consistency.</li><li>Add functionality easily through built-in integrations such as Stripe for payments or GitHub for version control.</li><li>Prototype across platforms,</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7GNLxh2lkLgeJtW1.png" /></figure><h3>How Does Bolt Work?</h3><p>Bolt works through prompt-based development. You describe what you want to create.</p><p>For example, when you give it the prompt:</p><pre>Build a marketing website for a design agency using Next.js and Tailwind CSS.</pre><p>From there, Bolt:</p><ul><li>Generates the code for your request.</li><li>Runs it instantly in a built-in preview environment.</li><li>Allows you to refine or debug using natural language commands.</li></ul><p>You can edit files directly, switch agents (like Claude or v1 Agent), and view the live results in seconds without leaving your browser.</p><h3>Bolt.new Alternatives</h3><p>While Bolt.new is one of the most polished AI app builders available, several alternatives explore similar concepts with unique approaches.</p><p>Some Bolt.new alternatives include, <a href="https://strapi.io/blog/how-to-build-a-frontend-with-lovable-dev-for-your-strapi-backend">Lovable.dev</a>, <a href="https://strapi.io/blog/building-a-page-builder-via-content-modeling-best-practices-in-strapi5">v0 by Vercel</a>, Replit Agent and so on.</p><p>Each tool shares the same goal; to let developers move from idea to implementation faster, while maintaining creative control.</p><h3>Bolt’s User Interface and Features</h3><p>Bolt.new’s interface is designed to make AI-assisted development intuitive, visual, and context-aware.</p><p>Here is a quick rundown of Bolt’s user interface and some key features:</p><h3>Interacting with Bolt AI</h3><p>Bolt’s interface is centered around an AI workspace where you can chat, plan, and edit code in real time. From the left-hand menu, you can view your projects and select which AI agent you want to work with:</p><ul><li>Claude Agent → uses Plan Mode, ideal for structured planning, step-by-step discussions, and scoped implementation.</li><li>v1 Agent (Legacy) → uses Discussion Mode, suited for open-ended conversations and quick edits.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J0HOj1cf0X9uuBzl.png" /></figure><p>You can attach files, insert reusable prompts, and clear context when switching topics, ensuring the AI stays focused and efficient.</p><h3>Projects and Files in Bolt</h3><p>Bolt makes managing and organizing your projects straightforward:</p><ul><li>Create, rename, or delete projects directly from the main sidebar or project header.</li><li>Access settings for hosting, analytics, and environment configuration.</li><li>Edit files using the Code view or upload assets such as images, videos, or documents.</li></ul><p>You can also export a project locally or duplicate it to preserve specific configurations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HY0GoodGqgN8Q-Go.png" /></figure><p>Lock and Target Features</p><ul><li>Lock: Protects key files or code blocks from unintended edits.</li><li>Target: Focuses Bolt’s attention on a specific file, preventing broad rewrites that waste tokens.</li></ul><p>These tools are crucial for maintaining control as your project grows in complexity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cRy-c8Dw2_OisFO7.png" /></figure><p>Other features include code highlighting and inspection.</p><h3>Backups and Reverting Changes in Bolt</h3><p>Bolt automatically saves backups and maintains a version history, so you can restore previous states without overwriting the current version.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RVcjEwJGqbUWIx2l.png" /></figure><h3>Browser Support</h3><p>Bolt runs best on Chromium-based browsers such as Chrome, Edge, Brave, Vivaldi, or Opera. Mobile browsers are currently not fully supported.</p><h3>Integration and Database Support</h3><p>Bolt supports third-party integrations for authentication, payments, analytics, and design systems. For databases, you can choose between:</p><ul><li>Bolt Cloud Database: a built-in, no-setup option for quick prototyping.</li><li>Supabase Integration: for developers who need SQL capabilities or external data access.</li></ul><h3>Publishing Your Project</h3><p>Beefore August 14, 2025, all Bolt projects were deployed using Netlify by default. Today, you can export, connect custom hosting, or deploy through supported CI/CD workflows.</p><p>This lets you choose between instant preview deployments and production-ready builds, depending on your project’s scope.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8zJMC_OZUdMgbDgs.png" /></figure><h3>Tokens — The Fuel for Vibe Coding</h3><p>To interact with Bolt or any AI-powered coding environment, you need <a href="https://docs.claude.com/en/docs/about-claude/glossary#tokens">tokens</a>. Tokens are the smallest units of text (like words or characters) that an AI model processes.</p><p>Think of tokens as the “fuel” for your vibe coding or AI development session.</p><p>Every time you send a message, receive code, or ask Bolt to analyze your files, tokens are consumed, just like API calls consume bandwidth.</p><h3>Maximizing Token Usage in Bolt</h3><p>Efficient token management can make a huge difference, especially in large or collaborative projects.</p><p>To learn more about token optimization, visit the <a href="https://support.bolt.new/best-practices/maximizing-token-efficiency">Maximizing Token Efficiency</a> guide by Bolt. Here is the summary:</p><ol><li>Plan your app</li><li>Use Discussion mode</li><li>Undo changes using the Version history feature</li><li>Keep your prompts specific and focused</li><li>Avoid repeated automated error fix attempts</li><li>Add functionality incrementally</li><li>Use the .bolt/ignore file</li><li>Reduce the size of your project</li></ol><p>Let’s discuss Bolt pricing for token usage.</p><h3>Bolt Pricing Plans</h3><p>Bolt’s pricing is based directly on token usage. Each plan determines how many tokens you can use.</p><p>As of this writing, Bolt offers four main plans:</p><ul><li>Free plan: Includes 1M tokens per month and public/private projects</li><li>Pro plan: Most popular. Costs $25/month for 1M tokens and includes more features.</li><li>Teams plan: $30 per member. Everything in Pro with each member receiving a monthly token allotment.</li><li>Custom plan: Custom pricing is for larger organizations.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gfTCKxJmib36CtU9.png" /></figure><p>For this tutorial, we’ll use the Teams plan, which includes 10M tokens per month. The Teams plan is ideal for longer and multi-prompt workflows.</p><p>If you’re just experimenting, the Free plan is perfect for quick prototypes and learning how token budgeting works.</p><p>Visit Bolt’s <a href="https://bolt.new/pricing">pricing page</a> to learn more.</p><h3>General Prompting Techniques</h3><p>Before you start vibe coding, it’s important to understand how to communicate effectively with your AI.</p><p>Here are nine general prompting techniques that can dramatically improve of AI-generated results.</p><ol><li>Context Layering: Give your AI the full project context.</li><li>Stepwise Prompting: Don’t dump everything at once on your AI. Break big tasks into chunks</li><li>Role Assignment: You should give the AI its persona.</li><li>Constraint Anchoring: Give the AI clear boundaries and requirements.</li><li>Comparative Prompting: Ask your AI to generate multiple distinct solutions for a single problem.</li><li>Chain-of-Thought Emulation: Ask the AI to explain its reasoning before generating your code.</li><li>Error-Forward Prompting: Forward your errors, stack traces, and linting messages to your AI to leverage its pattern recognition for quick debugging solutions.</li><li>Pattern Extension: Use examples of existing code conventions to teach AI to generate new code that matches your project’s style and structure.</li><li>Asking your AI: This option is very useful if you are struggling to articulate your prompt.</li></ol><p>Using Bolt, we will be combining most of these techniques to achieve better results. So, let’s look at the best practices when using Bolt.</p><h3>Strapi Project Overview and Setup: Company Website</h3><blockquote><em>👋 NOTE: You can skip this section if you already have a live Strapi Cloud project running.</em></blockquote><p>Before we generate our frontend with Bolt.new, we need a backend that Bolt can connect to.</p><p>In this tutorial, we will be using a <a href="https://strapi.io/blog/building-a-page-builder-via-content-modeling-best-practices-in-strapi5">Company Website</a> as an example. Below are the content models and relationships that make up its structure.</p><h3>Content Model Overview</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VePymx6Fg-wvmrEw.png" /></figure><p><em>Diagram 1: Content Model Types</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fNh0UZQluRCBDVS1.png" /></figure><p><em>Diagram 2: Content Models and Relationships</em></p><p>In the first diagram, we specified the content model types. And in the second diagram, we have the relationships between every model.</p><h3>Setting up your Strapi Project</h3><p>We’ll start with a ready-made Strapi project that includes seed data and configurations. You can run this locally or deploy it directly to Strapi Cloud.</p><p>So, let’s use a Strapi page builder <a href="https://github.com/Theodore-Kelechukwu-Onyejiaku/strapi5-page-builder-example">Company website example</a>.</p><p>Step 1: Clone the Example Project Clone the Strapi company website example from GitHub:</p><pre>git clone https://github.com/Theodore-Kelechukwu-Onyejiaku/strapi5-page-builder-example.git</pre><p>Inside the cloned project, you’ll find a file named company-website-data.tar.gz. This archive contains seed data that will pre-populate your Strapi app thereby saving time on manual content creation.</p><p>Step 2: Install Dependencies Install all required dependencies using either npm or yarn:</p><pre>npm install<br>#or<br>yarn install</pre><p>Step 3: Populate Strapi Project with Seed Data Next, populate your Strapi project using the provided seed data file:</p><pre>npm run strapi import -- -f company-website-data.tar.gz<br># or <br>yarn strapi import -f company-website-data.tar.gz</pre><p>This command automatically imports the prebuilt content models and sample data.</p><p>Step 4. Start Strapi Project Once the dependencies are installed and data imported, start your local server:</p><pre>npm run dev</pre><p>You should now have a working Strapi instance with preloaded content:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7kV9YdxkG1pxcDCX.png" /></figure><p>Step 5. Deploy to Strapi Cloud Hosting your Strapi instance on Strapi Cloud makes it publicly accessible. This is essential for connecting Bolt.new to a real CMS API.</p><p>Now, you can decide to host your project on <a href="https://strapi.io/cloud">Strapi cloud</a>. Check out this guide on Strapi cloud <a href="https://docs.strapi.io/cloud/getting-started/deployment-options">deployment options</a> or see the video below.</p><p>Follow the <a href="https://strapi.io/cloud">Strapi Cloud</a> deployment <a href="https://docs.strapi.io/cloud/getting-started/deployment-options">guide</a> or watch this quick video overview:</p><p>Play</p><p>Step 6. Transfer Local Data to Strapi Cloud Once deployed, we’ll transfer our local data to the cloud instance. First, create a Transfer Token from your Strapi Cloud dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2-blu8tt7iAZkrp8.png" /></figure><p>Then, run the transfer command, replacing the destination URL with your Strapi Cloud project URL:</p><pre>npm run strapi transfer -- --to destinationURL</pre><pre># or</pre><pre>yarn strapi transfer --to destinationURL</pre><p>In this tutorial, our destinationURL is https://superb-freedom-8531c68dfe.strapiapp.com/admin. So we will run the command below:</p><pre>npm run strapi transfer -- --to https://superb-freedom-8531c68dfe.strapiapp.com/admin</pre><p>When prompted, paste in your transfer token, which you created earlier. After a successful transfer, you’ll see the following confirmation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ocCE4UZQTk9jQAnR.png" /></figure><p>You can now verify the imported content in your Strapi Cloud dashboard:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*On0ZhAMQjuC6oon0.png" /></figure><p>Visit the <a href="https://docs.strapi.io/cms/data-management/transfer#setup-and-run-the-data-transfer">Data Transfer guide</a> to learn more about Data transfer in Strapi.</p><p>With your Strapi backend running on the cloud, your API is now publicly accessible.</p><p>This means you can connect Bolt.new to your Strapi project’s API URL, thus allowing you to build and preview your frontend dynamically.</p><p>In the next section, we’ll prompt Bolt to generate our frontend using this Strapi API as the backend.</p><h3>Prompt 1 — Planning your App</h3><p>Before diving into code, it’s good practice to help your AI tool understand the context and goal of your project.</p><p>In this case, we’ll start by using ChatGPT to help us write a clear, well-scoped prompt for Bolt.new.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eu0MIvMBZteAAiEu.png" /></figure><h3>Step 1: Generate a Prompt with Context</h3><p>To make Bolt.new more effective, we first “prime” ChatGPT with context, telling it what Bolt is, what we’re building, and what stack we’re using.</p><p>Then, we ask it to create a structured prompt for our company landing page.</p><p>Here’s the resulting prompt:</p><pre>I want to generate a visually creative and complex AI-based company landing page with Bolt.new.</pre><pre>Can you generate the prompt for a very complex landing page with amazing designs and be as creative as you possibly can? The tech stack is Next.js 15, TypeScript, and Tailwind CSS. </pre><pre>Let&#39;s start with the landing page for now. Other pages can come in later.</pre><h3>Step 2: Run the Prompt in Bolt.new</h3><p>Now, copy and paste the prompt into Bolt.new. Within seconds, Bolt generates a complete landing page using Next.js, TypeScript, and Tailwind CSS, all scaffolded automatically.</p><p><em>Landing page from Bolt.new</em></p><p>This is a best practice when working with AI tools: start small and foundational.</p><p>By focusing on a single page first, you allow Bolt to establish consistent styling and structure. This sets a strong base for future iterations.</p><p><a href="https://gist.github.com/Theodore-Kelechukwu-Onyejiaku/b100914f424f393cde75b5a2c740eafd"><em>→ View Full Prompt 1 on GitHub gist.</em></a></p><h3>Prompt 2 — Iterative Steps</h3><p>Now that Bolt has built the landing page, we’ll add structure incrementally. This iterative process helps you guide the AI’s creativity while keeping full control of the design and logic.</p><p>For this step, we’ll focus on creating the Header component. Bolt already generated a Footer component automatically, so we’ll only prompt it for the header.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qCTZOlY9U9i8QJmH.png" /></figure><p>Once again, we use ChatGPT to refine the header prompt and then paste it into Bolt.new.</p><p>After a few seconds, we get a responsive, fully functional header layout.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dYkGsp_T1JxtdihX.png" /></figure><p><a href="https://gist.github.com/Theodore-Kelechukwu-Onyejiaku/141e0ccb57acf9ebd45454cc4ade9502"><em>→ View Full Prompt 2 on GitHub gist.</em></a></p><p>This step-by-step approach of generating, previewing, and refining reflects the vibe-coding mindset. This mindset means collaborating with your AI, not just instructing it.</p><h3>Prompt 3 — Creating Additional Pages with Plan/Discussion Mode</h3><p>With the header and landing page ready, it’s time to extend the project.</p><p>Here we’ll leverage Bolt’s Plan Mode, which lets you discuss your codebase, generate ideas, and make controlled updates without consuming too many tokens.</p><p>Because we’re using the Claude Agent, only Plan Mode is available (the legacy v1 Agent uses Discussion Mode).</p><h3>Step 1. Ask Bolt to Generate a Plan</h3><p>Prompt Bolt to identify other pages to create:</p><pre>Now that I have the landing page and a header component, what other pages can you generate?</pre><p>Bolt will propose a project plan. If you’re satisfied, you can implement it directly by clicking “Implement Plan”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*14qVQ60675ztrYCd.png" /></figure><h3>Step 2. Adjust for Strapi Integration</h3><p>In our case, Bolt suggested using the Bolt Database for persistence. However, since we already have Strapi as our backend, we’ll correct that with another prompt:</p><pre>I want you to create only the pages and use only mock data. Don&#39;t integrate Bolt Database backend and authentication</pre><blockquote><em>💡 Tip: Bolt may occasionally hallucinate (generate irrelevant results). Keep refining your prompts in Plan Mode until it meets your requirements.</em></blockquote><h3>Step 3. Debug and Refine with the Select/Inspect Tool</h3><p>After the new pages are created, you may notice small layout bugs.</p><p>For example:</p><ul><li>The header disappears when navigating between pages.</li><li>The announcement bar is misaligned.</li></ul><p>Instead of manually hunting for the issues, use Bolt’s Select/Inspect tool for targeted fixes. This tool lets you visually select an element and prompt Bolt to adjust just that component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jsOCGqH07F2wXbsw.png" /></figure><p>For example:</p><pre>The Header component disappears upon scrolling or clicking to other pages. Please fix only this.</pre><p>Then, to simplify the UI for now:</p><pre>Now remove the announcement bar for now.</pre><p>And when we preview our app, we can see that the Header component works and that all pages are working.</p><p><em>Other Pages Created by Bolt</em></p><p>Next, let’s connect with Strapi backend!</p><h3>Wrapping Up Part 1</h3><p>In this first part of the series, we explored the concept of vibe-coding and learned how to use Bolt.new alongside Strapi 5 to set up a real CMS backend and generate the initial version of our company website’s frontend.</p><p>We covered Bolt’s interface, features, and prompting best practices while preparing a Strapi Cloud project as the foundation for integration. With our backend ready and frontend structure in place, we’ve built a strong starting point for a full-stack project.</p><p>In the next part, we’ll connect the Bolt-generated frontend to Strapi’s API, fetch live data, and publish our project to Netlify. Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db0bbab14956" width="1" height="1" alt=""><hr><p><a href="https://medium.com/strapi/build-a-company-website-with-bolt-new-and-strapi-5-part-1-db0bbab14956">Build a Company Website with Bolt.new and Strapi 5 - Part 1</a> was originally published in <a href="https://medium.com/strapi">Strapi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Strapi Email and Password Authentication with Next.js 15: Part 1]]></title>
            <link>https://medium.com/strapi/strapi-email-and-password-authentication-with-next-js-15-part-1-6428ccd653c0?source=rss-9323ef8b74c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/6428ccd653c0</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[sendgrid]]></category>
            <category><![CDATA[strapi]]></category>
            <dc:creator><![CDATA[Theodore Kelechukwu Onyejiaku]]></dc:creator>
            <pubDate>Thu, 01 May 2025 16:39:59 GMT</pubDate>
            <atom:updated>2025-05-01T16:39:59.043Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LOX3Yog9ADjHMP0tJ3FYYg.png" /></figure><h3>Introduction</h3><p>Most applications require that an individual is verified and permitted to access resources. This ensures the security of the app.</p><p>Strapi provides you with authentication mechanisms which include email and password, AuthO, AWS Cognito, GitHub, Google, etc. through its <a href="https://docs.strapi.io/cms/configurations/users-and-permissions-providers">Users and Permissions providers</a> feature. Thus, authentication bottlenecks are solved using Strapi.</p><p><a href="https://strapi.io/integrations/nextjs-cms">Next.js</a>, on the other hand, is a popular frontend framework that allows users to build applications with the power of React components. It also supports authentication, session management, and authorization through Middleware, Data Access Layer, and Data Object Layer. Learn more <a href="https://nextjs.org/docs/app/guides/authentication#authorization">here</a>.</p><p>In this tutorial, you will learn how to implement Strapi email and password authentication with a Next.js frontend.</p><h3>Tutorial Series</h3><p>We will divide this tutorial into two series:</p><ul><li>Part 1 - Email and Password registration, Email confirmation, and Login</li><li>Part 2 - Session Management, Data Access, password reset, and changing password</li></ul><h3>GitHub Repository: Full Code for Strapi and Next.js Authentication Project</h3><p>The complete code for this project can be found in this repo: <a href="https://github.com/Theodore-Kelechukwu-Onyejiaku/strapi-email-and--password-authentication">strapi-email-and-password-authentication</a></p><h3>Tutorial Goals</h3><p>In this tutorial, here are the concepts we will cover:</p><ol><li>Strapi Email and Password registration (signup) flow.</li><li>Strapi Email confirmation flow.</li><li>Strapi Email and Password Login (sign-in) flow</li><li>Strapi Forgot Password flow</li><li>Strapi Reset password flow</li><li>Changing Password in Strapi with Authorization</li><li>Next.js server actions, authentication, session management, middleware, and data access layer.</li></ol><h3>Prerequisites</h3><p>Before we begin, ensure you have the following:</p><ul><li><a href="https://nodejs.org/">Node.js</a> runtime: Only Active LTS or Maintenance LTS versions are supported (currently v18, v20, and v22).</li><li>A basic knowledge of Next.js and <a href="https://strapi.io/integrations/react-cms">React</a> should suffice.</li><li>A SendGrid API Key. Visit this <a href="https://www.twilio.com/docs/sendgrid/ui/account-and-settings/api-keys">page</a> to learn how to get yours.</li><li>Optionally, a HTTP client. <a href="https://www.postman.com/">Postman</a> is recommended.</li></ul><h3>Introduction to Strapi Email and Password Authentication</h3><p>Authentication refers to the process of verifying that an entity has the correct credentials or permission to access resources.</p><p><a href="https://strapi.io/">Strapi</a> offers multiple authentication methods to secure your application:</p><ol><li><a href="https://docs.strapi.io/cms/features/users-permissions">Users &amp; Permissions Plugin</a>: This is Strapi&#39;s built-in authentication system that provides email/password authentication, role-based access control, and third-party provider authentication.</li><li><a href="https://docs.strapi.io/cms/features/api-tokens">API Tokens</a>: This allows authenticating <a href="https://strapi.io/features/customizable-api">REST and GraphQL API</a> queries without user accounts, different token types such as read-only, full access, or custom.</li><li><a href="https://docs.strapi.io/cms/configurations/users-and-permissions-providers">Third-Party Authentication Providers</a>: Strapi supports numerous third-party authentication providers through the Users &amp; Permissions plugin: Social providers: Facebook, Google, Twitter, GitHub, Discord, Twitch, Instagram, VK, LinkedIn, Reddit Enterprise providers: Auth0, AWS Cognito, etc.</li><li><a href="https://docs.strapi.io/cms/features/sso">Single Sign-On (SSO)</a>: For enterprise users, Strapi offers SSO capabilities: Available with Enterprise plan. SSO allows administrators to authenticate through an identity provider (e.g. Microsoft Azure Active Directory).</li></ol><p>The email and password authentication in Strapi uses the Users &amp; Permissions plugin and follows RESTful API patterns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UmC48n2NkzOF-D3C.png" /></figure><p>If you are interested in knowing the concepts without digging into the technical aspect of this tutorial, please visit this <a href="https://docs.strapi.io/cms/configurations/users-and-permissions-providers/new-provider-guide">documentation page</a>.</p><p>Now, let&#39;s install Strapi!</p><h3>Strapi Installation and Setup</h3><p>Create a folder where both your Strapi and Next.js app will reside. Give it any name.</p><h3>Strapi Installation</h3><p>Let&#39;s begin by installing Strapi. To create a new Strapi project, run the command below in your terminal. Ensure you are in the directory where you want to keep both your Strapi backend and Next.js frontend.</p><pre>npx create-strapi@latest</pre><p>The command above will be followed with some questions from the terminal.</p><p>Depending on your preferred setup, you can select the answer you want. Here are the answers for this project.</p><pre>? What is the name of your project? strapi-backend<br>...<br>? Please log in or sign up. Skip<br>? Do you want to use the default database (sqlite) ? Yes<br>? Start with an example structure &amp; data? No<br>? Start with Typescript? Yes<br>? Install dependencies with npm? Yes<br>? Initialize a git repository? No</pre><blockquote><em>NOTE: The name of the project is </em><em>strapi-backend.</em></blockquote><h3>Start Strapi Development Server</h3><p>Once you have successfully installed Strapi, cd into your strapi project and run the Strapi develop command.</p><pre>cd strapi-backend<br>npm run develop</pre><p>This should start up your Strapi application in the URL: http://localhost:1337/admin. Enter your new admin credentials to continue.</p><p>This is what your Strapi dashboard should look like after registering the new admin:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iqvSy8_s_qJwAw_7.png" /></figure><p>To learn more about creating a Strapi project, read the <a href="https://docs.strapi.io/cms/installation/cli">Strapi CLI documentation</a> page.</p><p>In the next section, we will configure the Strapi email plugin to allow us to send emails.</p><h3>Configuring Strapi Email Plugin with SendGrid (Step-by-Step)</h3><p>In this project, you will need the <a href="https://docs.strapi.io/cms/features/email">Strapi Email plugin</a> to send emails.</p><p>For example, a confirmation email will be sent to a user when they register or sign up. So, you need to configure your Strapi Email plugin.</p><p>When you head over to <em>Settings &gt; Email Plugin &gt; Configuration</em> as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tv-xeTCDzo_-gQ_A.png" /></figure><p>You will notice that the default email provider is sendmail, this is for local development. However, for production-ready applications, we will be using <a href="https://sendgrid.com/">SendGrid</a> as our email provider.</p><h3>Install SendGrid provider</h3><p><a href="https://docs.strapi.io/cms/providers">Providers</a> can be installed using npm or yarn using the following format @strapi/provider-&lt;plugin&gt;-&lt;provider&gt; --save.</p><p>Install the <a href="https://market.strapi.io/providers/@strapi-provider-email-sendgrid">SendGrid email provider</a> which is available in the Strapi marketplace in your Strapi backend project by running the command below:</p><pre>npm i @strapi/provider-email-sendgrid</pre><p>Upon success, configure your provider as shown below:</p><h3>Configure SendGrid Provider</h3><p>Navigate to your Strapi project and locate the configuration file for plugins, ./config/plugins.ts. Add the following code:</p><pre>module.exports = ({ env }) =&gt; ({<br>  email: {<br>    config: {<br>      provider: &quot;sendgrid&quot;,<br>      providerOptions: {<br>        apiKey: env(&quot;SENDGRID_API_KEY&quot;), // Required<br>      },<br>      settings: {<br>        defaultFrom: env(&quot;SENDGRID_EMAIL&quot;),<br>        defaultReplyTo: env(&quot;SENDGRID_EMAIL&quot;),<br>      },<br>    },<br>  },<br>});</pre><p>Ensure you have your SendGrid API key and SendGrid email present in your Strapi project environment variable (strapi-backend/.env):</p><pre># Path: strapi-backend/.env<br><br># ... Other environment variables<br><br># SendGrid API Key<br>SENDGRID_API_KEY=YOUR_API_KEY<br>SENDGRID_EMAIL=YOUR_SENDGRID_EMAIL</pre><h3>Restart Strapi App</h3><p>Restart your Strapi development server and visit the email configuration page. You will notice that the email provider is now SendGrid and the default email address is the one you provided in the configuration file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RmB9ub2dvVWC8M_d.png" /></figure><blockquote><em>🖐️ NOTE: The test feature on this page might not work in development mode, because it might not be using your SendGrid configuration.</em></blockquote><p>Great! Let&#39;s dive into Next.js installation in the next section.</p><h3>Next.js Installation</h3><h3>Install Next.js</h3><p>Install Next.js using the command below. Ensure you are in the directory where you installed your Strapi project.</p><pre>npx create-next-app@latest</pre><p>During installation, ensure you follow the prompts. For this project, here are the answers to the prompts.</p><pre>✔ What is your project named? … nextjs-frontend<br>✔ Would you like to use TypeScript? … Yes<br>✔ Would you like to use ESLint? … No<br>✔ Would you like to use Tailwind CSS? … Yes<br>✔ Would you like your code inside a `src/` directory? … Yes<br>✔ Would you like to use App Router? (recommended) … Yes<br>✔ Would you like to use Turbopack for `next dev`? … Yes<br>✔ Would you like to customize the import alias (`@/*` by default)? … No</pre><blockquote><em>NOTE: The project name is </em><em>nextjs-frontend</em></blockquote><h3>Start Next.js Development Server</h3><p>Upon successful installation, cd into your Next.js project and run the command below to start your Next.js development server:</p><pre>cd nextjs-frontend<br>npm run dev</pre><p>Visit http://localhost:3000 to view your application.</p><blockquote><em>👋 NOTE: Want to learn more about how to integrate Strapi and Next.js? Visit the </em><a href="https://strapi.io/integrations/nextjs-cms"><em>Strapi and Next.js integration guide</em></a><em>.</em></blockquote><p>In the next section, we will perform some essential setups.</p><h3>Create Starter Files, Dependencies and Templates</h3><p>Before we begin implementing Strapi email and password authentication, we need to first install some dependencies, create some starter files and code templates.</p><h3>Install Dependencies</h3><p>Install the following dependencies:</p><ul><li><a href="https://axios-http.com/docs/intro">axios</a>: For HTTP requests.</li><li><a href="https://www.npmjs.com/package/jose">jose</a>: JavaScript module for JSON Object Signing and Encryption, providing support for JSON Web Tokens (JWT) and so on.</li><li><a href="https://www.npmjs.com/package/react-toastify">react-toastify</a>: Allows us to add toast notifications.</li></ul><pre>npm i axios jose react-toastify</pre><h3>Create Pages</h3><pre>nextjs-frontend/<br>├── ...<br>├── .env<br>├── middleware.ts<br>└── src/<br>    └── app/<br>        ├── actions/<br>        │   └── auth.ts<br>        ├── auth/<br>        │   ├── signup/<br>        │   │   └── page.tsx<br>        │   ├── login/<br>        │   │   └── page.tsx<br>        │   ├── confirm-email/<br>        │   │   └── page.tsx<br>        │   ├── signup-success/<br>        │   │   └── page.tsx<br>        │   ├── forgot-password/<br>        │   │   └── page.tsx<br>        │   ├── change-password/<br>        │   │   └── page.tsx<br>        │   └── reset-password/<br>        │       └── page.tsx<br>        ├── components/<br>        │   ├── NavBar.tsx<br>        │   └── LogOutButton.tsx<br>        ├── lib/<br>        ├── layout.tsx<br>        ├── page.tsx<br>        └── globals.css</pre><p>Create the following folders and files inside the nextjs-frontend/src/app folder.</p><ol><li>actions: This is where server actions logic will reside. Create the auth.ts file inside it.</li><li>auth: This will hold pages related to authentication. Inside this folder, create the following:</li></ol><ul><li>signup &gt; page.tsx</li><li>login &gt; page.tsx</li><li>confirm-email &gt; page.tsx</li><li>signup-success &gt; page.tsx</li><li>forgot-password &gt; page.tsx</li><li>change-password &gt; page.tsx</li><li>reset-password &gt; page.tsx</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lqzaG8YHbmb8IoBd.png" /></figure><p>3 components: Inside this folder, create the following:</p><ul><li>NavBar.tsx: Represents the navigation bar.</li><li>LogOutButton.tsx: Represents the button for logging out.</li></ul><p>3. lib: This will hold the logic for session management, API requests, type definitions, and <a href="https://en.wikipedia.org/wiki/Data_access_layer">Data Access Layer (DAL)</a>.</p><h3>Create Environment Variable File</h3><p>Inside the root of your frontend project folder nextjs-frontend, create the .env file. And add the environment variable for your Strapi API endpoint.</p><pre># Path: nextjs-frontend/.env<br><br>STRAPI_ENDPOINT=&quot;http://localhost:1337&quot;</pre><h3>Create Next.js Middleware File</h3><p>Middleware allows you to run code before a request is completed. We will use it to protect some pages.</p><p>Inside the nextjs-frontend/src folder, create the middleware.ts file.</p><h3>Modify Pages and Files</h3><h3>Global CSS</h3><p>Since we are using Tailwind CSS in this tutorial, head over to ./src/app/globals.css and delete other codes. Leave only the Tailwind import.</p><pre>/* Path: nextjs-frontend/src/app/globals.css *./<br><br>@import &quot;tailwindcss&quot;;</pre><h3>Log-Out Button</h3><p>Inside the nextjs-frontend/src/app/components/LogOutButton.tsx, add the following code:</p><pre>// Path: nextjs-frontend/src/app/components/LogOutButton.tsx<br><br>&quot;use client&quot;;<br><br>export default function LogOut() {<br>  return (<br>    &lt;button className=&quot;cursor-pointer w-full sm:w-auto px-6 py-2 bg-red-500 text-white rounded-lg shadow-md hover:bg-red-600 transition&quot;&gt;<br>      Sign Out<br>    &lt;/button&gt;<br>  );<br>}</pre><h3>Navigation Bar Component</h3><p>Inside the nextjs-frontend/src/app/components/NavBar.tsx file, add the following code:</p><pre>// Path: nextjs-frontend/src/app/components/NavBar.tsx<br><br>import Link from &quot;next/link&quot;;<br><br>export default async function NavBar() {<br>  return (<br>    &lt;nav className=&quot;flex items-center justify-between px-6 py-4 bg-white shadow-md&quot;&gt;<br>      {/* Logo */}<br>      &lt;Link href=&quot;/&quot; className=&quot;text-xl font-semibold cursor-pointer&quot;&gt;<br>        MyApp<br>      &lt;/Link&gt;<br>      &lt;div className=&quot;flex&quot;&gt;<br>        &lt;Link<br>          href=&quot;/auth/signin&quot;<br>          className=&quot;px-4 py-2 rounded-lg bg-blue-500 text-white font-medium shadow-md transition-transform transform hover:scale-105 hover:bg-blue-600 cursor-pointer&quot;<br>        &gt;<br>          Sign-in<br>        &lt;/Link&gt;<br>      &lt;/div&gt;<br>    &lt;/nav&gt;<br>  );<br>}</pre><h3>Home Page</h3><p>Inside the nextjs-frontend/src/app/page.tsx file, replace the code inside with the following code:</p><pre>// Path: nextjs-frontend/src/app/page.tsx<br><br>import Link from &quot;next/link&quot;;<br><br>export default async function Home() {<br>  return (<br>    &lt;div className=&quot;flex flex-col items-center justify-center min-h-screen bg-gray-100 text-gray-900 p-6&quot;&gt;<br>      {/* Title */}<br>      &lt;h1 className=&quot;text-3xl sm:text-4xl font-semibold mb-4&quot;&gt;<br>        Email &amp; Password Authentication in Next.js &amp; Strapi<br>      &lt;/h1&gt;<br><br>      {/* Subtitle */}<br>      &lt;p className=&quot;text-center text-lg text-gray-600 max-w-xl&quot;&gt;<br>        Learn how to implement a secure authentication flow using Next.js and<br>        Strapi. Start by signing in or creating an account.<br>      &lt;/p&gt;<br><br>      {/* Buttons */}<br>      &lt;div className=&quot;mt-6 flex space-x-4&quot;&gt;<br>        &lt;Link href=&quot;/auth/login&quot;&gt;<br>          &lt;button className=&quot;px-6 py-3 text-white bg-blue-500 rounded-lg shadow-md hover:bg-blue-600 transition&quot;&gt;<br>            Sign In<br>          &lt;/button&gt;<br>        &lt;/Link&gt;<br>        &lt;Link href=&quot;/auth/signup&quot;&gt;<br>          &lt;button className=&quot;cursor-pointer px-6 py-3 text-blue-500 border border-blue-500 rounded-lg shadow-md hover:bg-blue-50 transition&quot;&gt;<br>            Sign Up<br>          &lt;/button&gt;<br>        &lt;/Link&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h3>Layout</h3><p>Inside the layout file, we will import the following:</p><ul><li>NavBar,</li><li>ToastContainer from the react-toastify that you installed earlier.</li><li>react-toastify/dist/ReactToastify.css, which styles the ToastContainer above.</li></ul><pre>// Path: nextjs-frontend/src/app/layout.tsx<br><br>import type { Metadata } from &quot;next&quot;;<br>import { Geist, Geist_Mono } from &quot;next/font/google&quot;;<br>import &quot;./globals.css&quot;;<br>import NavBar from &quot;@/app/components/NavBar&quot;;<br>import { ToastContainer } from &quot;react-toastify&quot;;<br>import &quot;react-toastify/dist/ReactToastify.css&quot;;<br><br>const geistSans = Geist({<br>  variable: &quot;--font-geist-sans&quot;,<br>  subsets: [&quot;latin&quot;],<br>});<br><br>const geistMono = Geist_Mono({<br>  variable: &quot;--font-geist-mono&quot;,<br>  subsets: [&quot;latin&quot;],<br>});<br><br>export const metadata: Metadata = {<br>  title: &quot;Create Next App&quot;,<br>  description: &quot;Generated by create next app&quot;,<br>};<br><br>export default function RootLayout({<br>  children,<br>}: Readonly&lt;{<br>  children: React.ReactNode;<br>}&gt;) {<br>  return (<br>    &lt;html lang=&quot;en&quot;&gt;<br>      &lt;body<br>        className={`${geistSans.variable} ${geistMono.variable} antialiased`}<br>      &gt;<br>        &lt;ToastContainer /&gt;<br>        &lt;NavBar /&gt;<br><br>        {children}<br>      &lt;/body&gt;<br>    &lt;/html&gt;<br>  );<br>}</pre><p>Now, visit http://localhost:3000 to view your changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8gYC8CNCdIYnvXxc.png" /></figure><h3>Create Type Definitions for this Project</h3><p>Inside the nextjs-frontend/src/app/lib folder, create a file called definitions.ts and add the following code.</p><pre>// Path : nextjs-frontend/src/app/lib/definitions.ts<br><br><br>// This file contains type definitions for the application.<br><br>// Credentials for authentication<br>export type Credentials = {<br>  username?: string;<br>  email?: string;<br>  identifier?: string;<br>  currentPassword?: string;<br>  password?: string;<br>  confirmPassword?: string;<br>  newPassword?: string;<br>  code?: string;<br>};<br><br>// Form state for form handling and server actions<br>export type FormState = {<br>  errors: Credentials;<br>  values: Credentials;<br>  message?: string;<br>  success?: boolean;<br>};<br><br>export type SessionPayload = {<br>  user?: any;<br>  expiresAt?: Date;<br>  jwt?: string;<br>};</pre><p>The Credentials type will serve for authentication purposes. The FormState type will be for form handling and server actions variable types. And the SessionPayload refers to the type of payload returned from Strapi after successful login.</p><p>Now, let&#39;s get started!</p><h3>How to Implement User Signup with Email Confirmation in Strapi and Next.js</h3><p>Strapi&#39;s <a href="https://docs.strapi.io/cms/features/users-permissions">Users &amp; Permissions plugin</a> provides built-in functionality for email/password registration.</p><p>Here is the request for registering a new user.</p><pre>const STRAPI_ENDPOINT = &quot;http://localhost:1337/&quot;;<br><br>await axios.post(<br>  `${STRAPI_ENDPOINT}/api/auth/local/register`,<br>  {<br>    username: &#39;Strapi user&#39;,<br>    email: &#39;user@strapi.io&#39;,<br>    password: &#39;strapiPassword&#39;,<br>  },<br>);</pre><p>If you want additional fields, you will need to add them to the list of allowed fields in your config file. See the <a href="https://docs.strapi.io/cms/features/users-permissions#registration-configuration">registration configuration guide</a>.</p><h3>Ways of Registering a New User in Strapi</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H34v6tvBvBmnHwiI.png" /></figure><p>There are two ways to register a new user.</p><ol><li>Register a new user by confirming their email address.</li><li>Register a new user without confirming their email address</li></ol><p>You can decide to choose the latter.</p><p>However, you want to make sure the user&#39;s email is verified. Therefore, you will need to enable email confirmation in Strapi.</p><p>Here are reasons why you need email confirmation:</p><ul><li>User identity verification</li><li>Email delivery success</li><li>Boosted brand reputation, etc.</li></ul><blockquote><em>👋 NOTE: If you are not interested in implementing Email Confirmation, please continue from the &quot;Strapi Email and Password Login&quot; section.</em></blockquote><p>With that being said, let&#39;s walk through the steps of registering a new user.</p><h3>Step 1. Enable Email Confirmation in Strapi</h3><p>To begin, head over to <em>Settings &gt; USERS AND PERMISSIONS PLUGIN &gt; Advanced Settings</em> and do the following:</p><ul><li>Toggle the Enable email confirmation to true.</li><li>Add the redirect URL where a user will be redirected after the user&#39;s email is confirmed. The redirect URL for this project should be http://localhost:3000/auth/signup-success. This is the page that will show the user that the signup process is successful. We will create the signup-success page soon.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yfiqKgaQtlpxCLwI.png" /></figure><blockquote><em>🖐️ NOTE: After signup, Strapi sends you a confirmation link that will redirect you to the </em><em>http://localhost:3000/auth/signup-success above. The link looks like this: </em><em>http://localhost:1337/api/auth/email-confirmation?confirmation=56343d5821391b2b9c1569c5b69672f95bb0caf3. When clicked, it will redirect the user to the signup success page which you specified above.</em></blockquote><p>Since we are now sending emails using SendGrid as the default email provider, edit the email template to continue.</p><h3>Step 2: Edit Email Confirmation Template</h3><p>Navigate to <em>Settings &gt; USERS &amp; PERMISSIONS PLUGIN &gt; Email Templates &gt; Email address confirmation</em>.</p><p>Change the default shipper email from no-reply@strapi.io to the email address you used for your SendGrid configuration, otherwise, email delivery will fail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*o9geyrjJWOf1Aajh.png" /></figure><p>Next, we will write a request function to create a new user.</p><h3>Step 3: Create User Registration Request Function</h3><p>Inside the nextjs-frontend/src/app/lib folder, create a requests.ts file and add the following code:</p><pre>// Path: nextjs-frontend/src/app/lib/requests.ts<br><br>import { Credentials } from &quot;./definitions&quot;;<br>import axios from &quot;axios&quot;;<br><br>const STRAPI_ENDPOINT = process.env.STRAPI_ENDPOINT || &quot;http://localhost:1337&quot;;<br><br>export const signUpRequest = async (credentials: Credentials) =&gt; {<br>  try {<br>    const response = await axios.post(<br>      `${STRAPI_ENDPOINT}/api/auth/local/register`,<br>      {<br>        username: credentials.username,<br>        email: credentials.email,<br>        password: credentials.password,<br>      }<br>    );<br><br>    return response;<br>  } catch (error: any) {<br>    return error?.response?.data?.error?.message || &quot;Error signing up&quot;;<br>  }<br>};</pre><p>The signUpRequest() request function takes in a credentials object containing username, email, and password, and sends it to Strapi&#39;s /auth/local/register endpoint to create a new user with new credentials.</p><p>Next, let&#39;s create a server action that will invoke this request.</p><h3>Step 4: Create Server Action for User Registration</h3><p>Inside the ./src/app/actions/auth.ts file, create a server action that will do the following:</p><ul><li>Handle a signup form by validating user input (username, email, password, confirmPassword)</li><li>Call the signUpRequest() request function you created above.</li><li>Returns a FormState object type with error messages and form values if there are validation or API errors.</li><li>Redirect the user to a confirmation page.</li></ul><p>Here is the code below:</p><pre>// Path: nextjs-frontend/src/app/actions/auth.ts<br><br>&quot;use server&quot;;<br><br>import { redirect } from &quot;next/navigation&quot;;<br>import { FormState, Credentials } from &quot;../lib/definitions&quot;;<br>import { signUpRequest } from &quot;../lib/requests&quot;;<br><br>export async function signupAction(<br>  initialState: FormState,<br>  formData: FormData<br>): Promise&lt;FormState&gt; {<br>  // Convert formData into an object to extract data<br>  const username = formData.get(&quot;username&quot;);<br>  const email = formData.get(&quot;email&quot;);<br>  const password = formData.get(&quot;password&quot;);<br>  const confirmPassword = formData.get(&quot;confirmPassword&quot;);<br><br>  const errors: Credentials = {};<br><br>  // Validate the form data<br>  if (!username) errors.username = &quot;Username is required&quot;;<br>  if (!username) errors.email = &quot;Email is required&quot;;<br>  if (!password) errors.password = &quot;Password is required&quot;;<br>  if (!confirmPassword) errors.confirmPassword = &quot;Confirm password is required&quot;;<br>  if (password &amp;&amp; confirmPassword &amp;&amp; password !== confirmPassword) {<br>    errors.confirmPassword = &quot;Passwords do not match&quot;;<br>  }<br><br>  // Check if there are any errors<br>  if (Object.keys(errors).length &gt; 0) {<br>    return {<br>      errors,<br>      values: { username, email, password, confirmPassword } as Credentials,<br>      message: &quot;Error submitting form&quot;,<br>      success: false,<br>    };<br>  }<br><br>  // Call backend API<br>  const res: any = await signUpRequest({<br>    username,<br>    email,<br>    password,<br>  } as Credentials);<br><br>  // Check for errors in the response<br>  if (res.statusText !== &quot;OK&quot;) {<br>    return {<br>      errors: {} as Credentials,<br>      values: { username, email, password, confirmPassword } as Credentials,<br>      message: res?.statusText || res,<br>      success: false,<br>    };<br>  }<br><br>  // redirect to confirm email<br>  redirect(&quot;/auth/confirm-email&quot;);<br>}</pre><p>Next, set up the email confirmation page because we are redirecting the user to the email confirmation page.</p><h3>Step 5. Set Up an Email Confirmation Page</h3><p>Inside the nextjs-frontend/src/app/auth/confirm-email/page.tsx, add the following code:</p><pre>// Path: nextjs-frontend/src/app/auth/confirm-email/page.tsx<br><br>export default function ConfirmEmail() {<br>  return (<br>    &lt;div className=&quot;flex min-h-screen items-center justify-center bg-gray-100 px-4&quot;&gt;<br>      &lt;div className=&quot;w-full max-w-md p-6 space-y-6 bg-white rounded-lg shadow-md text-center&quot;&gt;<br>        &lt;h2 className=&quot;text-2xl font-semibold&quot;&gt;Confirm Your Email&lt;/h2&gt;<br>        &lt;p className=&quot;text-gray-700 text-sm&quot;&gt;<br>          We’ve sent a confirmation link to your email address. Please check<br>          your inbox and click the link to verify your account before logging<br>          in.<br>        &lt;/p&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h3>Step 6. Set Up the Signup Success Page.</h3><p>Locate the nextjs-frontend/src/app/auth/signup-success/page.tsx file and add the following code:</p><pre>// Path: nextjs-frontend/src/app/auth/signup-success/page.tsx<br><br>import Link from &quot;next/link&quot;;<br><br>export default function EmailConfirmed() {<br>  return (<br>    &lt;div className=&quot;flex min-h-screen items-center justify-center bg-gray-100 px-4&quot;&gt;<br>      &lt;div className=&quot;w-full max-w-md p-6 space-y-6 bg-white rounded-lg shadow-md text-center&quot;&gt;<br>        &lt;h2 className=&quot;text-2xl font-semibold text-green-600&quot;&gt;<br>          Email Confirmed ✅<br>        &lt;/h2&gt;<br><br>        &lt;p className=&quot;text-gray-700 text-sm&quot;&gt;<br>          Your email has been successfully verified. You can now log in to your<br>          account.<br>        &lt;/p&gt;<br><br>        &lt;Link href=&quot;/auth/signin&quot;&gt;<br>          &lt;button className=&quot;mt-6 w-full py-2 px-4 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition&quot;&gt;<br>            Go to Login<br>          &lt;/button&gt;<br>        &lt;/Link&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>The page above shows the user that the signup or registration is successful.</p><p>Next, create the signup form.</p><h3>Step 7: Create a Signup Form</h3><p>Create the signup form.</p><pre>// Path: ./src/app/auth/signup/page.tsx<br><br>&quot;use client&quot;;<br><br>import { useActionState } from &quot;react&quot;;<br>import { signupAction } from &quot;@/app/actions/auth&quot;;<br>import { FormState } from &quot;@/app/lib/definitions&quot;;<br><br>export default function SignUp() {<br>  // create a form state<br>  const initialState: FormState = {<br>    errors: {},<br>    values: {},<br>    message: &quot;&quot;,<br>    success: false,<br>  };<br><br>  // use the action state to handle the form submission<br>  const [state, formAction, isPending] = useActionState(<br>    signupAction,<br>    initialState<br>  );<br><br>  return (<br>    &lt;div className=&quot;flex min-h-screen items-center justify-center bg-gray-100&quot;&gt;<br>      &lt;div className=&quot;w-full max-w-md p-6 space-y-6 bg-white rounded-lg shadow-md&quot;&gt;<br>        &lt;h2 className=&quot;text-2xl font-semibold text-center&quot;&gt;Sign Up&lt;/h2&gt;<br><br>        &lt;form action={formAction} className=&quot;space-y-4&quot;&gt;<br>          &lt;p className=&quot;text-red-500 text-center text-sm&quot;&gt;<br>            {!state?.success &amp;&amp; state?.message}<br>          &lt;/p&gt;<br><br>          {/* Email */}<br>          &lt;div&gt;<br>            &lt;label className=&quot;block text-gray-700&quot;&gt;Username&lt;/label&gt;<br>            &lt;input<br>              type=&quot;text&quot;<br>              name=&quot;username&quot;<br>              defaultValue={state?.values?.username as string}<br>              placeholder=&quot;Enter your username&quot;<br>              className=&quot;w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500&quot;<br>            /&gt;<br>            {state?.errors.username &amp;&amp; (<br>              &lt;p className=&quot;text-red-500 text-sm&quot;&gt;{state?.errors.username}&lt;/p&gt;<br>            )}<br>          &lt;/div&gt;<br><br>          &lt;div&gt;<br>            &lt;label className=&quot;block text-gray-700&quot;&gt;Email&lt;/label&gt;<br>            &lt;input<br>              type=&quot;email&quot;<br>              name=&quot;email&quot;<br>              defaultValue={state?.values?.email as string}<br>              placeholder=&quot;Enter your email&quot;<br>              className=&quot;w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500&quot;<br>            /&gt;<br><br>            {state?.errors.email &amp;&amp; (<br>              &lt;p className=&quot;text-red-500 text-sm&quot;&gt;{state?.errors.email}&lt;/p&gt;<br>            )}<br>          &lt;/div&gt;<br><br>          {/* Password */}<br>          &lt;div&gt;<br>            &lt;label className=&quot;block text-gray-700&quot;&gt;Password&lt;/label&gt;<br>            &lt;input<br>              type=&quot;password&quot;<br>              name=&quot;password&quot;<br>              defaultValue={state?.values?.password as string}<br>              placeholder=&quot;Create a password&quot;<br>              className=&quot;w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500&quot;<br>            /&gt;<br><br>            {state?.errors.password &amp;&amp; (<br>              &lt;p className=&quot;text-red-500 text-sm&quot;&gt;{state?.errors.password}&lt;/p&gt;<br>            )}<br>          &lt;/div&gt;<br><br>          {/* Confirm Password */}<br>          &lt;div&gt;<br>            &lt;label className=&quot;block text-gray-700&quot;&gt;Confirm Password&lt;/label&gt;<br>            &lt;input<br>              type=&quot;password&quot;<br>              name=&quot;confirmPassword&quot;<br>              defaultValue={state?.values?.confirmPassword as string}<br>              placeholder=&quot;Confirm your password&quot;<br>              className=&quot;w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500&quot;<br>            /&gt;<br><br>            {state?.errors.confirmPassword &amp;&amp; (<br>              &lt;p className=&quot;text-red-500 text-sm&quot;&gt;<br>                {state?.errors.confirmPassword}<br>              &lt;/p&gt;<br>            )}<br>          &lt;/div&gt;<br><br>          {/* Sign Up Button */}<br>          &lt;button<br>            type=&quot;submit&quot;<br>            disabled={isPending}<br>            className=&quot;w-full py-2 text-white bg-blue-500 rounded-lg hover:bg-blue-600 transition&quot;<br>          &gt;<br>            {isPending ? &quot;Submitting...&quot; : &quot;Sign Up&quot;}<br>          &lt;/button&gt;<br>        &lt;/form&gt;<br><br>        {/* Sign In Link */}<br>        &lt;div className=&quot;text-center text-gray-600&quot;&gt;<br>          Already have an account?{&quot; &quot;}<br>          &lt;a href=&quot;/auth/login&quot; className=&quot;text-blue-500 hover:underline&quot;&gt;<br>            Sign In<br>          &lt;/a&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>This is how the signup page should look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ADcb2HPludjmNoXN.png" /></figure><p>Now, register a new user!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*N3eQOnNaM6eo8B4v.gif" /></figure><p>As you can see above, the signup process works the way we expect.</p><p>When you check your Strapi backend, you should see the new user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9dcTgjAl0IX0kxHm.png" /></figure><p>Congratulations! You have registered a new user.</p><p>What happens when the user of your app doesn&#39;t get an email confirmation and would like the confirmation link to be resent?</p><p>Or how do you know if an email is already confirmed?</p><p>Let&#39;s learn how to send an email confirmation after registration in Strapi in the next section.</p><h3>How to Send Email Confirmation After User Registration in Strapi</h3><p>By default, Strapi automatically sends a confirmation email upon registration provided that it is enabled in the Strapi backend as discussed previously.</p><p>However, in some cases, the user may miss or not receive the email and would love to have it resent to them.</p><p>Strapi provides us with the following flow for manually sending or resending a confirmation email:</p><pre>const STRAPI_ENDPOINT = &quot;http://localhost:1337/&quot;;<br><br>await axios.post(<br>  `${STRAPI_ENDPOINT}/api/auth/send-email-confirmation`,<br>  {<br>    email: &#39;user@strapi.io&#39;<br>  },<br>);</pre><p>Send a POST request with the correct email to the endpoint /api/auth/send-email-confirmation to confirm an email address.</p><h3>What if an Email is Already Confirmed?</h3><p>Recall that you already confirmed the email of the user you created above. Let&#39;s see what happens when you try to confirm it once more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CD8tvCnjBdXc1NLe.png" /></figure><p>When you try to confirm an already confirmed email, as shown above, you get the response &quot;Already confirmed&quot;.</p><h3>Resending Email Confirmation Logic</h3><p>We want to be able to allow the user to request a resend of the confirmation email.</p><p>There are many ways to do this, but here is what you will do in this tutorial:</p><ul><li>In the signup or registration section above, once the user registers, Strapi sends a confirmation email, and then you redirect them to the page where they get the message to check their email for the confirmation link.</li><li>You will modify the redirect of the signUpAction() server action function to include the email. This is so that they can request the confirmation link to be resent to them in case they didn&#39;t receive it:</li></ul><pre>// redirect to confirm email<br>redirect(&quot;/auth/confirm-email?email=&quot; + email);</pre><ul><li>The page where they get the message to check their email for the confirmation link will now programmatically allow a resend of the confirmation link by extracting the email from the URL using useSearchParams .</li></ul><p>Let&#39;s implement this:</p><h3>Step 1. Modify Signup Server Action to Include Email Address</h3><p>Include the email address in the redirect so that we can be able to resend an email confirmation if the user requests such.</p><pre>// Path : nextjs-frontend/src/app/actions/auth.ts<br><br>// ... imports <br><br>export async function signupAction(<br>  initialState: FormState,<br>  formData: FormData<br>): Promise&lt;FormState&gt; {<br>  <br>  // ... other codes<br>  <br>  // redirect to confirm email with user email<br>  redirect(&quot;/auth/confirm-email?email=&quot; + email);<br>}</pre><h3>Step 2. Create Send Email Confirmation Request Function</h3><p>Inside the nextjs-frontend/src/app/lib/requests.ts file, create the confirmEmailRequest() function to send email confirmation.</p><pre>// Path: nextjs-frontend/src/app/lib/requests.ts<br><br>// ... other codes<br><br>export const confirmEmailRequest = async (email: string) =&gt; {<br>  try {<br>    const response = await axios.post(<br>      `${STRAPI_ENDPOINT}/api/auth/send-email-confirmation`,<br>      {<br>        email,<br>      }<br>    );<br><br>    return response;<br>  } catch (error: any) {<br>    return (<br>      error?.response?.data?.error?.message ||<br>      &quot;Error sending confirmation email&quot;<br>    );<br>  }<br>};</pre><p>Next, create a server action that will call the confirmEmailRequest() function above.</p><h3>Step 3. Create Server Action for Email Confirmation</h3><p>Create a server action that will handle the form submission and invoke the confirmRequest() function above.</p><pre>// Path: nextjs-frontend/src/app/actions/auth.ts<br><br> // ... other imports<br><br>import { signUpRequest, confirmEmailRequest } from &quot;../lib/requests&quot;;<br><br>// ... other actions (signupAction)<br><br>export async function resendConfirmEmailAction(<br>  initialState: FormState,<br>  formData: FormData<br>) {<br>  // Extract email from formData<br>  const email = formData.get(&quot;email&quot;);<br><br>  // Validate the email<br>  if (!email) {<br>    return {<br>      values: { email } as Credentials,<br>      message: &quot;Email not found&quot;,<br>      success: false,<br>    };<br>  }<br><br>  // invoke the resend email function<br>  const res = await confirmEmailRequest(email as string);<br><br>  // Check for errors in the response<br>  if (res.statusText !== &quot;OK&quot;) {<br>    return {<br>      errors: {} as Credentials,<br>      values: { email } as Credentials,<br>      message: res?.statusText || res,<br>      success: false,<br>    };<br>  }<br><br>  return {<br>    values: { email } as Credentials,<br>    message: &quot;Confirmation email sent&quot;,<br>    success: true,<br>  };<br>}</pre><h3>Step 4: Modify the Confirm Email Message Page</h3><p>Now, modify the confirm email page, nextjs-frontend/src/app/auth/confirm-email/page.tsx, that tells the user to check their email for the confirmation link. It should now be able to get the email from the URL using useSearchParams.</p><pre>// Path: nextjs-frontend/src/app/auth/confirm-email/page.tsx<br><br>&quot;use client&quot;;<br><br>import { resendConfirmEmailAction } from &quot;@/app/actions/auth&quot;;<br>import { FormState } from &quot;@/app/lib/definitions&quot;;<br><br>import { useSearchParams } from &quot;next/navigation&quot;;<br>import { useActionState, useEffect } from &quot;react&quot;;<br><br>import { toast } from &quot;react-toastify&quot;;<br><br>export default function PleaseConfirmEmail() {<br>  // create initial state<br>  const initialState: FormState = {<br>    errors: {},<br>    values: {},<br>    message: &quot;&quot;,<br>    success: false,<br>  };<br><br>  // useActionState to manage the state of the action<br>  const [state, formAction, isPending] = useActionState(<br>    resendConfirmEmailAction,<br>    initialState<br>  );<br><br>  // useSearchParams to get the email from the URL<br>  const searchParams = useSearchParams();<br>  const userEmail = searchParams.get(&quot;email&quot;) || &quot;&quot;;<br><br>  useEffect(() =&gt; {<br>    if (state.success) {<br>      toast.success(state.message, { position: &quot;top-center&quot; });<br>    }<br>  }, [state.success]);<br><br>  return (<br>    &lt;div className=&quot;flex min-h-screen items-center justify-center bg-gray-100 px-4&quot;&gt;<br>      &lt;div className=&quot;w-full max-w-md p-6 space-y-6 bg-white rounded-lg shadow-md text-center&quot;&gt;<br>        &lt;h2 className=&quot;text-2xl font-semibold&quot;&gt;Confirm Your Email&lt;/h2&gt;<br>        &lt;p className=&quot;text-red-500&quot;&gt;{!state.success &amp;&amp; state.message}&lt;/p&gt;<br>        &lt;p className=&quot;text-gray-700 text-sm&quot;&gt;<br>          We’ve sent a confirmation link to your email address. Please check<br>          your inbox and click the link to verify your account before logging<br>          in.<br>        &lt;/p&gt;<br><br>        &lt;p className=&quot;text-gray-500 text-sm&quot;&gt;<br>          Didn’t receive the email? Check your spam folder or try resending it<br>          below.<br>        &lt;/p&gt;<br><br>        {/* Resend Email Button */}<br>        &lt;form action={formAction}&gt;<br>          &lt;input<br>            type=&quot;email&quot;<br>            name=&quot;email&quot;<br>            defaultValue={userEmail}<br>            className=&quot;w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500&quot;<br>          /&gt;<br>          &lt;button<br>            disabled={isPending}<br>            type=&quot;submit&quot;<br>            className=&quot;w-full my-4 py-2 px-4 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition&quot;<br>          &gt;<br>            Resend Confirmation Email<br>          &lt;/button&gt;<br>          {/* &lt;input type=&quot;hidden&quot; name=&quot;email&quot; value={userEmail as string} /&gt; */}<br>        &lt;/form&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>In the code above:</p><ul><li>The component uses useActionState to manage the form state and handle the resendConfirmEmailAction server action.</li><li>The email is prefilled from the URL using useSearchParams,</li><li>And a toast notification appears if the resend is successful.</li></ul><p>Enter the email address that you have confirmed and click the &quot;Resend Confirmation Email&quot; button.</p><p>You should get the error message &quot;Already confirmed&quot;.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V571p2ZtPoceSXMj.png" /></figure><p>Now with the new logic we have created above, create a new user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*b3uDFQjghkGM8ixx.png" /></figure><p>As shown above, when a user signs up, they get redirected to the page that tells them they have been sent a confirmation link. In this modified page, they can also request to get it resent to them.</p><p>The email address in the input from the image above comes prefilled from the URL which we extracted using the useSearchParams.</p><p>You have implemented user registration or signup, and email confirmation in Strapi. Next, let&#39;s implement Strapi email and password login!</p><h3>Strapi Email and Password Login</h3><p>After registration, a user will have to log in.</p><p>To log in as a user, you make a POST request to /api/auth/local endpoint.</p><pre>const STRAPI_ENDPOINT = &quot;http://localhost:1337/&quot;;<br><br>const response = await axios.post(`${BASE_URL}/api/auth/local`, {<br>  identifier: credentials.identifier,<br>  password: credentials.password,<br>});</pre><blockquote><em>🖐️ NOTE: The identifier here could be the user&#39;s email address or username.</em></blockquote><p>Here is the response you get:</p><pre>{<br>  &quot;jwt&quot;: &quot;eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MTUsImlhdCI6MTc0NTM1MzMzMSwiZXhwIjoxNzQ3OTQ1MzMxfQ.zvx2Q2OexHIPkNA5aCqaOG3Axn0rlylLOpgiVPifi8c&quot;,<br>  &quot;user&quot;: {<br>    &quot;id&quot;: 15,<br>    &quot;documentId&quot;: &quot;npbi8dusjdsdwu5a0zq6ticv&quot;,<br>    &quot;username&quot;: &quot;Theodore&quot;,<br>    &quot;email&quot;: &quot;strapiUser@gmail.com&quot;,<br>    &quot;provider&quot;: &quot;local&quot;,<br>    &quot;confirmed&quot;: true,<br>    &quot;blocked&quot;: false,<br>    &quot;createdAt&quot;: &quot;2025-04-22T18:18:01.170Z&quot;,<br>    &quot;updatedAt&quot;: &quot;2025-04-22T19:04:51.091Z&quot;,<br>    &quot;publishedAt&quot;: &quot;2025-04-22T18:18:01.172Z&quot;<br>  }<br>}</pre><p>The jwt from the response above will be extracted and used to make authorized requests as we will see in the later part of this tutorial.</p><p>Let&#39;s implement email and password login in Strapi.</p><h3>Step 1: Create Email and Password Request Function</h3><pre>// Path: nextjs-frontend/src/app/lib/requests.ts<br><br>// ... other codes<br><br>export const signInRequest = async (credentials: Credentials) =&gt; {<br>  try {<br>    const response = await axios.post(`${STRAPI_ENDPOINT}/api/auth/local`, {<br>      identifier: credentials.identifier,<br>      password: credentials.password,<br>    });<br><br>    return response;<br>  } catch (error: any) {<br>    return error?.response?.data?.error?.message || &quot;Error signing in&quot;;<br>  }<br>};</pre><h3>Step 2: Create Server Action to Handle Form Submission</h3><p>Create a server action function that does the following:</p><ul><li>Handles form submission for user sign-in by validating identifier and password from the formData.</li><li>If either field is missing, it returns a FormState object with error messages and previous values.</li><li>If inputs are valid, it calls the signInRequest function above to authenticate the user.</li><li>On success, it redirects to the /profile page which we will set up soon.</li><li>On failure, it returns a generic error message in the state.</li></ul><pre>// Path: nextjs-frontend/src/app/actions/auth.ts<br><br>// ... Other codes<br><br>export async function signinAction(<br>  initialState: FormState,<br>  formData: FormData<br>): Promise&lt;FormState&gt; {<br>  // Convert formData into an object to extract data<br>  const identifier = formData.get(&quot;identifier&quot;);<br>  const password = formData.get(&quot;password&quot;);<br><br>  const errors: Credentials = {};<br><br>  if (!identifier) errors.identifier = &quot;Username or email is required&quot;;<br>  if (!password) errors.password = &quot;Password is required&quot;;<br><br>  if (errors.password || errors.identifier) {<br>    return {<br>      errors,<br>      values: { identifier, password } as Credentials,<br>      message: &quot;Error submitting form&quot;,<br>      success: false,<br>    };<br>  }<br><br>  // Call backend API<br>  const res: any = await signInRequest({<br>    identifier,<br>    password,<br>  } as Credentials);<br><br>  if (res.statusText !== &quot;OK&quot;) {<br>    return {<br>      errors: {} as Credentials,<br>      values: { identifier, password } as Credentials,<br>      message: res?.statusText || res,<br>      success: false,<br>    };<br>  }<br><br>  redirect(&quot;/profile&quot;);<br>}</pre><p>Next, set up the login page.</p><h3>Set Up Login Page</h3><p>Head over to the nextjs-frontend/src/app/auth/login/page.tsx file and add the following code:</p><pre>// Path: nextjs-frontend/src/app/auth/login/page.tsx<br><br>&quot;use client&quot;;<br><br>import { useActionState } from &quot;react&quot;;<br><br>import { signinAction } from &quot;@/app/actions/auth&quot;;<br>import { FormState } from &quot;@/app/lib/definitions&quot;;<br>import { toast } from &quot;react-toastify&quot;;<br><br>export default function SignIn() {<br>  const initialState: FormState = {<br>    errors: {},<br>    values: {},<br>    message: &quot;&quot;,<br>    success: false,<br>  };<br><br>  const [state, formAction, isPending] = useActionState(<br>    signinAction,<br>    initialState<br>  );<br><br>  if (state.success) {<br>    toast.success(state.message, { position: &quot;top-center&quot; });<br>  }<br><br>  return (<br>    &lt;div className=&quot;flex min-h-screen items-center justify-center bg-gray-100&quot;&gt;<br>      &lt;div className=&quot;w-full max-w-md p-6 space-y-6 bg-white rounded-lg shadow-md&quot;&gt;<br>        &lt;h2 className=&quot;text-2xl font-semibold text-center&quot;&gt;Sign In&lt;/h2&gt;<br><br>        &lt;form action={formAction} className=&quot;space-y-4&quot;&gt;<br>          &lt;p className=&quot;text-red-500 text-center text-sm&quot;&gt;<br>            {!state?.success &amp;&amp; state?.message}<br>          &lt;/p&gt;<br><br>          {/* Email */}<br>          &lt;div&gt;<br>            &lt;label className=&quot;block text-gray-700&quot;&gt;Email&lt;/label&gt;<br>            &lt;input<br>              type=&quot;email&quot;<br>              name=&quot;identifier&quot;<br>              defaultValue={state?.values?.identifier}<br>              placeholder=&quot;Enter your email&quot;<br>              className=&quot;w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500&quot;<br>            /&gt;<br>            {state?.errors.identifier &amp;&amp; (<br>              &lt;p className=&quot;text-red-500 text-sm&quot;&gt;{state?.errors.identifier}&lt;/p&gt;<br>            )}<br>          &lt;/div&gt;<br><br>          {/* Password */}<br>          &lt;div&gt;<br>            &lt;label className=&quot;block text-gray-700&quot;&gt;Password&lt;/label&gt;<br>            &lt;input<br>              type=&quot;password&quot;<br>              name=&quot;password&quot;<br>              defaultValue={state?.values.password}<br>              placeholder=&quot;Enter your password&quot;<br>              className=&quot;w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500&quot;<br>            /&gt;<br>            {state?.errors.password &amp;&amp; (<br>              &lt;p className=&quot;text-red-500 text-sm&quot;&gt;{state?.errors.password}&lt;/p&gt;<br>            )}<br>            &lt;div className=&quot;text-right mt-1&quot;&gt;<br>              &lt;a<br>                href=&quot;/auth/forgot-password&quot;<br>                className=&quot;text-sm text-blue-500 hover:underline&quot;<br>              &gt;<br>                Forgot password?<br>              &lt;/a&gt;<br>            &lt;/div&gt;<br>          &lt;/div&gt;<br><br>          {/* Sign In Button */}<br>          &lt;button<br>            type=&quot;submit&quot;<br>            className=&quot;w-full py-2 text-white bg-blue-500 rounded-lg hover:bg-blue-600 transition&quot;<br>            disabled={isPending}<br>          &gt;<br>            Sign In<br>          &lt;/button&gt;<br>        &lt;/form&gt;<br><br>        {/* Sign Up Link */}<br>        &lt;p className=&quot;text-center text-gray-600 text-sm&quot;&gt;<br>          Don&#39;t have an account?{&quot; &quot;}<br>          &lt;a href=&quot;/auth/signup&quot; className=&quot;text-blue-500 hover:underline&quot;&gt;<br>            Sign Up<br>          &lt;/a&gt;<br>        &lt;/p&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>When you visit the login page at http://localhost:3000/auth/login, you should see the page below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0j68CX1TgKYOk_Xv.png" /></figure><p>After login, the user is redirected to the profile page. Set up the profile page below:</p><h3>Create User Profile Page</h3><p>Inside the nextjs-frontend/src/app folder, create a folder called profile. Inside the profile folder, create a new file called page.tsx and add the following code:</p><pre>// Path: nextjs-frontend/src/app/profile/page.tsx<br><br>import Link from &quot;next/link&quot;;<br>import LogOutButton from &quot;@/app/components/LogOutButton&quot;;<br><br>export default async function Profile() {<br><br>  return (<br>    &lt;div className=&quot;flex min-h-screen items-center justify-center bg-gray-100 px-4&quot;&gt;<br>      &lt;div className=&quot;w-full max-w-md bg-white p-6 rounded-lg shadow-md text-center space-y-6&quot;&gt;<br>        {/* Username */}<br>        &lt;p className=&quot;text-xl font-semibold text-gray-800 capitalize&quot;&gt;<br>          Welcome, John Doe!<br>        &lt;/p&gt;<br><br>        {/* Action Buttons */}<br>        &lt;div className=&quot;flex flex-col sm:flex-row justify-center gap-4&quot;&gt;<br>          &lt;Link<br>            href=&quot;/auth/change-password&quot;<br>            className=&quot;w-full sm:w-auto px-6 py-2 bg-blue-500 text-white rounded-lg shadow-md hover:bg-blue-600 transition&quot;<br>          &gt;<br>            Change Password<br>          &lt;/Link&gt;<br>          &lt;LogOutButton /&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>When you visit the profile page at http://localhost:3000/profile, this is what you should see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gXza9Tc5Weu4bvYO.png" /></figure><h3>Login Demo</h3><p>Log in in the new user:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jKMu_I9du47Dhyo9.gif" /></figure><p>You are now able to log in as a user. Congratulations! See the complete code for this project below.</p><h3>GitHub Repository: Full Code for Strapi and Next.js Authentication Project</h3><p>The complete code for this project can be found in this repo: <a href="https://github.com/Theodore-Kelechukwu-Onyejiaku/strapi-email-and--password-authentication">strapi-email-and-password-authentication</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6428ccd653c0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/strapi/strapi-email-and-password-authentication-with-next-js-15-part-1-6428ccd653c0">Strapi Email and Password Authentication with Next.js 15: Part 1</a> was originally published in <a href="https://medium.com/strapi">Strapi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a Custom Strapi Plugin with Medium and Dev.to APIs — Part 2]]></title>
            <link>https://medium.com/strapi/build-a-custom-strapi-plugin-with-medium-and-dev-to-apis-part-2-941818a91859?source=rss-9323ef8b74c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/941818a91859</guid>
            <category><![CDATA[strapi]]></category>
            <category><![CDATA[medium]]></category>
            <category><![CDATA[strapi-plugin]]></category>
            <category><![CDATA[dev]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Theodore Kelechukwu Onyejiaku]]></dc:creator>
            <pubDate>Thu, 30 Jan 2025 13:36:22 GMT</pubDate>
            <atom:updated>2025-01-30T13:36:22.997Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build a Custom Strapi Plugin with Medium and Dev.to APIs — Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q0R5oYFkSJTYbf42qIag5w.png" /></figure><p>In the previous <a href="https://strapi.io/blog/build-a-custom-strapi-plugin-with-medium-and-devto-apis-part1">part of this tutorial</a>, we learned how to develop <a href="https://strapi.io/">Strapi</a> plugins. We also delved into initializing and customizing a Strapi plugin. Furthermore, we looked at how to create content types for a Strapi plugin and pass data in a Strapi plugin. Finally, we consumed the Dev.to API using our Strapi plugin to publish posts to Dev.</p><p>This is the final part, where you will be able to publish posts to Medium and add pagination and search features.</p><h3>Tutorial Outline</h3><p>This article is in two parts:</p><ul><li><a href="https://strapi.io/blog/build-a-custom-strapi-plugin-with-medium-and-devto-apis-part1">Part 1: Initializing the plugin, content types, and Dev.to API integration</a></li><li><strong>Part 2: Medium API integration, pagination, search functionality, and injection zones</strong></li></ul><h3>Publish To Medium Using Medium API</h3><p>With Strapi headless CMS, we can do much more. Let’s publish a post to Medium from Strapi CMS!</p><h3>Server Side: Create Plugin Service and Modify Plugin Controller Method</h3><p><strong>1. Create a Service for Publishing to Medium</strong><br>We will create a service that will help us publish posts to Medium. Locate the service file ./src/plugins/content-publisher/server/src/services/service.ts and add a new service method called publishPostToMedium as shown below:</p><pre>// Path: ./src/plugins/content-publisher/server/src/services/service.ts<br><br>// ...other codes<br>/**<br> * Publish Post to Medium<br> */<br>async publishPostToMedium(post: any) {<br>  try {<br>    // destructuring the post object<br>    const { title, content, canonicalUrl, tags, banner } = post.blog;<br>    // get the blog tags<br>    const blogTags = tags.map((tag) =&gt; tag.blogTag);<br>    // payload to be sent to medium<br>    const mediumPayload = {<br>      title,<br>      content: `${title}\n![Image banner](${banner})\n${content}`,<br>      canonicalUrl,<br>      tags: blogTags,<br>      contentFormat: &quot;markdown&quot;,<br>    };<br>    // post<br>    const response = await axios.post(<br>      `https://api.medium.com/v1/users/${process.env.MEDIUM_USER_ID}/posts`,<br>      mediumPayload,<br>      {<br>        headers: {<br>          Authorization: `Bearer ${process.env.MEDIUM_API_TOKEN}`,<br>          &quot;Content-Type&quot;: &quot;application/json&quot;,<br>        },<br>      },<br>    );<br>    // get the medium url<br>    const mediumUrl = response.data?.data?.url;<br>    // update the post with the medium link<br>    await strapi.documents(&quot;plugin::content-publisher.post&quot;).update({<br>      documentId: post.documentId,<br>      data: {<br>        mediumLink: mediumUrl,<br>      } as Partial&lt;any&gt;,<br>    });<br>    // return the response<br>    return response.data;<br>  } catch (error) {<br>    throw error;<br>  }<br>}</pre><p><a href="https://gist.github.com/Theodore-Kelechukwu-Onyejiaku/75ff1a916c0172b598455192698f78e1">👉 See complete code of the snippet above</a></p><p>Similar to publishPostToDevTo, the publishPostToMedium function above does the following:</p><ul><li>Takes a post object as an argument.</li><li>Extracts relevant information from the post.blog object, including title, content, canonicalUrl, tags, and banner.</li><li>Prepares a payload for the Medium API, formatting the content and tags appropriately.</li><li>Makes a POST request to the Medium API to create a new post.</li><li>After successfully posting to Medium, it retrieves the URL of the newly created Medium post.</li><li>Uses Strapi’s Document Service API to update the post entry. It calls the update method on the strapi.documents service for the &quot;plugin::content-publisher.post content-type. It provides the documentId of the post to update. In the data object, the mediumLink field is set to the URL of the newly created Medium post.</li></ul><p><strong>2. Update </strong><strong>publishPostToMedium Controller</strong><br>Update the plugin controller method publishPostToMedium with the following code:</p><pre>// Path: ./src/plugins/content-publisher/server/src/controllers/controller.ts<br><br>import type { Core } from &#39;@strapi/strapi&#39;;<br>const controller = ({ strapi }: { strapi: Core.Strapi }) =&gt; ({<br>  // get blog entries<br>  async getBlogs(ctx) {},<br>  // get posts<br>  async getPosts(ctx) {<br>    ctx.body = await strapi.plugin(&#39;content-publisher&#39;).service(&#39;service&#39;).getPosts();<br>  },<br>  // publish a blog post to dev.to<br>  async publishPostToDevTo(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .publishPostToDevTo(ctx.request.body);<br>  },<br>  // publish a blog post to medium<br>  async publishPostToMedium(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .publishPostToMedium(ctx.request.body);<br>  },<br>  // search for a post<br>  async getSearchQuery(ctx) {},<br>  // delete a post<br>  async deletePost(ctx) {},<br>  // get a single post<br>  async getSinglePost(ctx) {},<br>});<br>export default controller;</pre><p>The publishPostToMedium controller method is now modified to call the publishPostToMedium service we created above.</p><p>Now, go ahead and publish a post to Medium.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*qiy8RKR9mFrnIMkb.gif" /></figure><h3>Inject a Strapi Plugin to a Collection Type Using Injection Zones</h3><p>So far, we have only been able to publish a post from the home page of our plugin. In this section, let’s demonstrate the use of <a href="https://docs.strapi.io/dev-docs/plugins/admin-panel-api#injection-zones-api">injection zones</a> in a Strapi plugin.</p><p>The injection zone feature allows plugins to add custom UI elements to specific areas of the Strapi admin panel. In this case, our content-publisher plugin will add a component to the right side of the edit view in the Content Manager. This is so we can publish directly from the <strong>Blog</strong> content manager.</p><p>Here is what it should look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*8AvCNr9o1MX1FcvZ.png" /></figure><p><em>Injected component</em></p><p>As shown in the image above, we injected a component to help us publish a blog directly in the content manager.</p><h3>Step 1: Create a Component for Injection</h3><p>We will start by creating the component we want to inject into the component manager.</p><p>Mind you, we only want this component to be visible on the <strong>Blog</strong> collection type. So, we will need to use the unstable_useContentManagerContext hook, which is a replacement for the <a href="https://docs.strapi.io/dev-docs/migration/v4-to-v5/additional-resources/helper-plugin#usecmeditviewdatamanager">useCMEditViewDataManager</a>. This hook accesses data and functionality related to the Edit View in the Content Manager such as the ID and slug of the content type.</p><p>Inside the ./src/plugins/content-publisher/admin/src/components folder, create the file InjectedComponent.tsx and add the following code:</p><pre>// Path: ./src/plugins/content-publisher/admin/src/components/InjectedComponent.tsx<br><br>import React from &#39;react&#39;;<br>import { Box, Flex, Typography, Divider } from &#39;@strapi/design-system&#39;;<br>import { unstable_useContentManagerContext } from &#39;@strapi/strapi/admin&#39;;<br>import axios from &#39;axios&#39;;<br>import { useEffect, useState } from &#39;react&#39;;<br>import PublishButton from &#39;./PublishButton&#39;;<br>import MediumIcon from &#39;./MediumIcon&#39;;<br>import DevToIcon from &#39;./DevToIcon&#39;;<br>export default function InjectedComponent() {<br>  // get the blog id<br>  const { slug, id } = unstable_useContentManagerContext();<br>  const [post, setPost] = useState({<br>    mediumLink: &#39;&#39;,<br>    devToLink: &#39;&#39;,<br>    blog: null,<br>  });<br>  // fetch single post<br>  const fetchSinglePost = async () =&gt; {<br>    const post = await axios.get(`/content-publisher/single-post?blogId=${id}`);<br>    setPost(post.data);<br>  };<br>  // fetch single post<br>  useEffect(() =&gt; {<br>    fetchSinglePost();<br>  }, []);<br>  // check if the slug is not blog<br>  if (slug !== &#39;api::blog.blog&#39;) return null;<br>  return (<br>    &lt;Box&gt;<br>      {post ? (<br>        &lt;&gt;<br>          &lt;Typography variant=&quot;beta&quot; padding={30}&gt;<br>            Publish to:<br>          &lt;/Typography&gt;<br>          &lt;Box marginTop={5}&gt;<br>            &lt;Flex<br>              gap={{<br>                large: 2,<br>              }}<br>              direction={{<br>                initial: &#39;row&#39;,<br>              }}<br>              alignItems={{<br>                initial: &#39;center&#39;,<br>              }}<br>            &gt;<br>              &lt;Typography variant=&quot;sigma&quot;&gt;Medium&lt;/Typography&gt;<br>            &lt;/Flex&gt;<br>            &lt;PublishButton post={post} type=&quot;medium&quot; /&gt;<br>            &lt;Divider /&gt;<br>          &lt;/Box&gt;<br>          &lt;Box padding={30}&gt;<br>            &lt;Divider marginBottom={4} /&gt;<br>            &lt;Flex<br>              gap={{<br>                large: 2,<br>              }}<br>              direction={{<br>                initial: &#39;row&#39;,<br>              }}<br>              alignItems={{<br>                initial: &#39;center&#39;,<br>              }}<br>            &gt;<br>              &lt;Typography variant=&quot;sigma&quot;&gt;Dev.to&lt;/Typography&gt;<br>            &lt;/Flex&gt;<br>            &lt;PublishButton post={post} type=&quot;devto&quot; /&gt;<br>          &lt;/Box&gt;<br>        &lt;/&gt;<br>      ) : null}<br>    &lt;/Box&gt;<br>  );<br>}</pre><p>Let’s break down the code above:</p><ul><li>The component uses the hook unstable_useContentManagerContext from Strapi&#39;s admin panel which retrieves the id and slug of the blog entry.</li><li>It fetches data about a single post using the API endpoint /content-publisher/single-post, which we created in the first part of this tutorial series. We will soon create the service and update the controller for this. It sends a request by adding the parameter blogId=${id}. Recall that the id was gotten using the unstable_useContentManagerContext() hook.</li><li>The component only renders content with the slug as api::blog.blog, which corresponds to <strong>Blog</strong> collection type.</li><li>We imported the PublishButton, which accepts the post we fetched as a parameter. This will allow us to be able to publish to Dev and Medium from the <strong>Blog</strong> collection type.</li></ul><h3>Step 2: Create Service and Update Controller To Fetch Single Post</h3><p><strong>Update </strong><strong>getSinglePost Controller Method</strong><br>Do you recall the getSinglePost controller method we created in <a href="https://strapi.io/blog/build-a-custom-strapi-plugin-with-medium-and-devto-apis-part1">Part 1</a> of this tutorial that should be called when we make a GET request to the /single-post endpoint? We will update it with the following code:</p><pre>// Path: ./src/plugins/content-publisher/server/src/controllers/controller.ts<br><br>import type { Core } from &#39;@strapi/strapi&#39;;<br>const controller = ({ strapi }: { strapi: Core.Strapi }) =&gt; ({<br>  // get blog entries<br>  async getBlogs(ctx) {},<br>  // get posts<br>  async getPosts(ctx) {<br>    ctx.body = await strapi.plugin(&#39;content-publisher&#39;).service(&#39;service&#39;).getPosts();<br>  },<br>  // publish a blog post to dev.to<br>  async publishPostToDevTo(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .publishPostToDevTo(ctx.request.body);<br>  },<br>  // publish a blog post to medium<br>  async publishPostToMedium(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .publishPostToMedium(ctx.request.body);<br>  },<br>  // get a single post<br>  async getSinglePost(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .getSinglePost(ctx.request.query);<br>  },<br>  // search for a post<br>  async getSearchQuery(ctx) {},<br>  // delete a post<br>  async deletePost(ctx) {},<br>});<br>export default controller;</pre><p>In the code above:</p><ul><li>We used Strapi’s plugin API to access a service method. strapi.plugin(&#39;content-publisher&#39;) accesses the &quot;content-publisher&quot; plugin.</li><li>.service(&#39;service&#39;) retrieves the main service of the plugin.</li><li>getSinglePost(ctx.request.query) calls the getSinglePost method of the service, which we will create soon, passing in the query parameters from the request. Recall that the query parameter is the blog ID (blogId=${id}) as explained in the injected component above.</li><li>The result of the service method call is then assigned to ctx.body, which sets the response body for the HTTP request.</li></ul><p><strong>Create </strong><strong>getSinglePost Service</strong><br>Inside the the service file, create the getSinglePost service method.</p><pre>// ./src/plugins/content-publisher/server/src/services/service.ts<br><br>// ... other codes<br>/**<br> * FETCH SINGLE Post<br> */<br>async getSinglePost(query: any) {<br>  // get blogId from query<br>  const { blogId } = query;<br>  try {<br>    // find the post<br>    const post = await strapi.documents(&#39;plugin::content-publisher.post&#39;).findFirst({<br>      populate: {<br>        blog: {<br>          populate: [&#39;tags&#39;],<br>        },<br>      },<br>      // filter the post by blogId<br>      filters: {<br>        blog: {<br>          documentId: {<br>            $eq: blogId,<br>          },<br>        },<br>      },<br>    });<br>    // return the post<br>    return post;<br>  } catch (error) {<br>    throw error;<br>  }<br>}<br><br>// ... other codes</pre><p><a href="https://gist.github.com/Theodore-Kelechukwu-Onyejiaku/d3e2dcda1c4aa527b5620c0185d9083a">👉 See complete code of the snippet above</a>.</p><p>Here is what the code above does:</p><ul><li>The getSinglePost method takes a query parameter of type any.</li><li>It extracts the blogId from the query parameter. The main functionality is wrapped in a try-catch block for error handling.</li><li>strapi.documents(&#39;plugin::medium-publisher.post&#39;) accesses the <strong>Post</strong> content-type of the &#39;content-publisher&#39; plugin.</li><li>findFirst() is used to find the first document matching the given criteria. It populates the &#39;blog&#39; field and its &#39;tags&#39;. It looks for a post where the related blog&#39;s documentId equals the provided blogId using the $eq operator. Learn more about <a href="https://docs.strapi.io/dev-docs/api/rest/filters-locale-publication">filtering</a>.</li><li>The found post is then returned.</li><li>If an error occurs, it’s caught in the catch block and re-thrown.</li></ul><h3>Step 1: Register an Injection Zone in Strapi</h3><p>Inside the ./src/plugins/content-publisher/admin/src/index.ts file, which is the Admin Panel API entry file, register an injection zone:</p><pre>// ./src/plugins/content-publisher/admin/src/index.ts<br><br>// from this<br>app.registerPlugin({<br>  id: PLUGIN_ID,<br>  initializer: Initializer,<br>  isReady: false,<br>  name: PLUGIN_ID,<br>});<br><br>// to this<br>app.registerPlugin({<br>  id: PLUGIN_ID,<br>  initializer: Initializer,<br>  isReady: false,<br>  name: PLUGIN_ID,<br>  injectionZones: {<br>    editView: {<br>      &quot;right-links&quot;: [],<br>    },<br>  },<br>});</pre><p>We modified the registerPlugin function by declaring an injection zone named &#39;right-links&#39; in the &#39;editView&#39; of the Content Manager. It&#39;s initially empty (an empty array). This will allow us to inject the component on the right side of the <strong>Blog</strong> content manager.</p><h3>Step 2: Inject Component Using bootstrap() Lifecycle</h3><p>Let’s inject the InjectedComponent into the &#39;right-links&#39; zone of the &#39;editView&#39; using the bootstrap function.</p><pre>async bootstrap(app: any) {<br>  app.getPlugin(&quot;content-manager&quot;).injectComponent(&quot;editView&quot;, &quot;right-links&quot;, {<br>    name: &quot;content-publisher&quot;,<br>    Component: () =&gt; &lt;InjectedComponent /&gt;,<br>  });<br>}</pre><p>This injects the InjectedComponent into the &#39;right-links&#39; zone of the &#39;editView&#39;. The InjectedComponent component will now be rendered in the injection zone.</p><p>Here is the full code of our modified Admin Panel API entry file:</p><pre>// Path: ./src/plugins/content-publisher/admin/src/index.ts<br><br>import React from &#39;react&#39;;<br>import { getTranslation } from &#39;./utils/getTranslation&#39;;<br>import { PLUGIN_ID } from &#39;./pluginId&#39;;<br>import { Initializer } from &#39;./components/Initializer&#39;;<br>import { PluginIcon } from &#39;./components/PluginIcon&#39;;<br>import InjectedComponent from &#39;./components/InjectedComponent&#39;;<br>export default {<br>  register(app: any) {<br>    app.addMenuLink({<br>      to: `plugins/${PLUGIN_ID}`,<br>      icon: PluginIcon,<br>      intlLabel: {<br>        id: `${PLUGIN_ID}.plugin.name`,<br>        defaultMessage: PLUGIN_ID,<br>      },<br>      Component: async () =&gt; {<br>        const { App } = await import(&#39;./pages/App&#39;);<br>        return App;<br>      },<br>    });<br>    app.registerPlugin({<br>      id: PLUGIN_ID,<br>      initializer: Initializer,<br>      isReady: false,<br>      name: PLUGIN_ID,<br>      injectionZones: {<br>        editView: {<br>          &#39;right-links&#39;: [],<br>        },<br>      },<br>    });<br>  },<br>  async bootstrap(app: any) {<br>    app.getPlugin(&#39;content-manager&#39;).injectComponent(&#39;editView&#39;, &#39;right-links&#39;, {<br>      name: &#39;content-publisher&#39;,<br>      Component: () =&gt; &lt;InjectedComponent /&gt;,<br>    });<br>  },<br>  async registerTrads({ locales }: { locales: string[] }) {<br>    return Promise.all(<br>      locales.map(async (locale) =&gt; {<br>        try {<br>          const { default: data } = await import(`./translations/${locale}.json`);<br>          return { data, locale };<br>        } catch {<br>          return { data: {}, locale };<br>        }<br>      })<br>    );<br>  },<br>};</pre><h3>Step 3: Publish content directly from the Content Manager</h3><p>Now, we can publish content directly from the <strong>Blog</strong> content manager of the admin panel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*N0QU5oPhruyTMa_6.gif" /></figure><blockquote><em>🖐️ </em><strong><em>NOTE:</em></strong><em> If you can’t get your component to be displayed. You can follow the instructions below.</em></blockquote><h3>Instruction on How to Display Injected Component</h3><ul><li>Try changing the ./src/plugins/content-publisher/server/src/index.ts file to ./src/plugins/content-publisher/server/src/index.tsx - change .ts to .tsx.</li><li>Correspondingly, modify&quot;source&quot;: &quot;./admin/src/index.ts&quot; inside the package.json file of your plugin(./src/plugins/content-publisher/package.json) ... to &quot;source&quot;: &quot;./admin/src/index.tsx&quot; - change .ts to .tsx.</li></ul><pre>// ... other codes<br>&quot;exports&quot;: {<br>    &quot;./package.json&quot;: &quot;./package.json&quot;,<br>    &quot;./strapi-admin&quot;: {<br>      &quot;types&quot;: &quot;./dist/admin/src/index.d.ts&quot;,<br>      &quot;source&quot;: &quot;./admin/src/index.tsx&quot;, // change ts =&gt; tsx<br>      &quot;import&quot;: &quot;./dist/admin/index.mjs&quot;,<br>      &quot;require&quot;: &quot;./dist/admin/index.js&quot;,<br>      &quot;default&quot;: &quot;./dist/admin/index.js&quot;<br>    },<br>// ... other codes</pre><ul><li>Build your Strapi application by stopping the development server and running strapi build. Do the same for the plugin.</li><li>Restart your Strapi dev server with npm run develop. CD into the plugin folder and start your plugin in watch mode with npm run watch.</li></ul><h3>Add Pagination to Strapi Plugin</h3><p>Now that we can publish posts to external platforms such as Medium and Dev, what happens when we have so many posts to publish. Let’s add pagination in order to solve this issue.</p><h3>Strapi Plugin Pagination Logic</h3><p>We want to display only 5 posts per page. So, we will create the following variables:</p><ul><li>currentPage: Tracks the current page number.</li><li>pageCount: Total number of pages, calculated based on the total posts and posts per page.</li><li>postsPerPage: Number of posts to display per page (set to 5).</li></ul><p>We will also create the function handleFetchPosts to calculate the start index for the API request based on the currentPage. Then, an API request will be made to /content-publisher/posts with query parameter for pagination: start=${start}.</p><p>Lastly, we will render buttons based on the pagination number.</p><p>Here is what our pagination should look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*8DD-WO5k-ET1p1m9.png" /></figure><p><em>Plugin Pagination Tabs</em></p><h3>Step 1: Update getPosts Controller Method for Pagination</h3><p>Let’s update the getPosts controller method to accept the parameters for pagination.</p><pre>// ./src/plugins/content-publisher/server/src/controllers/controller.ts<br><br>import type { Core } from &#39;@strapi/strapi&#39;;<br>const controller = ({ strapi }: { strapi: Core.Strapi }) =&gt; ({<br>  // get blog entries<br>  async getBlogs(ctx) {},<br>  // get posts<br>  async getPosts(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .getPosts(ctx.query);<br>  },<br>  // publish a blog post to dev.to<br>  async publishPostToDevTo(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .publishPostToDevTo(ctx.request.body);<br>  },<br>  // publish a blog post to medium<br>  async publishPostToMedium(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .publishPostToMedium(ctx.request.body);<br>  },<br>  // get a single post<br>  async getSinglePost(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .getSinglePost(ctx.request.query);<br>  },<br>  // search for a post<br>  async getSearchQuery(ctx) {},<br>  // delete a post<br>  async deletePost(ctx) {},<br>});<br>export default controller;</pre><p>In the code above, we updated the getPosts controller method to accept query parameters.</p><h3>Step 2: Update getPosts Service for Pagination</h3><p>Update the getPosts service method with the code below in order to return paginations.</p><pre>// ./src/plugins/content-publisher/server/src/services/service.ts<br>// ... other codes<br>const postPerPage = 5;<br>// ... other codes<br>/**<br>   * GET Posts with Pagination<br>   */<br>  async getPosts(query: any) {<br>    try {<br>      // get start from query params<br>      const { start } = query;<br>      // get total posts count<br>      const totalPosts = await strapi.documents(&#39;plugin::content-publisher.post&#39;).count({});<br>      // get posts<br>      const posts = await strapi.documents(&#39;plugin::content-publisher.post&#39;).findMany({<br>        populate: {<br>          blog: {<br>            populate: [&#39;tags&#39;],<br>          },<br>        },<br>        // return only 5 posts from the start index<br>        start,<br>        limit: postPerPage,<br>      });<br>      // return the posts and total posts<br>      return { posts, totalPosts };<br>    } catch (error) {<br>      throw error;<br>    }<br>  },<br><br>// ... other codes</pre><p><a href="https://gist.github.com/Theodore-Kelechukwu-Onyejiaku/a2789cc62b09147a7d08c70fab6c1fc9">👉 See complete code of the snippet above</a></p><p>We created a constant postPerPage and gave it a value of 5, the number of posts we want to see for a page. We updated the getPosts method.</p><p>Here is what the getPosts method does:</p><ul><li>Takes a query parameter, which we get the start index for pagination.</li><li>Counts the total number of posts using the count method and assigns the value to totalPosts.</li><li>Retrieves the posts based on findMany.</li><li>The findMany takes parameters populate, which populates the blog relation and further populates the tags relation within the blog. It also takes parameters start, the starting index for pagination, and parameter limit, which is the number of posts to return (defined by the postPerPage variable).</li></ul><h3>Step 3: Update PublishingTable for Pagination</h3><p>Here, we will update the PublishingTable component to render as a pagination.</p><p><strong>Import Pagination Components from Strapi Design System</strong></p><p>Locate the ./src/plugins/content-publisher/admin/src/components/PublishingTable.tsx file. We will start by importing components for pagination.</p><ul><li>PageLink for a page we want to visit.</li><li>previousLink for a previous page.</li><li>Pagination as parent component for all other components.</li></ul><pre>// Path: ./src/plugins/content-publisher/admin/src/components/PublishingTable.tsx <br><br>import {<br>  // ... other components<br>  PageLink,<br>  Pagination,<br>  PreviousLink,<br>  NextLink,<br>} from &#39;@strapi/design-system&#39;;<br>// ... other codes</pre><p><strong>Create Pagination Variables</strong></p><p>We will create state variables pageCount, currentPage, and postsPerpage as we mentioned earlier in our pagination logic.</p><pre>// Path: `./src/plugins/content-publisher/admin/src/components/PublishingTable.tsx` <br><br>// ... other codes<br>const [pageCount, setPageCount] = useState(1);<br>const [currentPage, setCurrentPage] = useState(1);<br>const postsPerPage = 5;<br>// ... other code</pre><p><strong>Update </strong><strong>handleFetchPosts function</strong><br>We will update the handleFetchPosts function to make a request with the start query parameter.</p><pre>/// Path: ./src/plugins/content-publisher/admin/src/components/PublishingTable.tsx<br><br>// ... other codes<br>const handleFetchPosts = async (page: number) =&gt; {<br>  // Calculate the start index<br>  const start = (page - 1) * postsPerPage;<br>  try {<br>    const response = await axios.get(<br>      `/content-publisher/posts?start=${start}`,<br>    );<br>    setPosts(response.data.posts);<br>    setPageCount(Math.ceil(response.data.totalPosts / postsPerPage));<br>  } catch (error) {<br>    console.error(&quot;Error fetching posts:&quot;, error);<br>  }<br>};<br>// .. other codes</pre><p><strong>Create Function to Handle Page Change</strong><br>We want a function to handle page changes when we switch between pagination tabs. Create the handlePageChange function below.</p><pre>// ./src/plugins/content-publisher/admin/src/components/PublishingTable.tsx<br><br> // ... other codes<br>const handlePageChange = (e: FormEvent, page: number) =&gt; {<br>  // Prevent the default behavior of the link<br>  if (page &lt; 1 || page &gt; pageCount) return;<br>  setCurrentPage(page);<br>  handleFetchPosts(page);<br>};<br>// ... other codes</pre><p>The handlePage function takes a parameter which is the page number and the event. It prevents the default behaviour of the button in which it will be invoked, sets current page to the page number clicked and then fetches posts.</p><p><strong>Render Pagination</strong></p><pre>// ./src/plugins/content-publisher/admin/src/components/PublishingTable.tsx<br><br>// ... other codes<br>{<br>  posts.length &gt; 0 ? (<br>    &lt;Pagination activePage={currentPage} pageCount={pageCount}&gt;<br>      &lt;PreviousLink<br>        onClick={(e: FormEvent) =&gt; handlePageChange(e, currentPage - 1)}<br>      &gt;<br>        Go to previous page<br>      &lt;/PreviousLink&gt;<br>      {Array.from({ length: pageCount }, (_, index) =&gt; (<br>        &lt;PageLink<br>          key={index}<br>          number={index + 1}<br>          onClick={(e: FormEvent) =&gt; handlePageChange(e, index + 1)}<br>        &gt;<br>          Go to page {index + 1}<br>        &lt;/PageLink&gt;<br>      ))}<br>      &lt;NextLink<br>        onClick={(e: FormEvent) =&gt; handlePageChange(e, currentPage + 1)}<br>      &gt;<br>        Go to next page<br>      &lt;/NextLink&gt;<br>    &lt;/Pagination&gt;<br>  ) : null;<br>}<br>// ... other codes</pre><p>Here is what we did in the code above:</p><ul><li>The &lt;Pagination&gt; component takes two props: activePage and pageCount</li><li>&lt;PreviousLink&gt; is used to navigate to the previous page. When clicked, it calls handlePageChange with the current page number minus 1.</li><li>An array of page links is generated using Array.from().</li><li>For each page, a &lt;PageLink&gt; component is created. It&#39;s given a unique key based on the index. The number prop is set to the page number. When clicked, it calls handlePageChange with the corresponding page number.</li><li>&lt;NextLink&gt; is used to navigate to the next page. When clicked, it calls handlePageChange with the current page number plus 1.</li></ul><p>Let’s see this in action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*V__7yJiKfnbfUhpu.gif" /></figure><p>Congratulations! We have added pagination. Next, let’s add the Search functionality.</p><p><a href="https://gist.github.com/Theodore-Kelechukwu-Onyejiaku/8904ae9fca54a1b1b38c71361f52b9b3">👉 See full code of the snippet for the </a><a href="https://gist.github.com/Theodore-Kelechukwu-Onyejiaku/8904ae9fca54a1b1b38c71361f52b9b3">PublishingTable Component above</a>.</p><h3>Add Search Feature to Plugin</h3><p>Pagination has now been added to our plugin, but what happens when we want to find a particular post by blog title? For this reason, let’s add a search functionality.</p><h3>Search Feature Logic</h3><p>We want to implement a search feature to filter posts based on user input. So, we will create the following:</p><ul><li>searchValue: A variable that tracks the user&#39;s search input.</li><li>handleSearchPost: A function to make an API request to /content-publisher/search with the search term (searchValue) and fetch matching posts. The request is sent using the query parameter: search=${searchValue}. If the search input is empty, the function will exit early to avoid unnecessary API calls.</li><li>The returned results will update the posts state to display only the matching posts.</li></ul><p>Here is what the search bar should look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*1f1hq3TRpleisp-T.png" /></figure><p><em>Plugin Search Bar</em></p><h3>Step 1: Update getSearchQuery Controller Method for Search</h3><p>We will update the getSearchQuery Controller method to accept query parameters.</p><pre>// Path: ./src/plugins/content-publisher/server/src/controllers/controller.ts</pre><pre>import type { Core } from &#39;@strapi/strapi&#39;;</pre><pre>const controller = ({ strapi }: { strapi: Core.Strapi }) =&gt; ({<br>  // get blog entries<br>  async getBlogs(ctx) {},</pre><pre>  // get posts<br>  async getPosts(ctx) {<br>    ctx.body = await strapi.plugin(&#39;content-publisher&#39;).service(&#39;service&#39;).getPosts(ctx.query);<br>  },</pre><pre>  // publish a blog post to dev.to<br>  async publishPostToDevTo(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .publishPostToDevTo(ctx.request.body);<br>  },</pre><pre>  // publish a blog post to medium<br>  async publishPostToMedium(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .publishPostToMedium(ctx.request.body);<br>  },</pre><pre>  // get a single post<br>  async getSinglePost(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .getSinglePost(ctx.request.query);<br>  },</pre><pre>  // search for a post<br>  async getSearchQuery(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .getSearchQuery(ctx.request.query);<br>  },</pre><pre>  // delete a post<br>  async deletePost(ctx) {},<br>});</pre><pre>export default controller;</pre><h3>Step 2: Create a getSearchQuery Service Method for Search Feature</h3><p>Inside the ./src/plugins/content-publisher/server/src/services/service.ts file, we will create the getSearchQuery method to help us fetch the requested query.</p><pre>// Path: ./src/plugins/content-publisher/server/src/services/service.ts</pre><pre>// ... other codes</pre><pre>/**<br> * Search Query<br> */<br>async getSearchQuery(query: { search: string; start: number }) {<br>  try {<br>    // get search and start from query<br>    const { search, start } = query;</pre><pre>    // find total posts<br>    const totalPosts = await strapi<br>      .documents(&quot;plugin::medium-publisher.post&quot;)<br>      .findMany({<br>        filters: {<br>          blog: { title: { $contains: search } },<br>        },<br>      });</pre><pre>    // find posts<br>    const posts = await strapi<br>      .documents(&quot;plugin::medium-publisher.post&quot;)<br>      .findMany({<br>        populate: {<br>          blog: {<br>            populate: [&quot;tags&quot;],<br>          },<br>        },<br>        // filter only blog titles that contains the search query<br>        filters: {<br>          blog: { title: { $contains: search } },<br>        },<br>        // return only 5 posts from the start index<br>        start: start * postPerPage,<br>        limit: postPerPage,<br>      });</pre><pre>    // return the posts and total posts<br>    return { posts, totalPosts: totalPosts.length };<br>  } catch (error) {<br>    throw error;<br>  }<br>},</pre><pre>// ... other codes</pre><p><a href="https://gist.github.com/Theodore-Kelechukwu-Onyejiaku/ea16e90e2ef97a1c0d24af0197a4adf9">👉 See complete code of the snippet above</a></p><p>Here is what the method above does:</p><ul><li>Takes a query object as an argument, which contains search (the search term) and start (the starting index for pagination) properties.</li><li>Uses the $contains filter to find posts where the blog title contains the search term.</li><li>The second query includes pagination (start and limit) and populates the blog relation along with its tags.</li><li>The method then returns an object containing the found posts and the total number of posts matching the search criteria.</li></ul><h3>Step 3: Update PublishingTable Component for the Search Feature</h3><p>Let’s update the PublishingTable component file ./src/plugins/content-publisher/admin/src/components/PublishingTable.tsx so as to implement and display the search feature.</p><p><strong>Import Search Bar Components</strong><br>We will import components from the Strapi design system that exists for the search user interface.</p><pre>// Path: ./src/plugins/content-publisher/admin/src/components/PublishingTable.tsx</pre><pre>// ... other codes</pre><pre>import {<br>  // ... other codes</pre><pre>  SearchForm,<br>  Searchbar,<br>}</pre><pre>// ... other codes</pre><p>In the code above, we imported the SearchForm component which is the form for the search. Also, we imported the Searchbar component which will serves as the input of our search value or key.</p><p><strong>Create </strong><strong>handleSearchPost Method</strong><br>Create a method called handleSearchPost, which will handle search requests for posts.</p><pre>// Path: ./src/plugins/content-publisher/admin/src/components/PublishingTable.tsx</pre><pre>// ... other codes</pre><pre>const handleSearchPost = async (event: FormEvent, page: number | null) =&gt; {<br>  event.preventDefault(); // Prevent the default form submission behavior<br>  let start;<br>  if (page === null) {<br>    start = 0;<br>  } else {<br>    start = (page - 1) * postsPerPage; // Calculate the start index for the paginated search<br>  }</pre><pre>  // If the search input is empty, return early<br>  if (!searchValue.trim()) {<br>    return;<br>  }</pre><pre>  try {<br>    // Make a GET request to the search endpoint<br>    const response = await axios.get(<br>      `/content-publisher/search?start=${start}&amp;search=${searchValue}`,<br>    );</pre><pre>    setPosts(response.data.posts); // Assuming the API returns matching posts<br>    setPageCount(Math.ceil(response.data.totalPosts / postsPerPage));<br>  } catch (error) {<br>    console.error(&quot;Error searching posts:&quot;, error);<br>  }<br>};</pre><pre>// ... other codes</pre><p>In the code above, the handleSearchPost sends a search query to /content-publisher/search with pagination (start and search query parameters). It updates posts and pageCount based on the API response.</p><p><strong>Modify </strong><strong>handlePageChange Method to Include Search</strong><br>Let&#39;s modify the handlePageChange method to include the handleSearchPost function.</p><pre>// Path: ./src/plugins/content-publisher/admin/src/components/PublishingTable.tsx</pre><pre>// ... other codes</pre><pre>const handlePageChange = (e: FormEvent, page: number) =&gt; {<br>  if (page &lt; 1 || page &gt; pageCount) return;<br>  setCurrentPage(page);</pre><pre>  if (searchValue) {<br>    handleSearchPost(e, page);<br>  } else {<br>    handleFetchPosts(page);<br>  }<br>};</pre><pre>// ... other codes</pre><p>The handlePageChange now updates currentPage and fetches data for the selected page. It determines whether to fetch default posts (handleFetchPosts) or search results (handleSearchPost) based on searchValue.</p><p><strong>Render Search Bar</strong><br>Let’s render the search bar in the PublishingTable component.</p><pre>// Path: ./src/plugins/content-publisher/admin/src/components/PublishingTable.tsx</pre><pre>// ... other codes</pre><pre>&lt;SearchForm<br>  onSubmit={(e: FormEvent) =&gt; {<br>    handleSearchPost(e, null);<br>  }}<br>&gt;<br>  &lt;Searchbar<br>    size=&quot;M&quot;<br>    name=&quot;searchbar&quot;<br>    onClear={() =&gt; {<br>      setSearchValue(&quot;&quot;);<br>      handleFetchPosts(1);<br>    }}<br>    value={searchValue}<br>    onChange={(e: any) =&gt; setSearchValue(e.target.value)}<br>    clearLabel=&quot;Clearing the plugin search&quot;<br>    placeholder=&quot;e.g: blog title&quot;<br>  &gt;<br>    Searching for a plugin<br>  &lt;/Searchbar&gt;<br>&lt;/SearchForm&gt;;</pre><pre>// ... other codes</pre><p>The code above renders a search form with a search bar to filter posts based on user input. When the form is submitted, it triggers the handleSearchPost function to fetch filtered results. The onClear handler resets the search value and fetches the default posts for page 1, while onChange updates the searchValue state as the user types.</p><p>Here is how the search works:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*MpTJx1RtdODZ818F.gif" /></figure><p><a href="https://gist.github.com/Theodore-Kelechukwu-Onyejiaku/f8a18fd806cf6e7bc25c7d0c12ceb60b">👉 See full code snippet for the </a><a href="https://gist.github.com/Theodore-Kelechukwu-Onyejiaku/f8a18fd806cf6e7bc25c7d0c12ceb60b">PublishingTable Component</a></p><h3>Add Delete Feature</h3><p>What happens when we don’t need a particular post entry?</p><p>For this reason, we want to be able to delete a post. So, let’s implement a delete feature. All we need to do is send a DELETE request with the post ID as a query parameter to the /delete-post endpoint.</p><h3>Update deletePost Controller Method</h3><p>In the controller file ./src/plugins/content-publisher/server/src/controllers/controller.ts, update the deletePost controller method to accept query parameters:</p><pre>// Path: ./src/plugins/content-publisher/server/src/controllers/controller.ts<br></pre><pre>import type { Core } from &#39;@strapi/strapi&#39;;</pre><pre>const controller = ({ strapi }: { strapi: Core.Strapi }) =&gt; ({<br>  // get blog entries<br>  async getBlogs(ctx) {},</pre><pre>  // get posts<br>  async getPosts(ctx) {<br>    ctx.body = await strapi.plugin(&#39;content-publisher&#39;).service(&#39;service&#39;).getPosts(ctx.query);<br>  },</pre><pre>  // publish a blog post to dev.to<br>  async publishPostToDevTo(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .publishPostToDevTo(ctx.request.body);<br>  },</pre><pre>  // publish a blog post to medium<br>  async publishPostToMedium(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .publishPostToMedium(ctx.request.body);<br>  },</pre><pre>  // get a single post<br>  async getSinglePost(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .getSinglePost(ctx.request.query);<br>  },</pre><pre>  // search for a post<br>  async getSearchQuery(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .getSearchQuery(ctx.request.query);<br>  },</pre><pre>  // delete a post<br>  async deletePost(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&#39;content-publisher&#39;)<br>      .service(&#39;service&#39;)<br>      .deletePost(ctx.request.query);<br>  },<br>});</pre><pre>export default controller;</pre><h3>Create a Service For Deleting a Post</h3><p>Inside the ./src/plugins/content-publisher/server/src/services/service.ts, create a service to delete a post.</p><pre>// Path: ./src/plugins/content-publisher/server/src/services/service.ts</pre><pre>// ... other codes</pre><pre>/**<br> * DELETE Post<br> */<br>async deletePost(query: { postId: string }) {<br>  try {<br>    // get postId from query<br>    const { postId } = query;</pre><pre>    // delete the post<br>    await strapi<br>      .documents(&quot;content::medium-publisher.post&quot;)<br>      .delete({ documentId: postId });</pre><pre>    return &quot;Post deleted&quot;;<br>  } catch (error) {<br>    console.error(&quot;Error deleting post:&quot;, error);<br>    throw error;<br>  }<br>},</pre><pre>// ... other codes</pre><p><a href="https://gist.github.com/Theodore-Kelechukwu-Onyejiaku/76670948685f20db50420addac0f5e29">👉 See complete code of the snippet above</a></p><p>In the deletePost function above, we did the following:</p><ul><li>Takes a query parameter with a postId property of type string.</li><li>Inside a try-catch block, it extracts the postId from the query object using destructuring.</li><li>It then uses Strapi’s Document Service API to delete the post.</li></ul><h3>Update PublishingTable for Deletion of Posts</h3><p>Inside the PublishingTable component, we will have to create a method to handle the deletion of posts. Create the method below:</p><pre>// Path: ./src/plugins/content-publisher/admin/src/components/PublishingTable.tsx<br></pre><pre>// ... other codes<br></pre><pre>const handleDeletePost = async (id: string) =&gt; {<br>  const response: Response = await axios.delete(<br>    `/content-publisher/delete-post?postId=${id}`,<br>    {},<br>  );<br>  handleFetchPosts(1)<br>};</pre><pre>// ... other codes</pre><p>Now, add the onClick event listener to the Trash icon to call the handleDeletePost function when it is clicked.</p><pre>// Path: ./src/plugins/content-publisher/admin/src/components/PublishingTable.tsx</pre><pre>// ... other codes</pre><pre>&lt;Trash<br>  onClick={() =&gt; {<br>    handleDeletePost(post.documentId);<br>  }}<br>  style={{ cursor: &quot;pointer&quot;, color: &quot;red&quot; }}<br>  width={20}<br>  height={20}<br>/&gt;;<br></pre><pre>// ... other codes</pre><p>Here is what deleting a post looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*7e3Z0RiguNmub4Ag.gif" /></figure><p><a href="https://gist.github.com/Theodore-Kelechukwu-Onyejiaku/189ee0c65c83e9f01c9746f3986546ff">👉 See code to full code of the snippet above for the </a><a href="https://gist.github.com/Theodore-Kelechukwu-Onyejiaku/189ee0c65c83e9f01c9746f3986546ff">PublishingTable component</a></p><h3>What’s Next?</h3><p>Congratulations on building your first Strapi CMS plugin. Here are some suggestions on how to improve the Content Publisher plugin.</p><ul><li>Implement batch publishing and deletion.</li><li>Add toast notifications when actions are performed.</li><li>Handle errors properly and display them to users.</li><li>Add other external platforms of your choice.</li></ul><p>We can’t wait to see you build amazing plugins.</p><h3>Github Project Repo</h3><p>You can find the complete project for this tutorial in this <a href="https://github.com/Theodore-Kelechukwu-Onyejiaku/custom-strapi-plugin">Github repo</a>.</p><p>In the repo, you will find branches part-1 and part-2. They both represent the complete code for each part of this tutorial. The main branch will hold future changes to this project.</p><h3>Conclusion</h3><p>In this final part of the Strapi plugin tutorial, we have learnt how to publish posts to Medium, add pagination, implement search functionality, and use injection zones in the Strapi admin panel and more.</p><p>What are you waiting for? Let’s start building plugins!</p><p>Aside from building amazing plugins, Strapi headless CMS offers a range of features tailored to meet your business needs. Try <a href="https://docs.strapi.io/dev-docs/intro">Strapi</a> today.</p><h3>Strapi Open Office Hours</h3><p>If you have any questions about Strapi 5 or just would like to stop by and say hi, you can join us at <strong>Strapi’s Discord Open Office Hours</strong> Monday through Friday at 12:30 pm — 1:30 pm CST: <a href="https://discord.com/invite/strapi">Strapi Discord Open Office Hours</a></p><p>Strapi 5 is available now! <a href="https://strapi.link/medium_redistribution">Start building today</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=941818a91859" width="1" height="1" alt=""><hr><p><a href="https://medium.com/strapi/build-a-custom-strapi-plugin-with-medium-and-dev-to-apis-part-2-941818a91859">Build a Custom Strapi Plugin with Medium and Dev.to APIs — Part 2</a> was originally published in <a href="https://medium.com/strapi">Strapi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to optimize images in Next.js]]></title>
            <link>https://medium.com/@theodoreonyejiaku/how-to-optimize-images-in-next-js-db97ad70f240?source=rss-9323ef8b74c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/db97ad70f240</guid>
            <dc:creator><![CDATA[Theodore Kelechukwu Onyejiaku]]></dc:creator>
            <pubDate>Tue, 28 Jan 2025 16:40:59 GMT</pubDate>
            <atom:updated>2025-01-28T16:40:59.873Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Image banner" src="https://cdn-images-1.medium.com/max/1024/0*jvT87SGcGyN_V_ig.png" /></figure><h4>Introduction</h4><p>This is the introduction</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db97ad70f240" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a Custom Strapi Plugin with Medium and Dev.to APIs — Part 1]]></title>
            <link>https://medium.com/strapi/build-a-custom-strapi-plugin-with-medium-and-dev-to-apis-part-1-86af8b5ff250?source=rss-9323ef8b74c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/86af8b5ff250</guid>
            <category><![CDATA[dev]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[strapi-plugin]]></category>
            <category><![CDATA[strapi]]></category>
            <category><![CDATA[medium]]></category>
            <dc:creator><![CDATA[Theodore Kelechukwu Onyejiaku]]></dc:creator>
            <pubDate>Wed, 22 Jan 2025 12:14:26 GMT</pubDate>
            <atom:updated>2025-01-22T12:14:26.577Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build a Custom Strapi Plugin with Medium and Dev.to APIs — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7gdpQG_O5cKQyF89gaEZwA.png" /></figure><h3>Introduction to Strapi Plugins</h3><p><a href="https://docs.strapi.io/dev-docs/plugins/developing-plugins">Strapi plugins</a> allow you to add extra functionalities and custom features to power up your Strapi application.</p><p>One of the features of the <a href="https://strapi.io/">Strapi CMS</a> is the ability it gives you to unlock the full potential of content management, thus allowing you to build custom features for yourself and the community. <a href="https://strapi.io/user/victor-coisne">Victor Coisne</a>, the VP of marketing at Strapi, explained this in his article <a href="https://playbooks.hypergrowthpartners.com/p/building-communities-that-drive-growth">“Building Communities That Drive Growth”</a>.</p><blockquote><em>“Strapi builds trust and shows that member input matters. They also foster transparency through forums, AMAs, and regular updates that keep members informed and valued.”</em></blockquote><p>In this article, we will build a custom Strapi plugin that will allow us publish contents to <a href="https://medium.com/">Medium</a> and <a href="https://dev.to/">Dev.to</a> using their APIs from the Strapi admin panel.</p><h3>Tutorial Outline</h3><p>This article is divided into two parts:</p><ul><li>Part 1: Initializing the plugin, content types, and Dev.to API integration.</li><li>Part 2: Medium API integration, pagination, search functionality, and injection zones.</li></ul><h3>What you Will Learn</h3><p>In this comprehensive tutorial, you will learn about the following:</p><ul><li>Initializing a Strapi plugin</li><li>Utilizing a Strapi <a href="https://docs.strapi.io/dev-docs/configurations/functions">Lifecycle function</a></li><li>Creating a Content Type for a Strapi plugin and Storing Data</li><li>Passing data from the server to the admin of a Strapi plugin</li><li>Integrating and consuming Medium and Dev APIs with Strapi plugin</li><li>Injecting a Strapi Plugin to a specific collection type with injection zones</li><li>Adding Pagination and Search functionality to a Strapi plugin</li></ul><h3>Prerequisites</h3><p>To follow along with this tutorial, please consider the following:</p><ul><li>A basic knowledge of <a href="https://react.dev/">React</a> is required. Strapi plugins are developed using React.js.</li><li>The latest Node.js runtime installed on your machine.</li><li>A <a href="https://dev.to/t/signup">Dev account</a>.</li><li>A <a href="https://help.medium.com/hc/en-us/articles/115004915268-Sign-in-or-sign-up-to-Medium">Medium account</a>.</li><li>An API platform like <a href="https://www.postman.com/downloads/">Postman</a>.</li></ul><h3>What We Will Be Building</h3><p>One of the <a href="https://strapi.io/features">features</a> of the Strapi CMS is the ability it gives you to unlock the full potential of content management. This means that contents like blog posts can also be published from Strapi to platforms like Medium and Dev.</p><p>In this article, we will make use of Dev API and Medium API, integrate them with Strapi headless CMS to allow us publish contents from the Strapi admin panel to these platforms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*5midhv-Fp2KEU-7x.gif" /></figure><h3>What is a Strapi Plugin?</h3><p>Strapi plugins allow you to extend Strapi core features.</p><p>They can be in 4 forms.</p><ul><li><a href="https://docs.strapi.io/dev-docs/plugins/using-plugins">Built-in plugins</a> like the Upload plugin, Users and Permissions plugin, Email plugin, etc.</li><li>3rd-party plugins developed by the community and can be found in the Strapi <a href="https://market.strapi.io/">Marketplace</a>. Examples include the <a href="https://market.strapi.io/plugins/strapi-plugin-redirects">Redirects</a>, <a href="https://market.strapi.io/plugins/strapi-plugin-strapi-algolia">Algolia</a>, <a href="https://market.strapi.io/providers/@strapi-provider-upload-aws-s3">AWS S3</a>, etc.</li><li>Custom plugins that you can develop on your own and share on the Strapi Marketplace or use alone. An example is the one for this tutorial.</li><li>Extended Strapi plugin. This is when you extend the features of an existing plugin.</li></ul><p>To learn more about Strapi plugins, please visit its Strapi <a href="https://docs.strapi.io/dev-docs/plugins">documentation page</a>.</p><h3>Strapi Design System</h3><p>To develop a Strapi plugin, you will be making use of the <a href="https://design-system.strapi.io/">Strapi design system</a>. This is a collection of typographies, colors, components, icons, etc. that are in line with Strapi brand design.</p><p>The Strapi design system allows you to make Strapi’s contributions more cohesive and to build plugins more efficiently.</p><p>This comes with a new Strapi app.</p><h3>Install Strapi and Create New Collection Types</h3><h4>Install a Strapi 5 Application</h4><p>Install a new <a href="https://strapi.io/five">Strapi 5</a> application by running the command below. For this project, we will be using NPM; you can choose any package manager of your choice:</p><pre># npm<br>npx create-strapi-app@latest<br><br># yarn<br>yarn create strapi<br><br># pnpm<br>pnpm create strapi</pre><p>The name of our project is plugin-project as shown below. The terminal will ask you a few questions. Choose a Yes or a No depending on your setup options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*wfnE4fOfytg-ugzF.png" /></figure><p>From the installation process, the name of our project is plugin-project. Feel free to give it a name of your choice.</p><h4>Start Strapi Application</h4><p>After the successful installation of your Strapi project, you should be able to start your Strapi application.</p><p>CD into your Strapi project:</p><pre>cd plugin-project</pre><p>Run the command below to start your Strapi development server:</p><pre>npm run develop</pre><p>The command above will redirect you to the Strapi admin registration page. Ensure you create a new admin user.</p><h3>Create New Strapi Content Types</h3><p><a href="https://docs.strapi.io/dev-docs/backend-customization/models">Strapi content types or models</a> are data structures for the content we want to manage.</p><p>Create the Strapi collection types <strong>Blog</strong> and <strong>Tag</strong>. Later on, we will create a collection type called <strong>Post</strong> for our Strapi plugin.</p><p><strong>Blog</strong> refers to entries we want to publish. <strong>Post</strong> on the other hand are entries containing details of a blog we want to publish such as the blog link, Medium link, etc. A <strong>Post</strong> entry will be created automatically using Strapi Life Cycle upon creating a <strong>Blog</strong> entry.</p><p>If you are new to Strapi, learn about content-types <a href="https://docs.strapi.io/user-docs/content-type-builder/creating-new-content-type">here</a>.</p><p>To create a new Strapi collection type, navigate to the <strong>Content-type Builder</strong> and click on the <strong>“+ Create new collection type”</strong> as shown in the first image below. After that, proceed to enter the name of the Collection type and click “Continue” to <a href="https://docs.strapi.io/user-docs/content-type-builder/configuring-fields-content-type">create fields</a> for each collection type as shown in the second image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*gdwY5IjdZKWzkUMk.png" /></figure><p><em>Locate the Content-type Builder</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*kcDTaoB4D8XpgLdD.png" /></figure><p><em>Enter Collection Name and Click “Continue”</em></p><p>Now, create the following collection types.</p><p><strong>Tag Collection Type</strong><br>This represents the category a blog post belongs to. It is required for both the Medium and Dev API. As we will see in the <strong>Blog</strong> collection type below, it has a <strong>“many to one”</strong> relation with the <strong>Blog</strong> collection, i.e., a blog entry can have more than one tag.</p><p>FieldTypeDescriptionblogTag<strong>Text</strong>Tag used for blog categorization</p><p><strong>Blog Collection Type</strong><br>The <strong>Blog</strong> collection type represents the blog post. It has fields like canonicalUrl and tags, which are required parameters when making requests to the Medium API or the Dev API.</p><p>FieldTypeDescriptiontitleTextThe title of the contentcontentRich text (Markdown)The main body contentcanonicalUrlTextThe canonical URL for SEO.tagsRelation with <strong>Tag</strong> collection type. =&gt; &quot;<strong>Blog</strong> has many <strong>Tags</strong>&quot;Associated tags for categorization.bannerTextURL or path for the banner image</p><blockquote><em>🖐️ NOTE: Ensure you disable “Draft and publish” for the </em><strong><em>Blog</em></strong><em> collection type.</em></blockquote><p>Make sure to disable the “Draft and Publish” feature for the <strong>Blog</strong> collection type by unchecking the option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*RwE1kBpRoQGOI04W.png" /></figure><p><em>Disable Draft and Publish</em></p><p>At this point, your Strapi app is ready to be powered up with a plugin! Next, we will learn how to generate a Strapi plugin.</p><h3>Step 5: Enable API Permission for Tag Collection Type</h3><p>Because we want to be able to use the tags of blog entries when publishing to Medium and Dev, we want to make sure that the tags of a blog are returned when we make a request to get a blog entry.</p><p>Ensure API permission is enabled for the Tag collection type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*71dqnEA0tY9KDrNj.png" /></figure><p><em>Enable API Permission for **Tag</em>* Collection*</p><h3>Initialize a Strapi Plugin Using The Plugin SDK</h3><p>The <a href="https://docs.strapi.io/dev-docs/plugins/development/plugin-sdk">Strapi plugin SDK</a> is used to develop and publish Strapi plugins for NPM.</p><p>Initialize a new Strapi plugin using the command below. Ensure you are in your Strapi project directory content-publisher. The name of our plugin is content-publisher.</p><pre>npx @strapi/sdk-plugin init content-publisher</pre><blockquote><em>🖐️ </em><strong><em>NOTE:</em></strong><em> You can use the </em><em>--force option after </em><em>npx if you experience peer dependency error.</em></blockquote><p>Make sure to answer the prompts that follow as shown below:</p><pre>✔ plugin name … content-publisher<br>✔ plugin display name … content-publisher<br>✔ plugin description … This is a plugin that allows you to publish contents from Strapi to Dev.to, Medium.com and many more in the future<br>✔ plugin author name … Theodore Kelechukwu Onyejiaku<br>✔ plugin author email … theodoreonyejiaku@gmail.com<br>✔ git url … <br>✔ plugin license … MIT<br>✔ register with the admin panel? … yes<br>✔ register with the server? … yes<br>✔ use editorconfig? … yes<br>✔ use eslint? … yes<br>✔ use prettier? … yes<br>✔ use typescript? … yes</pre><blockquote><em>🖐️ </em><strong><em>NOTE:</em></strong><em> Make sure to answer “yes” to register with admin panel and server. This is because we want to have our plugin server and frontend.</em></blockquote><p>If the plugin initialization is successful, you should see the success message “Plugin generated successfully” and instructions on how to enable the plugin, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*AVz-V9EHsVBQU9ia.png" /></figure><p><em>Enable Plugin</em></p><p>Head over to the plugin configuration file ./config/plugin.ts and add the code below:</p><pre>// Path: ./config/plugin.ts<br><br>export default {<br>  // ...<br>  &#39;content-publisher&#39;: {<br>    enabled: true,<br>    resolve: &#39;./src/plugins/content-publisher&#39;<br>  },<br>  // ...<br>}</pre><h3>Start The Strapi Plugin</h3><p>To start building our plugin, we need to make sure that any changes and rebuilds are updated by using the watch command.</p><p>First, CD into the plugin directory of your Strapi project, ./src/plugins/content-publisher. After that, run the command below:</p><pre>npm run watch</pre><p>You should now see your Strapi plugin in two ways</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*NM0yZkaZ4ytQhC5u.png" /></figure><p><em>Click on *Settings &gt; Plugins</em>** and find the content-publisher plugin*</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*s9FXNS9VQlOyKQJt.png" /></figure><p><em>Locate and click the new custom plugin icon.</em></p><h3>Strapi Plugin Structure</h3><p>The Strapi <a href="https://docs.strapi.io/dev-docs/plugins/development/plugin-structure">plugin structure</a> is divided into 2 parts.</p><ul><li><strong>Admin panel</strong>: This contains codes/files that will be visible on the Strapi admin panel. Examples include components, etc. This is found in the /admin directory of the plugin.</li><li><strong>Backend server</strong>: This contains codes/files that are related to the server of the plugin. Examples include middlewares, controllers, routes, etc. This is found in /server directory of the plugin.</li></ul><pre>src/<br>┣ ...<br>┣ plugins/<br>┃ ┗ content-publisher/<br>┃  ┣ admin/<br>┃  ┃ ┣ src/<br>┃  ┃ ┣ custom.d.ts<br>┃  ┃ ┣ tsconfig.build.json<br>┃  ┃ ┗ tsconfig.json<br>┃  ┣ server/<br>┃  ┃ ┣ src/<br>┃  ┃ ┣ tsconfig.build.json<br>┃  ┃ ┗ tsconfig.json<br>┃  ┗ ...<br>┗ index.ts</pre><p>For a comprehensive understanding of the Strapi plugin structure, please visit this Strapi documentation page: <a href="https://docs.strapi.io/dev-docs/plugins/development/plugin-structure">Plugin structure</a>.</p><h3>Update Strapi Plugin Icon and Page Content</h3><p>Let’s get busy!</p><p>We will modify the icon and page content of our plugin so that it can be seen live!</p><h3>Update Plugin Icon</h3><p>Locate the current plugin icon inside the components folder. This is available Inside the ./src/plugins/content-publisher/admin/src/components/PluginIcon.tsx file. Currently, it uses the puzzle-piece icon.</p><p>Update this file with the code below:</p><pre>// Path: src/plugins/content-publisher/admin/src/components/PluginIcon.tsx<br><br>import { Sparkle } from &#39;@strapi/icons&#39;;<br>const PluginIcon = () =&gt; &lt;Sparkle /&gt;;<br>export { PluginIcon };<br></pre><p>Now, the plugin icon has been updated to a sparkle icon, as shown in the image below. The current plugin icon can be updated to any icon you prefer. You could use an icon from the Strapi design system or an SVG of your choice that aligns with the Strapi design system.</p><h3>Update Plugin Page Content</h3><p>At the moment, the content of the plugin displays “Welcome to content-publisher.plugin.name”. Let’s update it.</p><p>Update the code inside the ./src/plugins/content-publisher/admin/src/pages/HomePage.tsx file with the following code:</p><pre>// Path: src/plugins/content-publisher/admin/src/pages/HomePage.tsx<br><br>import { Main, Box, Typography } from &#39;@strapi/design-system&#39;;<br>const HomePage = () =&gt; {<br>  return (<br>    &lt;Main padding={5}&gt;<br>      &lt;Box paddingBottom={4} margin={20}&gt;<br>        &lt;Typography variant=&quot;alpha&quot;&gt;Welcome To Content Publisher&lt;/Typography&gt;<br>        &lt;Box&gt;<br>          &lt;Typography variant=&quot;epsilon&quot;&gt;Publish blog posts to medium, dev.to, etc.&lt;/Typography&gt;<br>        &lt;/Box&gt;<br>      &lt;/Box&gt;<br>    &lt;/Main&gt;<br>  );<br>};<br>export { HomePage };<br></pre><p>In the code above, we used some some components from the Strapi design system to update the content and structure of the content of our plugin home page.</p><p>The image below shows what our new plugin home page and icon look like after the update.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*Z5nSeA5nqwCidIRf.png" /></figure><p><em>Home page of Content Publisher custom plugin</em></p><h3>Create Content Type for Strapi Plugin</h3><p>Since we want our custom plugin to be able to publish posts to Medium and Dev, we need to keep track of posts that have been published to these platforms or are ready for publishing.</p><h3>Generate Post Collection Type for Strapi Plugin</h3><p>We need to create a new collection type for our plugin. It will be called <strong>Post</strong>. It will have the following fields:</p><ul><li>mediumLink: This will be used to store the link to the published post on Medium. It will be of type <strong>Text</strong>.</li><li>devToLink: This will be used to store the link to the published post on Dev. It will be of type <strong>Text</strong>.</li><li>blog: This will point to blog content from the <strong>Blog</strong> collection type in our Strapi backend. It will be a <strong>one-to-one</strong> relationship with the <strong>Blog</strong> collection type.</li></ul><p>To generate the collection type for our plugin, we can do it in two ways. You can learn more by checking out <a href="https://docs.strapi.io/dev-docs/plugins/guides/store-and-access-data">how to store and access data from a Strapi plugin</a>.</p><ol><li>Use the generate command as shown below:</li></ol><pre># npm<br>npm run strapi generate content-type</pre><ol><li>Or create a file called post.ts inside server/src/content-types directory, and add the following code</li></ol><pre>// content-types/post.ts<br><br>const schema = {<br>  kind: &#39;collectionType&#39;,<br>  collectionName: &#39;posts&#39;,<br>  info: {<br>    singularName: &#39;post&#39;,<br>    pluralName: &#39;posts&#39;,<br>    displayName: &#39;Post&#39;,<br>  },<br>  options: {<br>    draftAndPublish: false,<br>  },<br>  pluginOptions: {<br>    &#39;content-manager&#39;: {<br>      visible: true,<br>    },<br>    &#39;content-type-builder&#39;: {<br>      visible: true,<br>    },<br>  },<br>  attributes: {<br>    mediumLink: {<br>      type: &#39;text&#39;,<br>    }<br>  },<br>};<br>export default {<br>  schema,<br>};</pre><p>Below is an explanation of the code above:</p><ul><li>We define a Strapi content type schema for <strong>Post</strong> and specify it as a collection type. We also set up basic metadata, disabled draft and publish functionality, and ensured the content type was visible in both the Content Manager and Content-Type Builder plugins of the Strapi admin panel.</li><li>We add attribute “mediumLink” as a text field. We will add the remaining fields devToLink and blog soon using the Content-type Builder on the Strapi admin panel.</li><li>Next, import this new content type so you can see it on the Strapi admin panel. Locate the ./src/plugins/content-publisher/server/src/content-types/index.ts and update it with the following code:</li></ul><pre>import post from &#39;./post&#39;;<br><br>export default {<br>  post,<br>};</pre><p>Now, we should be able to see the <strong>Post</strong> collection with the mediumLink field for our plugin:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*qSvat-YBYW-GIbo8.png" /></figure><p><em>Post collection with </em><em>mediumLink</em></p><p>Add the devToLink and blog fields by clicking the <strong>&quot;Add another field to the collection type&quot;</strong>. Remember to make sure that the blog field of the <strong>Post</strong> collection type is related to <strong>Blog collection</strong> in a one-to-one relation as &quot;Post has and belongs to one Blog.&quot; See image below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*4RGmBTROCLOLOunV.png" /></figure><p><em>Relation between </em><strong>Post</strong> and <strong>Blog</strong> collection types</p><h3>Strapi Plugin Server Customization: Routes and Controllers</h3><p>The Post collection type for our plugin is ready; we have to customize the backend of our plugin by creating routes, controllers, and services.</p><ul><li><strong>Routes:</strong> These handle requests sent to Strapi. You can find the routes for our plugin here: ./src/plugins/content-publisher/server/src/routes/index.ts</li><li><strong>Controllers:</strong> These are actions or methods performed when a request is made to a route. You can find the controllers for our plugin here: ./src/plugins/content-publisher/server/src/controllers/controller.ts</li><li><strong>Services:</strong> Reusable functions are often called by controllers. You can find the services for our plugin here: ./src/plugins/content-publisher/server/src/services/service.ts.</li></ul><p>Here is an example:</p><pre>// route GET route to fetch blogs<br>export default [<br>  {<br>    method: &#39;GET&#39;,<br>    path: &#39;/blogs&#39;,<br>    // name of the controller file &amp; the method.<br>    handler: &#39;controller.getBlogs&#39;,<br>    config: {<br>      policies: [],<br>    },<br>  },<br>];<br><br>// controller with a controller method or action<br>const controller = ({ strapi }: { strapi: Core.Strapi }) =&gt; ({<br>  async getBlogs(ctx) {<br>    ctx.body = await strapi.plugin(&#39;medium-publisher&#39;).service(&#39;service&#39;).getBlogPosts(); // invokes `getBlogposts()` service<br>  },<br>});<br>// A reusable service called by controller above<br>const service = ({ strapi }: { strapi: Core.Strapi }) =&gt; ({<br>  // GET Blog Posts<br>  async getBlogPosts() {<br>    try {<br>      const blogPost = await strapi.documents(&#39;api::blog.blog&#39;).findMany();<br>      return blogPost;<br>    } catch (error) {<br>      throw error;<br>    }<br>  },<br>});</pre><p>The above is a route that handles requests to /blogs. It is handled by a controller method called getBlogs. This method on the other hand invokes the getBlogPosts service.</p><p>In order to proceed, we need to customize our Strapi plugin server. Hence, we will customize the routes and controllers.</p><h3>Create Strapi Plugin Routes</h3><p>Strapi plugins can have two kinds of routes.</p><ol><li><strong>External or Content-Type Route:</strong> This will be accessible to requests within or outside the admin panel. This is declared by adding type:&#39;content-api&#39; to the route. An example is /api/blogs.</li><li><strong>Admin Route:</strong> These are hidden from the general API router and can only be accessed in the admin panel. This is done by adding type:&#39;admin&#39; to the route. An example is plugin-name/posts.</li></ol><p>Inside the ./src/plugins/content-publisher/server/src/routes, create two files, admin.ts and contentApi.ts respectively and add the codes below for each.</p><p><strong>Create Private Routes for Plugin</strong><br>Inside the ./src/plugins/content-publisher/server/src/routes/admin.ts file, add the following code. The following are routes accessible only to the admin panel and not the general or external API.</p><pre>// Path: ./src/plugins/content-publisher/server/src/routes/admin.ts<br>import policies from &#39;src/policies&#39;;<br>export default [<br>  {<br>    method: &#39;GET&#39;,<br>    path: &#39;/posts&#39;,<br>    handler: &#39;controller.getPosts&#39;,<br>    config: {<br>      policies: [],<br>      auth: false,<br>    },<br>  },<br>  {<br>    method: &#39;GET&#39;,<br>    path: &#39;/single-post&#39;,<br>    handler: &#39;controller.getSinglePost&#39;,<br>    config: {<br>      policies: [],<br>      auth: false,<br>    },<br>  },<br>  {<br>    method: &#39;POST&#39;,<br>    path: &#39;/publish-to-medium&#39;,<br>    handler: &#39;controller.publishPostToMedium&#39;,<br>    config: {<br>      policies: [],<br>      auth: false,<br>    },<br>  },<br>  {<br>    method: &#39;POST&#39;,<br>    path: &#39;/publish-to-devto&#39;,<br>    handler: &#39;controller.publishPostToDevTo&#39;,<br>    config: {<br>      policies: [],<br>      auth: false,<br>    },<br>  },<br>  {<br>    method: &#39;GET&#39;,<br>    path: &#39;/search&#39;,<br>    handler: &#39;controller.getSearchQuery&#39;,<br>    config: {<br>      policies: [],<br>      auth: false,<br>    },<br>  },<br>  {<br>    method: &#39;DELETE&#39;,<br>    path: &#39;/delete-post&#39;,<br>    handler: &#39;controller.deletePost&#39;,<br>    config: {<br>      policies: [],<br>      auth: false,<br>    },<br>  },<br>];</pre><p>In the code above, we created an array of admin routes that our plugin will use. Note that we added auth=false. This means the routes will be publicly accessible without requiring any authentication.</p><blockquote><em>🖐️ </em><strong><em>NOTE:</em></strong><em> We added </em><em>auth=false to each route above because we want the routes to be accessible without requiring any authentication.</em></blockquote><p>Here is what each route above does:</p><p>The routes above will be available to our plugin admin panel on the endpoint /content-publisher which is the name of our plugin. For example /content-publisher/posts.</p><p>We will create the corresponding controllers for each of these routes shortly.</p><p><strong>Create Public Route</strong><br>In order to demonstrate that we can make some routes private to the admin panel and others accessible externally, we will create a publicly availabe route.</p><p>Inside the ./src/plugins/content-publisher/server/src/routes/contentApi.ts file, add the following:</p><pre>export default [<br>  {<br>    method: &#39;GET&#39;,<br>    path: &#39;/blogs&#39;,<br>    // name of the controller file &amp; the method.<br>    handler: &#39;controller.getBlogs&#39;,<br>    config: {<br>      policies: [],<br>    },<br>  },<br>];</pre><p>This will be publicly accessible on api/blogs as we will see when testing our routes.</p><p><strong>Import Private and Public Routes</strong><br>Head over to ./src/plugins/content-publisher/server/src/routes/index.ts and import the routes we created above.</p><pre>&#39;use strict&#39;;<br><br>import admin from &#39;./admin&#39;;<br>import contentApi from &#39;./contentApi&#39;;<br>export default {<br>  &#39;content-api&#39;: {<br>    type: &#39;content-api&#39;,<br>    routes: [...contentApi],<br>  },<br>  admin: {<br>    type: &#39;admin&#39;,<br>    routes: [...admin],<br>  },<br>};</pre><p>As seen in the code above, we have routes that should be accessible only on the admin panel. We specified this with the type: &#39;admin&#39;. For the route that is available to the general API router, we specified type: &#39;content-api&#39;.</p><h3>Create Strapi Plugin Controllers</h3><p>At this point, our app should break because the controllers we mentioned in the routes above haven’t been created. Let’s create them.</p><p>Update the controller file in ./src/plugins/content-publisher/server/src/controllers/controller.ts with the following code:</p><pre>// Path: ./src/plugins/content-publisher/server/src/controllers/controller.ts<br><br>import type { Core } from &#39;@strapi/strapi&#39;;<br>const controller = ({ strapi }: { strapi: Core.Strapi }) =&gt; ({<br>  // get blog entries<br>  async getBlogs(ctx) {},<br>  // get posts <br>  async getPosts(ctx) {},<br>  // publish a blog post to medium<br>  async publishPostToMedium(ctx) {},<br>  // publish a blog post to dev.to<br>  async publishPostToDevTo(ctx) {},<br>  // search for a post<br>  async getSearchQuery(ctx) {},<br>  // delete a post<br>  async deletePost(ctx) {},<br>  // get a single post<br>  async getSinglePost(ctx) {},<br>});<br>export default controller;</pre><p>In the code above, we added the controller methods, which we will update and use later on in this tutorial.</p><p>Here is what each of the controller methods do:</p><ul><li>getBlogs: This will help us fetch blogs that have been created.</li><li>getPosts: This will help us fetch posts for publishing.</li><li>publishPostToMedium: We will use this to publish a post to Medium.</li><li>publishPostToDevTo: With this, we can publish a post to Dev.</li><li>getSearchQuery: When we send a query request to fetch a post, this method will return the search result.</li><li>getSinglePost: This will allow us to get a single post.</li></ul><h3>Create Environment Variables</h3><p>Inside the root of your project folder, locate the .env file and add the following environment variables to the existing ones:</p><pre>MEDIUM_API_TOKEN=&quot;your medium api key&quot;<br>MEDIUM_USER_ID=&quot;your medium user id&quot;<br>DEVTO_API_KEY=&quot;your dev.to api key&quot;</pre><p>In the code above, we created environment variables for the Medium and Dev APIs. The Medium API requires a user ID and an API token. Meanwhile, the Dev API requires an API key.</p><p>Let’s obtain these credentials.</p><h3>Obtain Medium and Dev API Keys</h3><p>Before we continue with the next sections, we need to have some credentials in order to consume the Medium and Dev APIs.</p><h3>How to Obtain Dev API Key</h3><p>To obtain your Dev API key, follow the following instructions below:</p><ul><li>Log in to your <a href="https://dev.to/t/login">Dev account</a></li><li>Click on your profile picture and click <strong>settings</strong></li><li>Click the <strong>Extensions</strong> tab</li><li>Scroll down to <strong>“DEV Community API Keys”</strong></li><li>Generate a new API key</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*LEpHPrtUiSsnrvW2.png" /></figure><p><em>Generate Dev API Key</em></p><p>Generate a new key and add the value to the environment variable DEVTO_API_KEY.</p><h3>How to Obtain Obtain Medium API Key</h3><p>Obtain your Medium API key by following the instructions below:</p><ul><li>Log in to your <a href="https://medium.com/m/signin">Medium account</a></li><li>Click on your profile picture and click <strong>settings</strong></li><li>Click on the <strong>“Security and apps”</strong> tab</li><li>Scroll down to the bottom and click on “Integration tokens”.</li><li>This will open a modal for you to copy your API key.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*XnA1q0jCIGppL6Y3.png" /></figure><ul><li><em>Copy Medium API Key</em></li><li>Get the token above and add it as a value to the environment variable MEDIUM_API_TOKEN.</li><li>With the API token above, we can now get the value for MEDIUM_USER_ID. Hence, to obtain your user ID, make a GET request to https://api.medium.com/v1/me. Ensure you add an authorization header to the request, which should be your API token.</li></ul><p>Here is an example below</p><pre>GET /v1/me HTTP/1.1<br>Host: api.medium.com<br>Authorization: Bearer 181d415f34379af07b2c11d144dfbe35d<br>Content-Type: application/json<br>Accept: application/json<br>Accept-Charset: utf-8</pre><p>Using <a href="https://www.postman.com/">Postman</a> HTTP client:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*64je59XQ3AqdCr5Z.png" /><figcaption><em>Add API Key to request</em></figcaption></figure><p>Here is a successful response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*MHs8VwMh7zg7JVnn.png" /><figcaption><em>Successful Response</em></figcaption></figure><p>In the response above, the user ID, represented by id, is returned along with other user details. Get the user ID and add it as a value to the MEDIUM_USER_ID environment variable.</p><h3>How to Create a New Entry Automatically Using Strapi Lifecycle Function</h3><p>When we create a blog entry, we want to automatically create a corresponding post entry. As we said before, a post entry will contain details about the publishing of the blog entry, like the live Medium and Dev links, and relation to the blog entry from which it was created.</p><p>Navigate to the register lifecycle function file ./src/plugins/content-publisher/server/src/register.ts and replace the code inside with the following:</p><pre>// Path: ./src/plugins/content-publisher/server/src/register.ts<br>import type { Core } from &#39;@strapi/strapi&#39;;<br><br>const register = ({ strapi }: { strapi: Core.Strapi }) =&gt; {<br>  strapi.db.lifecycles.subscribe({<br>    // only for the blog collection type<br>    models: [&#39;api::blog.blog&#39;],<br>    // after a blog post is created<br>    async afterCreate(event) {<br>      // create new data<br>      const newData = {<br>        blog: event.result.documentId,<br>        mediumLink: null,<br>        devToLink: null,<br>      };<br>      // create new post<br>      await strapi.documents(&#39;plugin::medium-publisher.post&#39;).create({<br>        data: newData,<br>      });<br>    },<br>  });<br>};<br>export default register;</pre><p>The code above is a Strapi 5 lifecycle function that listens for events related to the <strong>Blog</strong> API collection type models: [&#39;api::blog.blog&#39;]. Specifically, it subscribes to the afterCreate event, which triggers after a new blog entry is created.</p><p>When triggered, it creates a new entry in the content-publisher.post, which is the <strong>Post</strong> collection type of our plugin, with references to the blog post and placeholder values for mediumLink and devToLink</p><p><strong>Create a new Blog Entry</strong><br>Let’s see if our lifecycle event works. Start by creating a new blog entry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*8hKP-szzoSsGEH8m.png" /></figure><p><em>Create a Blog Entry</em></p><p>After creating the blog entry, navigate to the <em>Post</em> collection, and you will find a new entry automatically created upon creating the blog entry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*NZZ7u4sr2FSznTze.png" /></figure><p><em>A Post Entry is Automatically created</em></p><p>As you can see, new post entries are created automatically.</p><p>Now, create more blog entries so that we can fetch and display posts for publishing.</p><h3>Fetch and Display Posts in Strapi Plugin</h3><p>Posts have now been created. Let’s display them on the admin panel of our plugin.</p><h3>Step 1: Update Controller Method to Fetch Posts</h3><p>Do you recall the getPosts() controller method we created some time ago inside the controller file ./src/plugins/content-publisher/server/src/controllers/controller.ts, let&#39;s modify it with the following:</p><pre>... <br>// get posts<br>async getPosts(ctx) {<br>  ctx.body = await strapi<br>    .plugin(&quot;content-publisher&quot;)<br>    .service(&quot;service&quot;)<br>    .getPosts();<br>}</pre><p>The controller method above retrieves posts by calling the getPosts() service, which we will create shortly, of our plugin &quot;content-publisher&quot;, and sets the response body ctx.body to the result.</p><h3>Step 2: Create a Service to Fetch Posts</h3><p>Inside the ./src/plugins/content-publisher/admin/src/components directory, create a file called PublishingTable.tsx, and add the following code inside with the following:</p><pre>// Path: ./src/plugins/content-publisher/admin/src/components/PublishingTable.tsx<br><br>import {<br>  Table,<br>  Thead,<br>  Tbody,<br>  Tr,<br>  Td,<br>  Th,<br>  Typography,<br>  Box,<br>  Link,<br>  Flex,<br>} from &#39;@strapi/design-system&#39;;<br>import { Trash } from &#39;@strapi/icons&#39;;<br>import axios from &#39;axios&#39;;<br>import { useState, useEffect, FormEvent } from &#39;react&#39;;<br>import formattedDate from &#39;../utils/formattedDate&#39;;<br>import PublishButton from &#39;./PublishButton&#39;;<br>import MediumIcon from &#39;./MediumIcon&#39;;<br>import DevToIcon from &#39;./DevToIcon&#39;;<br>const PublishingTable = () =&gt; {<br>  const [posts, setPosts] = useState([]);<br>  return (<br>    &lt;Box&gt;<br>      &lt;Box padding={8} margin={20}&gt;<br>        &lt;Table colCount={7} rowCount={posts.length + 1}&gt;<br>          &lt;Thead&gt;<br>            &lt;Tr&gt;<br>              &lt;Th&gt;<br>                &lt;Typography variant=&quot;sigma&quot; textColor=&quot;neutral600&quot;&gt;<br>                  Blog ID<br>                &lt;/Typography&gt;<br>              &lt;/Th&gt;<br>              &lt;Th&gt;<br>                &lt;Typography variant=&quot;sigma&quot; textColor=&quot;neutral600&quot;&gt;<br>                  Date Created<br>                &lt;/Typography&gt;<br>              &lt;/Th&gt;<br>              &lt;Th&gt;<br>                &lt;Typography variant=&quot;sigma&quot; textColor=&quot;neutral600&quot;&gt;<br>                  Blog Title<br>                &lt;/Typography&gt;<br>              &lt;/Th&gt;<br>              &lt;Th&gt;<br>                &lt;Typography variant=&quot;sigma&quot; textColor=&quot;neutral600&quot;&gt;<br>                  Blog Link<br>                &lt;/Typography&gt;<br>              &lt;/Th&gt;<br>              &lt;Th&gt;<br>                &lt;Flex gap={2} direction=&quot;row&quot; alignItems=&quot;center&quot;&gt;<br>                  {/* Medium icon */}<br>                  &lt;MediumIcon /&gt;<br>                  &lt;Typography variant=&quot;sigma&quot;&gt;Medium&lt;/Typography&gt;<br>                &lt;/Flex&gt;<br>              &lt;/Th&gt;<br>              &lt;Th&gt;<br>                &lt;Flex gap={2} direction=&quot;row&quot; alignItems=&quot;center&quot;&gt;<br>                  {/* Dev.to icon */}<br>                  &lt;DevToIcon /&gt;<br>                  &lt;Typography variant=&quot;sigma&quot;&gt;Dev.to&lt;/Typography&gt;<br>                &lt;/Flex&gt;<br>              &lt;/Th&gt;<br>              &lt;Th&gt;&lt;/Th&gt;<br>            &lt;/Tr&gt;<br>          &lt;/Thead&gt;<br>          &lt;Tbody&gt;<br>            {posts.map((post: any) =&gt; (<br>              &lt;Tr key={post.id}&gt;<br>                &lt;Td&gt;<br>                  &lt;Typography textColor=&quot;neutral800&quot;&gt;{post.id}&lt;/Typography&gt;<br>                &lt;/Td&gt;<br>                &lt;Td&gt;<br>                  &lt;Typography textColor=&quot;neutral800&quot;&gt;<br>                    {formattedDate(post.blog?.updatedAt)}<br>                  &lt;/Typography&gt;<br>                &lt;/Td&gt;<br>                &lt;Td&gt;<br>                  &lt;Typography textColor=&quot;neutral800&quot;&gt;{post.blog.title.slice(0, 30)}...&lt;/Typography&gt;<br>                &lt;/Td&gt;<br>                &lt;Td&gt;<br>                  &lt;Typography textColor=&quot;neutral800&quot;&gt;<br>                    &lt;Link<br>                      href={`http://localhost:1337/admin/content-manager/collection-types/api::blog.blog/${post.blog.documentId}`}<br>                    &gt;<br>                      {post.blog.title.slice(0, 30)}...<br>                    &lt;/Link&gt;<br>                  &lt;/Typography&gt;<br>                &lt;/Td&gt;<br>                &lt;Td&gt;<br>                  &lt;PublishButton post={post} type=&quot;medium&quot; /&gt;<br>                &lt;/Td&gt;<br>                &lt;Td&gt;<br>                  &lt;PublishButton post={post} type=&quot;devto&quot; /&gt;<br>                &lt;/Td&gt;<br>                &lt;Td&gt;<br>                  &lt;Trash style={{ cursor: &#39;pointer&#39;, color: &#39;red&#39; }} width={20} height={20} /&gt;<br>                &lt;/Td&gt;<br>              &lt;/Tr&gt;<br>            ))}<br>          &lt;/Tbody&gt;<br>        &lt;/Table&gt;<br>      &lt;/Box&gt;<br>    &lt;/Box&gt;<br>  );<br>};<br>export default PublishingTable;</pre><p>The PublishingTable React component above renders a table to manage and display posts. It uses the @strapi/design-system library for UI components and displays blog data such as ID, creation date, title, and links, along with publishing options for Medium and Dev.to via PublishButton component which we will create soon. It also contains components MediumIcon and DevToIcon which we will create soon.</p><p>The table dynamically maps over a posts state array (managed by useState) to populate rows, and includes a utility function formattedDate() (we will create this shortly) that format dates and a delete button represented by a trash icon.</p><p>So, let’s create the PublishButton component and the formattedDate() utility function.</p><h3>Step 4: Create a Date Formatter Utility Function</h3><p>By default, Strapi returns dates in ISO 8601 format, e.g. 2025–01–06T22:09:08.655Z. However, we want to display the dates in a much friendlier way, like January 6, 2025.</p><p>Inside the ./src/plugins/content-publisher/admin/src/utils directory, create a file called formattedDate.ts and add the following code:</p><pre>// Path: ./src/plugins/content-publisher/admin/src/utils/formattedDate.ts<br><br>const formattedDate = (isoDate: Date) =&gt; {<br>  // Create a Date object from the ISO string<br>  const date = new Date(isoDate);<br>  const result = date.toLocaleDateString(&#39;en-US&#39;, {<br>    year: &#39;numeric&#39;,<br>    month: &#39;long&#39;,<br>    day: &#39;numeric&#39;,<br>  });<br>  return result;<br>};<br>export default formattedDate;</pre><p>The formattedDate() function converts an ISO date string such as &quot;2025-01-06T22:09:08.655Z&quot; into a human-readable format (e.g., &quot;January 1, 2025&quot;) using the toLocaleDateString method with U.S. English formatting.</p><h3>Step 3: Create Other Components</h3><p>In the PublishingTable component we created above, we imported PublishButton, MediumIcon and DevToIcon. Let&#39;s create them.</p><p><strong>Create Publish Button Component</strong><br>Inside the ./src/plugins/content-publisher/admin/src/components directory, create a new file called PublishButton.tsx and add the following code. This component will be responsible for publishing posts to different platforms.</p><pre>// Path: ./src/plugins/content-publisher/admin/src/components/PublishButton.tsx<br><br>import { Box, Button, Typography, LinkButton, Flex, Link } from &#39;@strapi/design-system&#39;;<br>import { Play, Check, Cursor } from &#39;@strapi/icons&#39;;<br>const PublishButton = ({ post, type }: { post: any; type: string }) =&gt; {<br>  return (<br>    &lt;Box&gt;<br>      &lt;Button style={bigBtn} size=&quot;S&quot; startIcon={&lt;Play /&gt;} variant=&quot;default&quot;&gt;<br>        &lt;Typography variant=&quot;pi&quot;&gt;start&lt;/Typography&gt;<br>      &lt;/Button&gt;<br>    &lt;/Box&gt;<br>  );<br>};<br>const bigBtn = {<br>  width: &#39;100px&#39;,<br>};<br>export default PublishButton;</pre><p>It takes two parameters, the <strong>Post entry</strong> and the type “medium” or “devto”.</p><p><strong>Create Medium Icon Component</strong><br>Inside the ./src/plugins/content-publisher/admin/src/components directory, create a new file called MediumIcon.tsx and add the following code:</p><pre>// Path: ./src/plugins/content-publisher/admin/src/components/MediumIcon.tsx<br><br>import React from &quot;react&quot;;<br>export default function MediumIcon() {<br>  return (<br>    &lt;svg<br>      width=&quot;24px&quot;<br>      height=&quot;24px&quot;<br>      viewBox=&quot;0 0 24 24&quot;<br>      fill=&quot;none&quot;<br>      xmlns=&quot;http://www.w3.org/2000/svg&quot;<br>    &gt;<br>      &lt;g id=&quot;SVGRepo_bgCarrier&quot; stroke-width=&quot;0&quot;&gt;&lt;/g&gt;<br>      &lt;g<br>        id=&quot;SVGRepo_tracerCarrier&quot;<br>        stroke-linecap=&quot;round&quot;<br>        stroke-linejoin=&quot;round&quot;<br>      &gt;&lt;/g&gt;<br>      &lt;g id=&quot;SVGRepo_iconCarrier&quot;&gt;<br>        {&quot; &quot;}<br>        &lt;path<br>          d=&quot;M13 12C13 15.3137 10.3137 18 7 18C3.68629 18 1 15.3137 1 12C1 8.68629 3.68629 6 7 6C10.3137 6 13 8.68629 13 12Z&quot;<br>          fill=&quot;#0F0F0F&quot;<br>        &gt;&lt;/path&gt;{&quot; &quot;}<br>        &lt;path<br>          d=&quot;M23 12C23 14.7614 22.5523 17 22 17C21.4477 17 21 14.7614 21 12C21 9.23858 21.4477 7 22 7C22.5523 7 23 9.23858 23 12Z&quot;<br>          fill=&quot;#0F0F0F&quot;<br>        &gt;&lt;/path&gt;{&quot; &quot;}<br>        &lt;path<br>          d=&quot;M17 18C18.6569 18 20 15.3137 20 12C20 8.68629 18.6569 6 17 6C15.3431 6 14 8.68629 14 12C14 15.3137 15.3431 18 17 18Z&quot;<br>          fill=&quot;#0F0F0F&quot;<br>        &gt;&lt;/path&gt;{&quot; &quot;}<br>      &lt;/g&gt;<br>    &lt;/svg&gt;<br>  );<br>}</pre><p><strong>Create Dev Icon Component</strong><br>Inside the ./src/plugins/content-publisher/admin/src/components directory, create a new file called MediumIcon.tsx and add the following code:</p><pre>// Path: ./src/plugins/content-publisher/admin/src/components/MediumIcon.tsx<br><br>import React from &quot;react&quot;;<br>export default function DevToIcon() {<br>  return (<br>    &lt;svg<br>      xmlns=&quot;http://www.w3.org/2000/svg&quot;<br>      aria-label=&quot;dev.to&quot;<br>      role=&quot;img&quot;<br>      viewBox=&quot;0 0 512 512&quot;<br>      width=&quot;24px&quot;<br>      height=&quot;24px&quot;<br>      fill=&quot;#000000&quot;<br>    &gt;<br>      &lt;g id=&quot;SVGRepo_bgCarrier&quot; stroke-width=&quot;0&quot;&gt;&lt;/g&gt;<br>      &lt;g<br>        id=&quot;SVGRepo_tracerCarrier&quot;<br>        stroke-linecap=&quot;round&quot;<br>        stroke-linejoin=&quot;round&quot;<br>      &gt;&lt;/g&gt;<br>      &lt;g id=&quot;SVGRepo_iconCarrier&quot;&gt;<br>        &lt;rect width=&quot;512&quot; height=&quot;512&quot; rx=&quot;15%&quot;&gt;&lt;/rect&gt;<br>        &lt;path<br>          fill=&quot;#ffffff&quot;<br>          d=&quot;M140.47 203.94h-17.44v104.47h17.45c10.155-.545 17.358-8.669 17.47-17.41v-69.65c-.696-10.364-7.796-17.272-17.48-17.41zm45.73 87.25c0 18.81-11.61 47.31-48.36 47.25h-46.4V172.98h47.38c35.44 0 47.36 28.46 47.37 47.28zm100.68-88.66H233.6v38.42h32.57v29.57H233.6v38.41h53.29v29.57h-62.18c-11.16.29-20.44-8.53-20.72-19.69V193.7c-.27-11.15 8.56-20.41 19.71-20.69h63.19zm103.64 115.29c-13.2 30.75-36.85 24.63-47.44 0l-38.53-144.8h32.57l29.71 113.72 29.57-113.72h32.58z&quot;<br>        &gt;&lt;/path&gt;<br>      &lt;/g&gt;<br>    &lt;/svg&gt;<br>  );<br>}</pre><h3>Step 2: Create a Function to Fetch Posts</h3><p>Implement a function to fetch posts. Add the following code to the PublishingTable component.</p><pre>// ... other codes<br><br>const handleFetchPosts = async () =&gt; {<br>  try {<br>    // Get posts from content-publisher plugin<br>    const response = await axios.get(`/content-publisher/posts`);<br>    setPosts(response.data);<br>  } catch (error) {<br>    console.error(&quot;Error fetching posts:&quot;, error);<br>  }<br>};<br>useEffect(() =&gt; {<br>  handleFetchPosts();<br>}, []);<br>// ... other codes</pre><p>The handleFetchPosts() function above fetches blog posts from the /content-publisher/posts endpoint which we already created in our routes, using axios and updates the posts state with the response data, handling any errors by logging them to the console. It is invoked inside a useEffect hook to run once when the component mounts.</p><p>Here is what our plugin admin panel should look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*KK5moi51do9rMeWx.png" /></figure><p><em>Content Publisher Table</em></p><p><a href="https://gist.github.com/Theodore-Kelechukwu-Onyejiaku/51541663048806c8f828345b475ae1fe">👉 See the complete code of </a><a href="https://gist.github.com/Theodore-Kelechukwu-Onyejiaku/51541663048806c8f828345b475ae1fe">PublishingTable component here</a>.</p><h3>Publishing to Dev</h3><p>Now, let’s publish a post to Dev!</p><h3>Server Side: Create Plugin Service and Modify Plugin Controller Method</h3><p>Let’s start by implementing this on the server side of our plugin.<br><strong>1. Create a Service For Publishing Post to Dev</strong><br>We will start by creating a service called publishPostToDevTo. Add the code below to the service file ./src/plugins/content-publisher/server/src/services/service.ts with the following code:</p><pre>// ... other codes<br><br>/**<br> * Publish Post to Dev.to<br> */<br>async publishPostToDevTo(post: any) {<br>  try {<br>    // destructuring the post object<br>    const { title, content, canonicalUrl, tags, banner } = post.blog;<br>    // get the blog tags<br>    const blogTags = tags.map((tag) =&gt; tag.blogTag);<br>    // payload to be sent to dev.to<br>    const devToPayload = {<br>      article: {<br>        title,<br>        body_markdown: content,<br>        published: true,<br>        series: null,<br>        main_image: banner,<br>        canonical_url: canonicalUrl,<br>        description:<br>          content.length &gt; 140 ? `${content.slice(0, 140)}...` : content,<br>        tags: blogTags,<br>        organization_id: null,<br>      },<br>    };<br>    // post<br>    const response = await axios.post(<br>      `https://dev.to/api/articles`,<br>      devToPayload,<br>      {<br>        headers: {<br>          &quot;Content-Type&quot;: &quot;application/json&quot;,<br>          &quot;api-key&quot;: process.env.DEVTO_API_KEY,<br>        },<br>      },<br>    );<br>    // get the dev.to url<br>    const devToUrl = response.data?.url;<br>    // update the post with the dev.to link<br>    await strapi.documents(&quot;plugin::content-publisher.post&quot;).update({<br>      documentId: post.documentId,<br>      data: {<br>        devToLink: devToUrl,<br>      } as any,<br>    });<br>    // return the response<br>    return response.data;<br>  } catch (error) {<br>    return error.response.data<br>  }<br>}<br>// ... other codes</pre><p><a href="https://gist.github.com/Theodore-Kelechukwu-Onyejiaku/e70bfde08d1a2cb3004c9183e40a19a9">👉 See complete code of the snippet above</a></p><p>Here is what the code above does:</p><ul><li>Takes a <strong>Post</strong> entry as a parameter which will be sent from the admin panel or frontend.</li><li>Destructures the <strong>Post</strong> entry to get details of the blog such as title, content, canonicalUrl, tags, and banner</li><li>Maps through the tags object to return an array containing the tags as strings.</li><li>Creates a Dev API payload using the Dev request body schema. Learn more <a href="https://developers.forem.com/api/v0#tag/articles/operation/createArticle">here</a>.</li><li>Sends a POST request to https://dev.to/api/articles endpoint with the Dev API Key.</li><li>Retrieves the live link to the published post and updates the <strong>Post</strong> entry of our plugin if the API request is successful. Otherwise, an error is returned.</li></ul><p><strong>2. Update Plugin Controller</strong><br>Update the plugin controller method publishPostToDevTo with the following code:</p><pre>// ./src/plugins/content-publisher/server/src/controllers/controller.ts<br><br>import type { Core } from &quot;@strapi/strapi&quot;;<br>const controller = ({ strapi }: { strapi: Core.Strapi }) =&gt; ({<br>  // get blog entries<br>  async getBlogs(ctx) {},<br>  // get posts<br>  async getPosts(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&quot;content-publisher&quot;)<br>      .service(&quot;service&quot;)<br>      .getPosts();<br>  },<br>  // publish a blog post to dev.to<br>  async publishPostToDevTo(ctx) {<br>    ctx.body = await strapi<br>      .plugin(&quot;medium-publisher&quot;)<br>      .service(&quot;service&quot;)<br>      .publishPostToDevTo(ctx.request.body);<br>  },<br>  // publish a blog post to medium<br>  async publishPostToMedium(ctx) {},<br>  // search for a post<br>  async getSearchQuery(ctx) {},<br>  // delete a post<br>  async deletePost(ctx) {},<br>  // get a single post<br>  async getSinglePost(ctx) {},<br>});<br>export default controller;</pre><p>The publishPostToDevTo controller method is now modified to call the publishPostToDevTo service we created earlier.</p><h3>Admin Panel</h3><p>In the admin section, we will have to update the publish button to be able to publish post to Dev or Medium.</p><p><strong>Update The Publish Button</strong></p><pre>// ... other codes<br><br>// Function to handle publishing the post<br>  const handlePublishPost = async () =&gt; {<br>    try {<br>      // Set loading to true<br>      setLoading(true);<br>      let endpoint;<br>      // Check if the type is medium or devto<br>      if (type === &#39;medium&#39;) {<br>        endpoint = &#39;/content-publisher/publish-to-medium&#39;;<br>      } else {<br>        endpoint = &#39;/content-publisher/publish-to-devto&#39;;<br>      }<br>      // Post the data<br>      await axios.post(endpoint, post);<br>      // Reload the page<br>      window.location.reload();<br>    } catch (error) {<br>      console.log(error);<br>    } finally {<br>      // Set loading to false<br>      setLoading(false);<br>    }<br>  };<br>// ... other codes</pre><p><a href="https://gist.github.com/Theodore-Kelechukwu-Onyejiaku/4c7647c3f3dcfc84e2a1132e0702ff73">👉 See complete code of the snippet above</a>.</p><p>Here is what the code above does:</p><ul><li>We updated the PublishButton button to handle publishing a post to either Medium or Dev.to based on the type prop.</li><li>It manages a loading state with useState and uses an axios.post request to send the post data to the appropriate plugin endpoint /content-publisher/publish-to-medium or /content-publisher/publish-to-devto. Recall the private routes we created earlier for our plugin.</li><li>The button dynamically updates its appearance and behavior, showing different states (e.g., “published,” “publishing,” or “start”) and enabling users to visit the post’s live link if already published.</li></ul><p>Here is a demo of what we did above:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*Xu1RPHjhn_xruP7T.gif" /></figure><p>As seen above, we can now publish posts to Dev. Amazing!</p><h3>Github Project Repo</h3><p>You can find the complete project for this tutorial in this <a href="https://github.com/Theodore-Kelechukwu-Onyejiaku/custom-strapi-plugin">Github repo</a>.</p><p>In the repo, you will find branches part-1 and part-2. They both represent the complete code for each part of this tutorial.</p><h3>Conclusion</h3><p>In this tutorial, we learned how to develop Strapi plugins. We have delved into initializing and customizing a Strapi plugin. We also looked at how to create content types for a Strapi plugin and pass data in a Strapi plugin. Finally, we consumed the Dev API using our Strapi headless CMS plugin to publish posts to dev.to.</p><p>In the next part of this tutorial, we will be able to publish posts to medium.com. Also, we will inject our plugin into the <strong>Blog</strong> collection type and implement search and pagination. See you in the next part.</p><h3>Strapi Open Office Hours</h3><p>If you have any questions about Strapi 5 or just would like to stop by and say hi, you can join us at <strong>Strapi’s Discord Open Office Hours</strong> Monday through Friday at 12:30 pm — 1:30 pm CST: <a href="https://discord.com/invite/strapi">Strapi Discord Open Office Hours</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86af8b5ff250" width="1" height="1" alt=""><hr><p><a href="https://medium.com/strapi/build-a-custom-strapi-plugin-with-medium-and-dev-to-apis-part-1-86af8b5ff250">Build a Custom Strapi Plugin with Medium and Dev.to APIs — Part 1</a> was originally published in <a href="https://medium.com/strapi">Strapi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Commonly Asked Questions: Transitioning from Strapi 4 to Strapi 5]]></title>
            <link>https://medium.com/strapi/commonly-asked-questions-transitioning-from-strapi-4-to-strapi-5-c2af2dd72622?source=rss-9323ef8b74c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2af2dd72622</guid>
            <category><![CDATA[strapi]]></category>
            <category><![CDATA[faq]]></category>
            <category><![CDATA[strapi-v5]]></category>
            <category><![CDATA[strapi-v4]]></category>
            <dc:creator><![CDATA[Theodore Kelechukwu Onyejiaku]]></dc:creator>
            <pubDate>Thu, 12 Dec 2024 15:09:27 GMT</pubDate>
            <atom:updated>2024-12-12T15:09:27.063Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kEUcFesxteMFq35aF4WxTw.png" /></figure><p>With the release of Strapi 5, developers and users have been introduced to a range of new features, breaking changes, and enhancements aimed at improving the overall developer experience. However, change often brings questions.</p><p>This post addresses some of the most commonly asked questions (faq) around what has changed when transitioning from Strapi 4 to Strapi 5, helping you navigate the updates with ease.</p><h3>Key Changes in Strapi 5</h3><h3>What are the most significant updates in Strapi 5 from Strapi 4?</h3><p>Strapi 5 introduces several updates, including:</p><ol><li>Document System: A new concept for managing content variations (e.g., drafts, published states, and locales) in a unified way, enabling advanced features like content history and draft &amp; publish.</li><li>Plugin SDK: Simplifies plugin development and sharing by automating packaging, bundling, and compatibility checks.</li><li>Refined API Response Format: Flattened data structure for more intuitive and efficient API interactions.</li><li>Strapi Design System Updates: Improved UI consistency and maintainability.</li><li>TypeScript Integration: Enhanced support for type safety and developer productivity.</li></ol><h3>The Document System</h3><h3>Why was the Document System introduced?</h3><p>The Document System was introduced to unify content variations like drafts, published states, and locales under a single model. This approach simplifies content management while paving the way for new features such as content history and draft &amp; publish. By consolidating variations, Strapi ensures better consistency across the application and provides a robust foundation for plugins and advanced functionalities.</p><h3>Is everything now a Document?</h3><p>No. Only entities that represent content types with multiple states or locales are considered Documents. For example, the Media Library and Users &amp; Permissions (U&amp;P) are not managed as Documents because their use cases do not align with this model.</p><h3>How do I incorporate the Document System into my plugin?</h3><p>Plugins can interact with the Document System using the new Document Service API. This API allows you to create, update, and manage content variations programmatically, ensuring seamless integration with the Document model.</p><h3>TypeScript Integration</h3><h3>Why is TypeScript integration significant in Strapi 5?</h3><p>TypeScript integration in Strapi 5 marks a major milestone, aiming to provide stronger type safety, better tooling support, and a smoother development experience. Here’s how Strapi 5 uses TypeScript to empower developers:</p><p>1. Stronger Type Safety:</p><p>With TypeScript, Strapi 5 enforces stricter type checks, reducing runtime errors and ensuring greater confidence when working with complex data structures. Developers can now benefit from autocomplete and error detection directly in their IDEs, leading to fewer bugs and faster debugging.</p><p>2. Improved Developer Productivity:</p><p>TypeScript integration brings features like type inference and IntelliSense, helping developers write code more efficiently. By knowing the shape of data and available methods, developers can focus on building functionality rather than guessing how things work under the hood.</p><p>3. Enhanced Plugin Development:</p><p>Plugins built using the new Plugin SDK can now leverage TypeScript types, ensuring better compatibility and fewer issues when integrating plugins into projects. Plugin developers can use the provided type definitions to build more robust and reliable extensions.</p><p>4. Improved Design System:</p><p>The design system’s migration to TypeScript was a significant effort, exposing potential breaking changes that were carefully addressed. This effort resulted in better type definitions for UI components, making integration and customization easier for developers.</p><p>5. Backward Compatibility:</p><p>Strapi 5 continues to support JavaScript projects, ensuring that developers who are not ready to adopt TypeScript can still work seamlessly with the framework. However, adopting TypeScript is highly recommended for new projects to take full advantage of its benefits.</p><h3>The Plugin SDK</h3><h3>Why was a Plugin SDK developed?</h3><p>The Plugin SDK simplifies the process of creating, packaging, and sharing plugins by automating tasks like dependency management and bundling. It also aligns with industry standards, reducing the learning curve for developers familiar with SDK-based ecosystems.</p><h3>What does the Plugin SDK offer?</h3><p>The SDK provides:</p><ul><li>Streamlined project initialization (npx @strapi/sdk-plugin init my-plugin)</li><li>Build tools for packaging plugins in CommonJS and ES Modules.</li><li>Live development tools (watch and watch:link) for real-time updates.</li><li>Verification tools to ensure plugins are ready for production.</li></ul><h3>Why was the helper plugin removed?</h3><p>The helper plugin was removed to reduce complexity and eliminate circular dependencies within the Strapi ecosystem. It was initially used to centralize shared components and hooks, such as notifications or tracking, but this approach led to several problems:</p><ol><li>Bloated API Surface: The helper plugin included too many unrelated features, causing confusion among developers.</li><li>Dependency Issues: Many contexts and providers relied on by the admin panel were tied to the helper plugin, creating a backward relationship where the plugin depended on the admin package. This resulted in circular dependencies and complications during the TypeScript migration.</li><li>Misleading Name: Despite its name, the helper plugin was not an actual plugin, which further confused developers.</li><li>Better Hierarchy: By moving shared utilities directly into the admin package, the system became more linear and easier to maintain, with admin serving as the base layer for all frontend code.</li></ol><p>This restructuring improves clarity, simplifies the codebase, and ensures a cleaner separation of concerns. It also paves the way for easier maintenance and development, especially with the integration of TypeScript.</p><h3>API Changes</h3><h3>Why Did the Response Format Change?</h3><p>Strapi 5 introduced a flattened API response format to improve readability, simplify data access, and boost performance. By eliminating the excessive nesting of attributes and data keys, developers can now work with cleaner and more streamlined data structures. This update is especially beneficial for handling complex queries, as it reduces the overhead associated with navigating deeply nested objects.</p><p>To illustrate the difference, we’ll compare an example response from a Strapi 4 project with its updated equivalent in Strapi 5.</p><p>We will use an example from our archived Strapi Corporate Strater Project to see the comparison between the old response and new.</p><p>We will take a look at the data being fetched for our landing page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gPCiZMM-xRD728Dz.gif" /></figure><h3>Example Comparison</h3><h3>Strapi 4 Response (Nested Format)</h3><p>In Strapi 4, the response format is deeply nested, with attributes and related data stored under separate keys. For example:</p><pre>1{<br>2  &quot;data&quot;: [<br>3    {<br>4      &quot;id&quot;: 1,<br>5      &quot;attributes&quot;: {<br>6        &quot;shortName&quot;: &quot;Home Page&quot;,<br>7        &quot;slug&quot;: &quot;home&quot;,<br>8        &quot;contentSections&quot;: [<br>9          {<br>10            &quot;__component&quot;: &quot;sections.hero&quot;,<br>11            &quot;title&quot;: &quot;Strapi [Starter] with Next JS&quot;,<br>12            &quot;picture&quot;: {<br>13              &quot;data&quot;: {<br>14                &quot;attributes&quot;: {<br>15                  &quot;url&quot;: &quot;/uploads/undraw_woman_ffrd.svg&quot;<br>16                }<br>17              }<br>18            }<br>19          }<br>20        ]<br>21      }<br>22    }<br>23  ]<br>24}</pre><p>This structure requires accessing multiple layers (e.g., data -&gt; attributes -&gt; contentSections) to retrieve information, making it cumbersome for developers and less performant.</p><h3>Strapi 5 Response (Flattened Format)</h3><p>In Strapi 5, the response has been streamlined. Attributes are now at the top level, and related data no longer requires navigating through a data or attributes wrapper:</p><pre>1{<br>2  &quot;data&quot;: [<br>3    {<br>4      &quot;id&quot;: 10,<br>5      &quot;shortName&quot;: &quot;Home Page&quot;,<br>6      &quot;slug&quot;: &quot;home&quot;,<br>7      &quot;contentSections&quot;: [<br>8        {<br>9          &quot;__component&quot;: &quot;sections.hero&quot;,<br>10          &quot;title&quot;: &quot;Strapi [Starter] with Next JS&quot;,<br>11          &quot;picture&quot;: {<br>12            &quot;id&quot;: 33,<br>13            &quot;url&quot;: &quot;/uploads/undraw_woman_ffrd.svg&quot;<br>14          }<br>15        }<br>16      ]<br>17    }<br>18  ]<br>19}</pre><p>This flattened format makes it easier to extract data directly, improving code clarity and reducing the need for verbose queries.</p><h3>Example Comparison: Full Response Strapi 4 vs Strapi 5</h3><p>Strapi 4 Response:</p><pre>1{<br>2    &quot;data&quot;: [<br>3        {<br>4            &quot;id&quot;: 1,<br>5            &quot;attributes&quot;: {<br>6                &quot;shortName&quot;: &quot;Home Page&quot;,<br>7                &quot;slug&quot;: &quot;home&quot;,<br>8                &quot;heading&quot;: &quot;dfsgsg&quot;,<br>9                &quot;description&quot;: &quot;dfsgsdfg&quot;,<br>10                &quot;createdAt&quot;: &quot;2023-03-08T14:13:57.041Z&quot;,<br>11                &quot;updatedAt&quot;: &quot;2024-05-31T16:19:31.954Z&quot;,<br>12                &quot;publishedAt&quot;: &quot;2023-03-08T14:28:43.068Z&quot;,<br>13                &quot;locale&quot;: &quot;en&quot;,<br>14                &quot;contentSections&quot;: [<br>15                    {<br>16                        &quot;id&quot;: 1,<br>17                        &quot;__component&quot;: &quot;sections.hero&quot;,<br>18                        &quot;title&quot;: &quot;Strapi [Starter] with Next JS&quot;,<br>19                        &quot;description&quot;: &quot;This is build with [Strapi] and [Next] JS. A match made in heaven.&quot;,<br>20                        &quot;picture&quot;: {<br>21                            &quot;data&quot;: {<br>22                                &quot;id&quot;: 11,<br>23                                &quot;attributes&quot;: {<br>24                                    &quot;url&quot;: &quot;/uploads/undraw_woman_ffrd_b3ac24fb06.svg&quot;,<br>25                                    &quot;alternativeText&quot;: null,<br>26                                    &quot;caption&quot;: null,<br>27                                    &quot;width&quot;: 643,<br>28                                    &quot;height&quot;: 700<br>29                                }<br>30                            }<br>31                        },<br>32                        &quot;buttons&quot;: [<br>33                            {<br>34                                &quot;id&quot;: 2,<br>35                                &quot;url&quot;: &quot;https://discord.com/invite/strapi&quot;,<br>36                                &quot;newTab&quot;: true,<br>37                                &quot;text&quot;: &quot;Discord&quot;,<br>38                                &quot;type&quot;: &quot;secondary&quot;<br>39                            },<br>40                            {<br>41                                &quot;id&quot;: 3,<br>42                                &quot;url&quot;: &quot;https://strapi.io/events&quot;,<br>43                                &quot;newTab&quot;: true,<br>44                                &quot;text&quot;: &quot;Events&quot;,<br>45                                &quot;type&quot;: &quot;primary&quot;<br>46                            }<br>47                        ]<br>48                    },<br>49                    {<br>50                        &quot;id&quot;: 1,<br>51                        &quot;__component&quot;: &quot;sections.features&quot;,<br>52                        &quot;heading&quot;: &quot;Features&quot;,<br>53                        &quot;description&quot;: &quot;Welcome to Strapi Starter&quot;,<br>54                        &quot;feature&quot;: [<br>55                            {<br>56                                &quot;id&quot;: 1,<br>57                                &quot;title&quot;: &quot;Discover Next.js&quot;,<br>58                                &quot;description&quot;: &quot;The React Framework for Production: Explore the future of web development with Next.js, the cutting-edge React framework.&quot;,<br>59                                &quot;showLink&quot;: true,<br>60                                &quot;newTab&quot;: true,<br>61                                &quot;url&quot;: &quot;https://vercel.com/&quot;,<br>62                                &quot;text&quot;: &quot;Learn more&quot;,<br>63                                &quot;media&quot;: {<br>64                                    &quot;data&quot;: null<br>65                                }<br>66                            },<br>67                            {<br>68                                &quot;id&quot;: 2,<br>69                                &quot;title&quot;: &quot;Strapi&quot;,<br>70                                &quot;description&quot;: &quot;Unleash the power of Strapi, the leading open-source headless CMS that lets you create, manage, and distribute your content across multiple platforms.&quot;,<br>71                                &quot;showLink&quot;: true,<br>72                                &quot;newTab&quot;: true,<br>73                                &quot;url&quot;: &quot;https://strapi.io&quot;,<br>74                                &quot;text&quot;: &quot;Learn more&quot;,<br>75                                &quot;media&quot;: {<br>76                                    &quot;data&quot;: null<br>77                                }<br>78                            },<br>79                            {<br>80                                &quot;id&quot;: 3,<br>81                                &quot;title&quot;: &quot;Cloud&quot;,<br>82                                &quot;description&quot;: &quot;Simplify your content management experience with Strapi Cloud, the fully-managed hosting solution for your Strapi projects.&quot;,<br>83                                &quot;showLink&quot;: true,<br>84                                &quot;newTab&quot;: true,<br>85                                &quot;url&quot;: &quot;https://strapi.io/cloud&quot;,<br>86                                &quot;text&quot;: &quot;Learn more&quot;,<br>87                                &quot;media&quot;: {<br>88                                    &quot;data&quot;: null<br>89                                }<br>90                            }<br>91                        ]<br>92                    },<br>93                    {<br>94                        &quot;id&quot;: 1,<br>95                        &quot;__component&quot;: &quot;sections.pricing&quot;,<br>96                        &quot;title&quot;: &quot;Our Plans&quot;,<br>97                        &quot;plans&quot;: [<br>98                            {<br>99                                &quot;id&quot;: 1,<br>100                                &quot;name&quot;: &quot;Free&quot;,<br>101                                &quot;description&quot;: &quot;Features&quot;,<br>102                                &quot;isRecommended&quot;: false,<br>103                                &quot;price&quot;: 0,<br>104                                &quot;pricePeriod&quot;: &quot;Monthly&quot;,<br>105                                &quot;product_features&quot;: {<br>106                                    &quot;data&quot;: [<br>107                                        {<br>108                                            &quot;id&quot;: 1,<br>109                                            &quot;attributes&quot;: {<br>110                                                &quot;name&quot;: &quot;Example Feature 1&quot;,<br>111                                                &quot;createdAt&quot;: &quot;2023-03-10T15:45:14.988Z&quot;,<br>112                                                &quot;updatedAt&quot;: &quot;2023-03-28T15:45:07.118Z&quot;,<br>113                                                &quot;publishedAt&quot;: &quot;2023-03-10T15:45:16.468Z&quot;<br>114                                            }<br>115                                        },<br>116                                        {<br>117                                            &quot;id&quot;: 3,<br>118                                            &quot;attributes&quot;: {<br>119                                                &quot;name&quot;: &quot;Example Feature 2&quot;,<br>120                                                &quot;createdAt&quot;: &quot;2023-03-10T15:46:27.207Z&quot;,<br>121                                                &quot;updatedAt&quot;: &quot;2023-03-28T15:45:18.540Z&quot;,<br>122                                                &quot;publishedAt&quot;: &quot;2023-03-10T15:46:27.565Z&quot;<br>123                                            }<br>124                                        },<br>125                                        {<br>126                                            &quot;id&quot;: 4,<br>127                                            &quot;attributes&quot;: {<br>128                                                &quot;name&quot;: &quot;Example Feature 3&quot;,<br>129                                                &quot;createdAt&quot;: &quot;2023-03-10T15:46:39.431Z&quot;,<br>130                                                &quot;updatedAt&quot;: &quot;2023-03-28T15:45:28.608Z&quot;,<br>131                                                &quot;publishedAt&quot;: &quot;2023-03-10T15:46:40.548Z&quot;<br>132                                            }<br>133                                        }<br>134                                    ]<br>135                                }<br>136                            },<br>137                            {<br>138                                &quot;id&quot;: 2,<br>139                                &quot;name&quot;: &quot;Pro&quot;,<br>140                                &quot;description&quot;: &quot;Features&quot;,<br>141                                &quot;isRecommended&quot;: true,<br>142                                &quot;price&quot;: 9.99,<br>143                                &quot;pricePeriod&quot;: &quot;monthly&quot;,<br>144                                &quot;product_features&quot;: {<br>145                                    &quot;data&quot;: [<br>146                                        {<br>147                                            &quot;id&quot;: 1,<br>148                                            &quot;attributes&quot;: {<br>149                                                &quot;name&quot;: &quot;Example Feature 1&quot;,<br>150                                                &quot;createdAt&quot;: &quot;2023-03-10T15:45:14.988Z&quot;,<br>151                                                &quot;updatedAt&quot;: &quot;2023-03-28T15:45:07.118Z&quot;,<br>152                                                &quot;publishedAt&quot;: &quot;2023-03-10T15:45:16.468Z&quot;<br>153                                            }<br>154                                        },<br>155                                        {<br>156                                            &quot;id&quot;: 3,<br>157                                            &quot;attributes&quot;: {<br>158                                                &quot;name&quot;: &quot;Example Feature 2&quot;,<br>159                                                &quot;createdAt&quot;: &quot;2023-03-10T15:46:27.207Z&quot;,<br>160                                                &quot;updatedAt&quot;: &quot;2023-03-28T15:45:18.540Z&quot;,<br>161                                                &quot;publishedAt&quot;: &quot;2023-03-10T15:46:27.565Z&quot;<br>162                                            }<br>163                                        },<br>164                                        {<br>165                                            &quot;id&quot;: 4,<br>166                                            &quot;attributes&quot;: {<br>167                                                &quot;name&quot;: &quot;Example Feature 3&quot;,<br>168                                                &quot;createdAt&quot;: &quot;2023-03-10T15:46:39.431Z&quot;,<br>169                                                &quot;updatedAt&quot;: &quot;2023-03-28T15:45:28.608Z&quot;,<br>170                                                &quot;publishedAt&quot;: &quot;2023-03-10T15:46:40.548Z&quot;<br>171                                            }<br>172                                        },<br>173                                        {<br>174                                            &quot;id&quot;: 2,<br>175                                            &quot;attributes&quot;: {<br>176                                                &quot;name&quot;: &quot;Example Feature 4&quot;,<br>177                                                &quot;createdAt&quot;: &quot;2023-03-10T15:45:47.489Z&quot;,<br>178                                                &quot;updatedAt&quot;: &quot;2023-03-28T15:46:00.360Z&quot;,<br>179                                                &quot;publishedAt&quot;: &quot;2023-03-10T15:46:10.561Z&quot;<br>180                                            }<br>181                                        }<br>182                                    ]<br>183                                }<br>184                            },<br>185                            {<br>186                                &quot;id&quot;: 3,<br>187                                &quot;name&quot;: &quot;Enterprise &quot;,<br>188                                &quot;description&quot;: &quot;Features&quot;,<br>189                                &quot;isRecommended&quot;: false,<br>190                                &quot;price&quot;: 19.99,<br>191                                &quot;pricePeriod&quot;: &quot;monthly&quot;,<br>192                                &quot;product_features&quot;: {<br>193                                    &quot;data&quot;: [<br>194                                        {<br>195                                            &quot;id&quot;: 1,<br>196                                            &quot;attributes&quot;: {<br>197                                                &quot;name&quot;: &quot;Example Feature 1&quot;,<br>198                                                &quot;createdAt&quot;: &quot;2023-03-10T15:45:14.988Z&quot;,<br>199                                                &quot;updatedAt&quot;: &quot;2023-03-28T15:45:07.118Z&quot;,<br>200                                                &quot;publishedAt&quot;: &quot;2023-03-10T15:45:16.468Z&quot;<br>201                                            }<br>202                                        },<br>203                                        {<br>204                                            &quot;id&quot;: 3,<br>205                                            &quot;attributes&quot;: {<br>206                                                &quot;name&quot;: &quot;Example Feature 2&quot;,<br>207                                                &quot;createdAt&quot;: &quot;2023-03-10T15:46:27.207Z&quot;,<br>208                                                &quot;updatedAt&quot;: &quot;2023-03-28T15:45:18.540Z&quot;,<br>209                                                &quot;publishedAt&quot;: &quot;2023-03-10T15:46:27.565Z&quot;<br>210                                            }<br>211                                        },<br>212                                        {<br>213                                            &quot;id&quot;: 4,<br>214                                            &quot;attributes&quot;: {<br>215                                                &quot;name&quot;: &quot;Example Feature 3&quot;,<br>216                                                &quot;createdAt&quot;: &quot;2023-03-10T15:46:39.431Z&quot;,<br>217                                                &quot;updatedAt&quot;: &quot;2023-03-28T15:45:28.608Z&quot;,<br>218                                                &quot;publishedAt&quot;: &quot;2023-03-10T15:46:40.548Z&quot;<br>219                                            }<br>220                                        },<br>221                                        {<br>222                                            &quot;id&quot;: 2,<br>223                                            &quot;attributes&quot;: {<br>224                                                &quot;name&quot;: &quot;Example Feature 4&quot;,<br>225                                                &quot;createdAt&quot;: &quot;2023-03-10T15:45:47.489Z&quot;,<br>226                                                &quot;updatedAt&quot;: &quot;2023-03-28T15:46:00.360Z&quot;,<br>227                                                &quot;publishedAt&quot;: &quot;2023-03-10T15:46:10.561Z&quot;<br>228                                            }<br>229                                        },<br>230                                        {<br>231                                            &quot;id&quot;: 5,<br>232                                            &quot;attributes&quot;: {<br>233                                                &quot;name&quot;: &quot;Example Feature 5&quot;,<br>234                                                &quot;createdAt&quot;: &quot;2023-03-28T15:45:55.243Z&quot;,<br>235                                                &quot;updatedAt&quot;: &quot;2023-03-28T15:50:01.464Z&quot;,<br>236                                                &quot;publishedAt&quot;: &quot;2023-03-28T15:50:01.464Z&quot;<br>237                                            }<br>238                                        }<br>239                                    ]<br>240                                }<br>241                            }<br>242                        ]<br>243                    },<br>244                    {<br>245                        &quot;id&quot;: 1,<br>246                        &quot;__component&quot;: &quot;sections.testimonials-group&quot;,<br>247                        &quot;title&quot;: &quot;Testimonials&quot;,<br>248                        &quot;description&quot;: &quot;Hello&quot;,<br>249                        &quot;testimonials&quot;: [<br>250                            {<br>251                                &quot;id&quot;: 1,<br>252                                &quot;text&quot;: &quot;ed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.&quot;,<br>253                                &quot;authorName&quot;: &quot;Paul Brats&quot;,<br>254                                &quot;picture&quot;: {<br>255                                    &quot;data&quot;: {<br>256                                        &quot;id&quot;: 20,<br>257                                        &quot;attributes&quot;: {<br>258                                            &quot;url&quot;: &quot;/uploads/paul_brats_012832af74.jpg&quot;,<br>259                                            &quot;alternativeText&quot;: null,<br>260                                            &quot;caption&quot;: null,<br>261                                            &quot;width&quot;: 200,<br>262                                            &quot;height&quot;: 200<br>263                                        }<br>264                                    }<br>265                                }<br>266                            },<br>267                            {<br>268                                &quot;id&quot;: 2,<br>269                                &quot;text&quot;: &quot;ed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.&quot;,<br>270                                &quot;authorName&quot;: &quot;Kit Kat&quot;,<br>271                                &quot;picture&quot;: {<br>272                                    &quot;data&quot;: {<br>273                                        &quot;id&quot;: 22,<br>274                                        &quot;attributes&quot;: {<br>275                                            &quot;url&quot;: &quot;/uploads/kit_kat_96feba6636.png&quot;,<br>276                                            &quot;alternativeText&quot;: null,<br>277                                            &quot;caption&quot;: null,<br>278                                            &quot;width&quot;: 2000,<br>279                                            &quot;height&quot;: 2000<br>280                                        }<br>281                                    }<br>282                                }<br>283                            }<br>284                        ]<br>285                    },<br>286                    {<br>287                        &quot;id&quot;: 1,<br>288                        &quot;__component&quot;: &quot;sections.lead-form&quot;,<br>289                        &quot;title&quot;: &quot;Join our community.&quot;,<br>290                        &quot;emailPlaceholder&quot;: &quot;Enter your email&quot;,<br>291                        &quot;location&quot;: &quot;main page&quot;,<br>292                        &quot;description&quot;: &quot;Doloribus consectetur quasi ipsa quo neque culpa blanditiis ducimus recusandae a veritatis optio cumque, in harum ad nam!&quot;,<br>293                        &quot;submitButton&quot;: {<br>294                            &quot;id&quot;: 1,<br>295                            &quot;text&quot;: &quot;Submit&quot;,<br>296                            &quot;type&quot;: &quot;primary&quot;<br>297                        }<br>298                    }<br>299                ],<br>300                &quot;seo&quot;: {<br>301                    &quot;id&quot;: 8,<br>302                    &quot;metaTitle&quot;: &quot;dfgsdg&quot;,<br>303                    &quot;metaDescription&quot;: &quot;dsfgsdf&quot;,<br>304                    &quot;shareImage&quot;: {<br>305                        &quot;data&quot;: null<br>306                    }<br>307                }<br>308            }<br>309        }<br>310    ],<br>311    &quot;meta&quot;: {<br>312        &quot;pagination&quot;: {<br>313            &quot;page&quot;: 1,<br>314            &quot;pageSize&quot;: 25,<br>315            &quot;pageCount&quot;: 1,<br>316            &quot;total&quot;: 1<br>317        }<br>318    }<br>319}</pre><p>Strapi 5 Response:</p><pre>1{<br>2    &quot;data&quot;: [<br>3        {<br>4            &quot;id&quot;: 10,<br>5            &quot;shortName&quot;: &quot;Home Page&quot;,<br>6            &quot;slug&quot;: &quot;home&quot;,<br>7            &quot;heading&quot;: &quot;Home Page&quot;,<br>8            &quot;description&quot;: &quot;This is the home page&quot;,<br>9            &quot;createdAt&quot;: &quot;2023-03-08T14:13:57.041Z&quot;,<br>10            &quot;updatedAt&quot;: &quot;2024-09-25T16:22:15.255Z&quot;,<br>11            &quot;publishedAt&quot;: &quot;2024-09-25T16:22:15.278Z&quot;,<br>12            &quot;locale&quot;: &quot;en&quot;,<br>13            &quot;documentId&quot;: &quot;jp9xgszv0fiebxygaonae4jr&quot;,<br>14            &quot;contentSections&quot;: [<br>15                {<br>16                    &quot;__component&quot;: &quot;sections.hero&quot;,<br>17                    &quot;id&quot;: 8,<br>18                    &quot;title&quot;: &quot;Strapi [Starter] with Next JS&quot;,<br>19                    &quot;description&quot;: &quot;This is build with [Strapi] and [Next] JS. A match made in heaven.&quot;,<br>20                    &quot;picture&quot;: {<br>21                        &quot;id&quot;: 33,<br>22                        &quot;name&quot;: &quot;undraw_woman_ffrd.svg&quot;,<br>23                        &quot;alternativeText&quot;: null,<br>24                        &quot;caption&quot;: null,<br>25                        &quot;width&quot;: 643,<br>26                        &quot;height&quot;: 700,<br>27                        &quot;formats&quot;: null,<br>28                        &quot;hash&quot;: &quot;undraw_woman_ffrd_b3ac24fb06&quot;,<br>29                        &quot;ext&quot;: &quot;.svg&quot;,<br>30                        &quot;mime&quot;: &quot;image/svg+xml&quot;,<br>31                        &quot;size&quot;: 6.76,<br>32                        &quot;url&quot;: &quot;/uploads/undraw_woman_ffrd_b3ac24fb06.svg&quot;,<br>33                        &quot;previewUrl&quot;: null,<br>34                        &quot;provider&quot;: &quot;local&quot;,<br>35                        &quot;provider_metadata&quot;: null,<br>36                        &quot;createdAt&quot;: &quot;2023-03-09T18:10:31.642Z&quot;,<br>37                        &quot;updatedAt&quot;: &quot;2024-12-07T22:01:43.508Z&quot;,<br>38                        &quot;documentId&quot;: &quot;lojbt8nq3a7lbs1ket3s4ye2&quot;,<br>39                        &quot;locale&quot;: null,<br>40                        &quot;publishedAt&quot;: null<br>41                    },<br>42                    &quot;buttons&quot;: [<br>43                        {<br>44                            &quot;id&quot;: 9,<br>45                            &quot;url&quot;: &quot;https://discord.com/invite/strapi&quot;,<br>46                            &quot;newTab&quot;: true,<br>47                            &quot;text&quot;: &quot;Discord&quot;,<br>48                            &quot;type&quot;: &quot;secondary&quot;<br>49                        },<br>50                        {<br>51                            &quot;id&quot;: 10,<br>52                            &quot;url&quot;: &quot;https://strapi.io/events&quot;,<br>53                            &quot;newTab&quot;: true,<br>54                            &quot;text&quot;: &quot;Events&quot;,<br>55                            &quot;type&quot;: &quot;primary&quot;<br>56                        }<br>57                    ]<br>58                },<br>59                {<br>60                    &quot;__component&quot;: &quot;sections.features&quot;,<br>61                    &quot;id&quot;: 4,<br>62                    &quot;heading&quot;: &quot;Features&quot;,<br>63                    &quot;description&quot;: &quot;Welcome to Strapi Starter&quot;,<br>64                    &quot;feature&quot;: [<br>65                        {<br>66                            &quot;id&quot;: 10,<br>67                            &quot;title&quot;: &quot;Discover Next.js&quot;,<br>68                            &quot;description&quot;: &quot;The React Framework for Production: Explore the future of web development with Next.js, the cutting-edge React framework.&quot;,<br>69                            &quot;showLink&quot;: true,<br>70                            &quot;newTab&quot;: true,<br>71                            &quot;url&quot;: &quot;https://vercel.com/&quot;,<br>72                            &quot;text&quot;: &quot;Learn more&quot;<br>73                        },<br>74                        {<br>75                            &quot;id&quot;: 11,<br>76                            &quot;title&quot;: &quot;Strapi&quot;,<br>77                            &quot;description&quot;: &quot;Unleash the power of Strapi, the leading open-source headless CMS that lets you create, manage, and distribute your content across multiple platforms.&quot;,<br>78                            &quot;showLink&quot;: true,<br>79                            &quot;newTab&quot;: true,<br>80                            &quot;url&quot;: &quot;https://strapi.io&quot;,<br>81                            &quot;text&quot;: &quot;Learn more&quot;<br>82                        },<br>83                        {<br>84                            &quot;id&quot;: 12,<br>85                            &quot;title&quot;: &quot;Cloud&quot;,<br>86                            &quot;description&quot;: &quot;Simplify your content management experience with Strapi Cloud, the fully-managed hosting solution for your Strapi projects.&quot;,<br>87                            &quot;showLink&quot;: true,<br>88                            &quot;newTab&quot;: true,<br>89                            &quot;url&quot;: &quot;https://strapi.io/cloud&quot;,<br>90                            &quot;text&quot;: &quot;Learn more&quot;<br>91                        }<br>92                    ]<br>93                },<br>94                {<br>95                    &quot;__component&quot;: &quot;sections.pricing&quot;,<br>96                    &quot;id&quot;: 4,<br>97                    &quot;title&quot;: &quot;Our Plans&quot;,<br>98                    &quot;plans&quot;: [<br>99                        {<br>100                            &quot;id&quot;: 10,<br>101                            &quot;name&quot;: &quot;Free&quot;,<br>102                            &quot;description&quot;: &quot;Features&quot;,<br>103                            &quot;isRecommended&quot;: false,<br>104                            &quot;price&quot;: 0,<br>105                            &quot;pricePeriod&quot;: &quot;Monthly&quot;,<br>106                            &quot;product_features&quot;: [<br>107                                {<br>108                                    &quot;id&quot;: 16,<br>109                                    &quot;name&quot;: &quot;Example Feature 1&quot;,<br>110                                    &quot;createdAt&quot;: &quot;2023-03-10T15:45:14.988Z&quot;,<br>111                                    &quot;updatedAt&quot;: &quot;2023-03-28T15:45:07.118Z&quot;,<br>112                                    &quot;publishedAt&quot;: &quot;2023-03-10T15:45:16.468Z&quot;,<br>113                                    &quot;documentId&quot;: &quot;ji45ovqy68cpuj9a8hgfb67v&quot;,<br>114                                    &quot;locale&quot;: null<br>115                                },<br>116                                {<br>117                                    &quot;id&quot;: 18,<br>118                                    &quot;name&quot;: &quot;Example Feature 2&quot;,<br>119                                    &quot;createdAt&quot;: &quot;2023-03-10T15:46:27.207Z&quot;,<br>120                                    &quot;updatedAt&quot;: &quot;2023-03-28T15:45:18.540Z&quot;,<br>121                                    &quot;publishedAt&quot;: &quot;2023-03-10T15:46:27.565Z&quot;,<br>122                                    &quot;documentId&quot;: &quot;wxim98n316kfqy54zsmdazkp&quot;,<br>123                                    &quot;locale&quot;: null<br>124                                },<br>125                                {<br>126                                    &quot;id&quot;: 19,<br>127                                    &quot;name&quot;: &quot;Example Feature 3&quot;,<br>128                                    &quot;createdAt&quot;: &quot;2023-03-10T15:46:39.431Z&quot;,<br>129                                    &quot;updatedAt&quot;: &quot;2023-03-28T15:45:28.608Z&quot;,<br>130                                    &quot;publishedAt&quot;: &quot;2023-03-10T15:46:40.548Z&quot;,<br>131                                    &quot;documentId&quot;: &quot;v6phofjnzfn0q2i9ham968mj&quot;,<br>132                                    &quot;locale&quot;: null<br>133                                }<br>134                            ]<br>135                        },<br>136                        {<br>137                            &quot;id&quot;: 11,<br>138                            &quot;name&quot;: &quot;Pro&quot;,<br>139                            &quot;description&quot;: &quot;Features&quot;,<br>140                            &quot;isRecommended&quot;: true,<br>141                            &quot;price&quot;: 9.99,<br>142                            &quot;pricePeriod&quot;: &quot;monthly&quot;,<br>143                            &quot;product_features&quot;: [<br>144                                {<br>145                                    &quot;id&quot;: 16,<br>146                                    &quot;name&quot;: &quot;Example Feature 1&quot;,<br>147                                    &quot;createdAt&quot;: &quot;2023-03-10T15:45:14.988Z&quot;,<br>148                                    &quot;updatedAt&quot;: &quot;2023-03-28T15:45:07.118Z&quot;,<br>149                                    &quot;publishedAt&quot;: &quot;2023-03-10T15:45:16.468Z&quot;,<br>150                                    &quot;documentId&quot;: &quot;ji45ovqy68cpuj9a8hgfb67v&quot;,<br>151                                    &quot;locale&quot;: null<br>152                                },<br>153                                {<br>154                                    &quot;id&quot;: 18,<br>155                                    &quot;name&quot;: &quot;Example Feature 2&quot;,<br>156                                    &quot;createdAt&quot;: &quot;2023-03-10T15:46:27.207Z&quot;,<br>157                                    &quot;updatedAt&quot;: &quot;2023-03-28T15:45:18.540Z&quot;,<br>158                                    &quot;publishedAt&quot;: &quot;2023-03-10T15:46:27.565Z&quot;,<br>159                                    &quot;documentId&quot;: &quot;wxim98n316kfqy54zsmdazkp&quot;,<br>160                                    &quot;locale&quot;: null<br>161                                },<br>162                                {<br>163                                    &quot;id&quot;: 19,<br>164                                    &quot;name&quot;: &quot;Example Feature 3&quot;,<br>165                                    &quot;createdAt&quot;: &quot;2023-03-10T15:46:39.431Z&quot;,<br>166                                    &quot;updatedAt&quot;: &quot;2023-03-28T15:45:28.608Z&quot;,<br>167                                    &quot;publishedAt&quot;: &quot;2023-03-10T15:46:40.548Z&quot;,<br>168                                    &quot;documentId&quot;: &quot;v6phofjnzfn0q2i9ham968mj&quot;,<br>169                                    &quot;locale&quot;: null<br>170                                },<br>171                                {<br>172                                    &quot;id&quot;: 17,<br>173                                    &quot;name&quot;: &quot;Example Feature 4&quot;,<br>174                                    &quot;createdAt&quot;: &quot;2023-03-10T15:45:47.489Z&quot;,<br>175                                    &quot;updatedAt&quot;: &quot;2023-03-28T15:46:00.360Z&quot;,<br>176                                    &quot;publishedAt&quot;: &quot;2023-03-10T15:46:10.561Z&quot;,<br>177                                    &quot;documentId&quot;: &quot;jykjv5t5h5kqh2u649un53ss&quot;,<br>178                                    &quot;locale&quot;: null<br>179                                }<br>180                            ]<br>181                        },<br>182                        {<br>183                            &quot;id&quot;: 12,<br>184                            &quot;name&quot;: &quot;Enterprise &quot;,<br>185                            &quot;description&quot;: &quot;Features&quot;,<br>186                            &quot;isRecommended&quot;: false,<br>187                            &quot;price&quot;: 19.99,<br>188                            &quot;pricePeriod&quot;: &quot;monthly&quot;,<br>189                            &quot;product_features&quot;: [<br>190                                {<br>191                                    &quot;id&quot;: 16,<br>192                                    &quot;name&quot;: &quot;Example Feature 1&quot;,<br>193                                    &quot;createdAt&quot;: &quot;2023-03-10T15:45:14.988Z&quot;,<br>194                                    &quot;updatedAt&quot;: &quot;2023-03-28T15:45:07.118Z&quot;,<br>195                                    &quot;publishedAt&quot;: &quot;2023-03-10T15:45:16.468Z&quot;,<br>196                                    &quot;documentId&quot;: &quot;ji45ovqy68cpuj9a8hgfb67v&quot;,<br>197                                    &quot;locale&quot;: null<br>198                                },<br>199                                {<br>200                                    &quot;id&quot;: 18,<br>201                                    &quot;name&quot;: &quot;Example Feature 2&quot;,<br>202                                    &quot;createdAt&quot;: &quot;2023-03-10T15:46:27.207Z&quot;,<br>203                                    &quot;updatedAt&quot;: &quot;2023-03-28T15:45:18.540Z&quot;,<br>204                                    &quot;publishedAt&quot;: &quot;2023-03-10T15:46:27.565Z&quot;,<br>205                                    &quot;documentId&quot;: &quot;wxim98n316kfqy54zsmdazkp&quot;,<br>206                                    &quot;locale&quot;: null<br>207                                },<br>208                                {<br>209                                    &quot;id&quot;: 19,<br>210                                    &quot;name&quot;: &quot;Example Feature 3&quot;,<br>211                                    &quot;createdAt&quot;: &quot;2023-03-10T15:46:39.431Z&quot;,<br>212                                    &quot;updatedAt&quot;: &quot;2023-03-28T15:45:28.608Z&quot;,<br>213                                    &quot;publishedAt&quot;: &quot;2023-03-10T15:46:40.548Z&quot;,<br>214                                    &quot;documentId&quot;: &quot;v6phofjnzfn0q2i9ham968mj&quot;,<br>215                                    &quot;locale&quot;: null<br>216                                },<br>217                                {<br>218                                    &quot;id&quot;: 17,<br>219                                    &quot;name&quot;: &quot;Example Feature 4&quot;,<br>220                                    &quot;createdAt&quot;: &quot;2023-03-10T15:45:47.489Z&quot;,<br>221                                    &quot;updatedAt&quot;: &quot;2023-03-28T15:46:00.360Z&quot;,<br>222                                    &quot;publishedAt&quot;: &quot;2023-03-10T15:46:10.561Z&quot;,<br>223                                    &quot;documentId&quot;: &quot;jykjv5t5h5kqh2u649un53ss&quot;,<br>224                                    &quot;locale&quot;: null<br>225                                },<br>226                                {<br>227                                    &quot;id&quot;: 20,<br>228                                    &quot;name&quot;: &quot;Example Feature 5&quot;,<br>229                                    &quot;createdAt&quot;: &quot;2023-03-28T15:45:55.243Z&quot;,<br>230                                    &quot;updatedAt&quot;: &quot;2023-03-28T15:50:01.464Z&quot;,<br>231                                    &quot;publishedAt&quot;: &quot;2023-03-28T15:50:01.464Z&quot;,<br>232                                    &quot;documentId&quot;: &quot;vjmgoy0s7xvdgn1hlyk3wxhz&quot;,<br>233                                    &quot;locale&quot;: null<br>234                                }<br>235                            ]<br>236                        }<br>237                    ]<br>238                },<br>239                {<br>240                    &quot;__component&quot;: &quot;sections.testimonials-group&quot;,<br>241                    &quot;id&quot;: 4,<br>242                    &quot;title&quot;: &quot;Testimonials&quot;,<br>243                    &quot;description&quot;: &quot;Hello&quot;,<br>244                    &quot;testimonials&quot;: [<br>245                        {<br>246                            &quot;id&quot;: 7,<br>247                            &quot;text&quot;: &quot;ed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.&quot;,<br>248                            &quot;authorName&quot;: &quot;Paul Brats&quot;,<br>249                            &quot;picture&quot;: {<br>250                                &quot;id&quot;: 30,<br>251                                &quot;name&quot;: &quot;undraw_male_avatar_g98d.svg&quot;,<br>252                                &quot;alternativeText&quot;: null,<br>253                                &quot;caption&quot;: null,<br>254                                &quot;width&quot;: 532,<br>255                                &quot;height&quot;: 532,<br>256                                &quot;formats&quot;: null,<br>257                                &quot;hash&quot;: &quot;undraw_male_avatar_g98d_88c6a54b04&quot;,<br>258                                &quot;ext&quot;: &quot;.svg&quot;,<br>259                                &quot;mime&quot;: &quot;image/svg+xml&quot;,<br>260                                &quot;size&quot;: 3.17,<br>261                                &quot;url&quot;: &quot;/uploads/undraw_male_avatar_g98d_88c6a54b04.svg&quot;,<br>262                                &quot;previewUrl&quot;: null,<br>263                                &quot;provider&quot;: &quot;local&quot;,<br>264                                &quot;provider_metadata&quot;: null,<br>265                                &quot;createdAt&quot;: &quot;2023-03-09T18:09:14.586Z&quot;,<br>266                                &quot;updatedAt&quot;: &quot;2024-12-07T22:01:43.466Z&quot;,<br>267                                &quot;documentId&quot;: &quot;xcrtk3vtw6zy6jls5taxoex5&quot;,<br>268                                &quot;locale&quot;: null,<br>269                                &quot;publishedAt&quot;: null<br>270                            }<br>271                        },<br>272                        {<br>273                            &quot;id&quot;: 8,<br>274                            &quot;text&quot;: &quot;ed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.&quot;,<br>275                            &quot;authorName&quot;: &quot;Kit Kat&quot;,<br>276                            &quot;picture&quot;: {<br>277                                &quot;id&quot;: 32,<br>278                                &quot;name&quot;: &quot;undraw_female_avatar_efig.svg&quot;,<br>279                                &quot;alternativeText&quot;: null,<br>280                                &quot;caption&quot;: null,<br>281                                &quot;width&quot;: 532,<br>282                                &quot;height&quot;: 532,<br>283                                &quot;formats&quot;: null,<br>284                                &quot;hash&quot;: &quot;undraw_female_avatar_efig_38ecf0db0c&quot;,<br>285                                &quot;ext&quot;: &quot;.svg&quot;,<br>286                                &quot;mime&quot;: &quot;image/svg+xml&quot;,<br>287                                &quot;size&quot;: 5.01,<br>288                                &quot;url&quot;: &quot;/uploads/undraw_female_avatar_efig_38ecf0db0c.svg&quot;,<br>289                                &quot;previewUrl&quot;: null,<br>290                                &quot;provider&quot;: &quot;local&quot;,<br>291                                &quot;provider_metadata&quot;: null,<br>292                                &quot;createdAt&quot;: &quot;2023-03-09T18:10:31.630Z&quot;,<br>293                                &quot;updatedAt&quot;: &quot;2024-12-07T22:01:43.491Z&quot;,<br>294                                &quot;documentId&quot;: &quot;hn44xb0ixxzckz3nii5hgpld&quot;,<br>295                                &quot;locale&quot;: null,<br>296                                &quot;publishedAt&quot;: null<br>297                            }<br>298                        }<br>299                    ]<br>300                },<br>301                {<br>302                    &quot;__component&quot;: &quot;sections.lead-form&quot;,<br>303                    &quot;id&quot;: 4,<br>304                    &quot;title&quot;: &quot;Join our community.&quot;,<br>305                    &quot;emailPlaceholder&quot;: &quot;Enter your email&quot;,<br>306                    &quot;location&quot;: &quot;main page&quot;,<br>307                    &quot;description&quot;: &quot;Doloribus consectetur quasi ipsa quo neque culpa blanditiis ducimus recusandae a veritatis optio cumque, in harum ad nam!&quot;,<br>308                    &quot;submitButton&quot;: {<br>309                        &quot;id&quot;: 4,<br>310                        &quot;text&quot;: &quot;Submit&quot;,<br>311                        &quot;type&quot;: &quot;primary&quot;<br>312                    }<br>313                }<br>314            ],<br>315            &quot;seo&quot;: {<br>316                &quot;id&quot;: 36,<br>317                &quot;metaTitle&quot;: &quot;Home Page&quot;,<br>318                &quot;metaDescription&quot;: &quot;This is the home page&quot;,<br>319                &quot;shareImage&quot;: {<br>320                    &quot;id&quot;: 41,<br>321                    &quot;name&quot;: &quot;ai-prompt.jpg&quot;,<br>322                    &quot;alternativeText&quot;: null,<br>323                    &quot;caption&quot;: null,<br>324                    &quot;width&quot;: 5192,<br>325                    &quot;height&quot;: 3466,<br>326                    &quot;formats&quot;: {<br>327                        &quot;thumbnail&quot;: {<br>328                            &quot;name&quot;: &quot;thumbnail_ai-prompt.jpg&quot;,<br>329                            &quot;hash&quot;: &quot;thumbnail_ai_prompt_e43fe026b1&quot;,<br>330                            &quot;ext&quot;: &quot;.jpg&quot;,<br>331                            &quot;mime&quot;: &quot;image/jpeg&quot;,<br>332                            &quot;path&quot;: null,<br>333                            &quot;width&quot;: 234,<br>334                            &quot;height&quot;: 156,<br>335                            &quot;size&quot;: 8.15,<br>336                            &quot;url&quot;: &quot;/uploads/thumbnail_ai_prompt_e43fe026b1.jpg&quot;<br>337                        },<br>338                        &quot;small&quot;: {<br>339                            &quot;name&quot;: &quot;small_ai-prompt.jpg&quot;,<br>340                            &quot;hash&quot;: &quot;small_ai_prompt_e43fe026b1&quot;,<br>341                            &quot;ext&quot;: &quot;.jpg&quot;,<br>342                            &quot;mime&quot;: &quot;image/jpeg&quot;,<br>343                            &quot;path&quot;: null,<br>344                            &quot;width&quot;: 500,<br>345                            &quot;height&quot;: 334,<br>346                            &quot;size&quot;: 24.77,<br>347                            &quot;url&quot;: &quot;/uploads/small_ai_prompt_e43fe026b1.jpg&quot;<br>348                        },<br>349                        &quot;medium&quot;: {<br>350                            &quot;name&quot;: &quot;medium_ai-prompt.jpg&quot;,<br>351                            &quot;hash&quot;: &quot;medium_ai_prompt_e43fe026b1&quot;,<br>352                            &quot;ext&quot;: &quot;.jpg&quot;,<br>353                            &quot;mime&quot;: &quot;image/jpeg&quot;,<br>354                            &quot;path&quot;: null,<br>355                            &quot;width&quot;: 750,<br>356                            &quot;height&quot;: 500,<br>357                            &quot;size&quot;: 47.18,<br>358                            &quot;url&quot;: &quot;/uploads/medium_ai_prompt_e43fe026b1.jpg&quot;<br>359                        },<br>360                        &quot;large&quot;: {<br>361                            &quot;name&quot;: &quot;large_ai-prompt.jpg&quot;,<br>362                            &quot;hash&quot;: &quot;large_ai_prompt_e43fe026b1&quot;,<br>363                            &quot;ext&quot;: &quot;.jpg&quot;,<br>364                            &quot;mime&quot;: &quot;image/jpeg&quot;,<br>365                            &quot;path&quot;: null,<br>366                            &quot;width&quot;: 1000,<br>367                            &quot;height&quot;: 667,<br>368                            &quot;size&quot;: 73.64,<br>369                            &quot;url&quot;: &quot;/uploads/large_ai_prompt_e43fe026b1.jpg&quot;<br>370                        }<br>371                    },<br>372                    &quot;hash&quot;: &quot;ai_prompt_e43fe026b1&quot;,<br>373                    &quot;ext&quot;: &quot;.jpg&quot;,<br>374                    &quot;mime&quot;: &quot;image/jpeg&quot;,<br>375                    &quot;size&quot;: 2395.35,<br>376                    &quot;url&quot;: &quot;/uploads/ai_prompt_e43fe026b1.jpg&quot;,<br>377                    &quot;previewUrl&quot;: null,<br>378                    &quot;provider&quot;: &quot;local&quot;,<br>379                    &quot;provider_metadata&quot;: null,<br>380                    &quot;createdAt&quot;: &quot;2023-03-28T17:06:52.873Z&quot;,<br>381                    &quot;updatedAt&quot;: &quot;2024-12-07T22:01:45.567Z&quot;,<br>382                    &quot;documentId&quot;: &quot;uucl140hzuga3r5tmgiow2db&quot;,<br>383                    &quot;locale&quot;: null,<br>384                    &quot;publishedAt&quot;: null<br>385                }<br>386            }<br>387        }<br>388    ],<br>389    &quot;meta&quot;: {<br>390        &quot;pagination&quot;: {<br>391            &quot;page&quot;: 1,<br>392            &quot;pageSize&quot;: 25,<br>393            &quot;pageCount&quot;: 1,<br>394            &quot;total&quot;: 1<br>395        }<br>396    }<br>397}</pre><h3>Key Changes in Strapi 5 API Responses</h3><ol><li>Flattened Structure: Attributes like shortName, slug, and contentSections are now at the top level within the data object, eliminating the attributes wrapper.</li></ol><p>2. Simplified Media and Relations: Related media and entities, previously nested under additional data and attributes keys, are now directly accessible with essential fields such as id and url.</p><p>3. Introduction of documentId: A new documentId field has been added for better tracking and handling of documents in the response.</p><h3>Backward Compatibility for Migration</h3><p>Strapi 5 provides a retro-compatibility mode for developers migrating from Strapi 4. This mode allows continued use of the old response format by adding the following header to API requests:</p><pre>1    Strapi-Response-Format: v4</pre><h3>Migration Steps:</h3><ol><li>Enable Retro-Compatibility: Start by enabling the v4 response format using the header mentioned above. This prevents immediate breaking changes in your frontend.</li></ol><p>2. Update Queries and Code: Gradually update your frontend code to accommodate the new flattened format.</p><p>3. Validate Functionality: Test your application to ensure all updated queries and mutations are functioning correctly.</p><p>4. Disable Retro-Compatibility: Once the transition is complete, remove the header and fully adopt the Strapi 5 response format.</p><h3>GraphQL API Updates</h3><p>The GraphQL API has also been updated to align with the new response format. While it remains backward-compatible during migration, queries and mutations may need adjustments to match the new flattened schema.</p><h3>Why the Change Matters</h3><p>The new response format in Strapi 5 simplifies frontend development by:</p><ul><li>Reducing unnecessary nesting and improving data readability.</li><li>Enhancing performance with leaner responses.</li><li>Streamlining code required to access API data.</li></ul><p>By providing a retro-compatibility mode, Strapi ensures a smooth transition for projects migrating from version 4, allowing developers to take advantage of the improved format at their own pace.</p><h3>Strapi Design System and Admin Panel</h3><h3>Why were there so many changes to the Strapi Design System?</h3><p>The extensive changes to Strapi’s design system stem from the need to address accumulated technical debt, enhance developer experience, and prepare the system for future scalability. Here are the key reasons:</p><ol><li>Framework Agnosticism: The original design system was tightly coupled to the CMS, limiting its flexibility. Making it framework-agnostic was essential for extending its use across projects like Strapi Cloud and other potential products.</li><li>Developer Experience (DX): Minor inconveniences, such as manual rem calculations and inconsistent imports, created friction for developers. These changes simplify usage and improve the overall DX.</li><li>TypeScript Migration: Migrating the design system to TypeScript highlighted potential breaking changes. Consolidating these into a single major release minimizes ongoing disruptions.</li><li>SVG Overhaul: Hardcoded values for SVG icons caused significant issues with customization and responsiveness. The changes ensure more flexibility and consistent behavior.</li><li>Composability and Flexibility: Many components were too rigid due to overly DRY (Don’t Repeat Yourself) practices. Introducing more composability provides developers with greater freedom to adapt components to their needs.</li><li>Modernization with Dot Notation: Adopting a consistent naming pattern for components, like the dot notation used in radix-ui, creates a more intuitive API and aligns with modern best practices.</li><li>Accessibility and Documentation: Improving component testing, accessibility, and documentation ensures the design system is a first-class product that meets modern standards and user expectations.</li><li>Breaking Changes for Long-term Gains: These changes set the foundation for a more robust, scalable, and user-friendly design system. Comprehensive migration guides and tools like codemods are planned to help developers transition smoothly.</li></ol><p>In summary, the Strapi design system overhaul addresses past limitations, aligns with industry best practices, and prepares it for future scalability, even if it introduces short-term challenges for developers.</p><h3>Why can’t we modify the admin panel anymore?</h3><p>The reason it’s no longer possible to modify the admin panel with tools like patch-package is due to a change in Strapi’s build tooling, which now uses Vite and Rollup for bundling.</p><p>These tools create optimized bundles and generate file names with content-based hashes, which can change with each build. As a result, the structure of the bundled files makes it significantly harder to apply patches reliably, particularly across multiple releases.</p><p>It’s important to clarify that this wasn’t a deliberate decision to remove customization but rather a side effect of optimizing the build process. While patch-package was often used as a workaround to make modifications, it was always intended as a temporary fix rather than a sustainable customization method.</p><p>For users who need to modify the frontend, the recommended approach is to use Strapi’s documented public APIs. Additionally, users can propose new APIs or contribute to implementing them after discussing their ideas with the Strapi team to ensure they align with the project and can be merged.</p><p>However, if users still want to use patch-package at their own risk, the process is as follows:</p><ul><li>Fork Strapi and check out the tag that matches the version you want to modify.</li><li>Set it up for contributing by running yarn setup.</li><li>Make the changes you need in the source code.</li><li>Build the code by running yarn build.</li><li>Use patch-package to generate the patch on the dist folder: npx patch-package dist. Apply the patch to your application.</li></ul><p>Keep in mind that this approach requires maintaining and updating the patches for every release, and it carries risks, as it operates outside the intended customization framework.</p><h3>Developer Tools</h3><h3>Why did lifecycles become less useful?</h3><p>Lifecycles in Strapi 5 haven’t fundamentally changed — they still get triggered by database actions just as they did in Strapi 4. However, the introduction of the new Draft &amp; Publish (D&amp;P) system, Content History, and the document service has added significant complexity to data management.</p><p>In Strapi 5, a single document can now correspond to multiple database entries (e.g., drafts, historical versions, and different locales). This means that actions like publish, unpublish, or discardDraft can trigger multiple database lifecycles. For example:</p><ul><li>Publish/Unpublish: These actions result in multiple database operations, such as creating or deleting entries for each locale.</li><li>Discard Draft: This triggers both create and delete lifecycles, which did not occur in earlier versions.</li></ul><p>Because of this complexity, lifecycles written for Strapi 4 are likely to break in Strapi 5, especially for content types that utilize Draft &amp; Publish, internationalization (i18n), or other advanced features.</p><h3>Can You Still Use Lifecycles?</h3><p>While it’s technically possible to use the old lifecycles, they are only recommended for very basic content types that do not use Draft &amp; Publish, internationalization, or other features that add complexity or for parts of the Strapi application that does not use the document service (users-permissions plugin, upload package, or custom plugins).</p><p>For most cases, especially when dealing with more complex data structures, using document service middlewares is highly recommended. These provide a more reliable and powerful way to manage custom logic in Strapi 5.</p><h3>Why Use Document Service Middlewares?</h3><p>Document service middlewares offer significant advantages, including:</p><ul><li>Greater control over document-related operations.</li><li>A more predictable and stable way to implement custom logic.</li><li>Better compatibility with the Draft &amp; Publish system and internationalization features.</li><li>More agnostic programmatic API that allows for easier registration of middlewares from anywhere in the application including plugins.</li></ul><p>For these reasons, the Strapi team encourages migrating to document service middlewares, as they provide more value and better align with the architectural improvements in Strapi 5.</p><h3>Looking Ahead</h3><p>Strapi 5 is a significant step forward in enhancing the developer experience. While it introduces some breaking changes in plugin development and the change from entity service to document service, these updates are designed to make Strapi more powerful, flexible, and easier to use.</p><p>By addressing common questions, improving TypeScript support, and providing robust tools like the Plugin SDK and Document System, Strapi 5 sets the stage for future improvements and features..</p><p>Have more questions? Drop them in the comments, or check out the official Strapi documentation for more insights into the latest version!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2af2dd72622" width="1" height="1" alt=""><hr><p><a href="https://medium.com/strapi/commonly-asked-questions-transitioning-from-strapi-4-to-strapi-5-c2af2dd72622">Commonly Asked Questions: Transitioning from Strapi 4 to Strapi 5</a> was originally published in <a href="https://medium.com/strapi">Strapi</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Type-Safe Fetch with Next.js, Strapi, and OpenAPI]]></title>
            <link>https://medium.com/@theodoreonyejiaku/type-safe-fetch-with-next-js-strapi-and-openapi-7d9b976c7360?source=rss-9323ef8b74c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d9b976c7360</guid>
            <category><![CDATA[headless-cms]]></category>
            <category><![CDATA[strapi]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[open-api]]></category>
            <dc:creator><![CDATA[Theodore Kelechukwu Onyejiaku]]></dc:creator>
            <pubDate>Wed, 03 Apr 2024 19:54:20 GMT</pubDate>
            <atom:updated>2024-04-04T04:48:52.453Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3X-4Y_sGYqpeuhoBN6ZYrg.jpeg" /><figcaption>Type-safe Fetch with Next.js, Strapi and OpenAPI</figcaption></figure><p>This blog post will teach you how to achieve type safety in a front-end application used for your Strapi backend. You can accomplish this with just a few lines of code using a REST API and the fetch function.</p><p>If you like the content in a video format, feel free to check the original version on YouTube: <a href="https://youtu.be/Je5z-C9hoC8">Type-Safe Fetch with Next.js, Strapi, and OpenAPI</a>.</p><h3>Why TypeScript anyway?</h3><p><a href="https://www.typescriptlang.org/">TypeScript</a> helps you in many ways in the context of a JavaScript app. It makes it easier to consume interfaces of any type.</p><p>For example, if a component’s properties are typed, it is much more straightforward to use this component. However, when developing a react component with typed properties, you know what data you can use to implement your component.</p><p>However, TypeScript can also significantly help when interacting with external services using their APIs.</p><p>When you use technologies like <a href="https://graphql.org/">GraphQL</a>, it is trivial to derive TypeScript types. A GraphQL API is created by implementing a schema. Generating the TypeScript type definitions from this schema is simple, and you do not have to do any more work than just making the GraphQL API. This is one reason why I like GraphQL so much.</p><p>Other approaches, like tRPC (TypeScript Remote Procedure Calls), already include TypeScript in their name. When developing an API, you inherently also create its types.</p><p>However, the most commonly used APIs are still simple JSON APIs (often called REST APIs). This API, in essence, gives you a URL that then returns a “whatever” JSON object.</p><p>Working with REST API could be more pleasant when you are used to fully typed APIs. You can start logging the response, or you will have to look up documentation for this API. Since you know that the documentation and API are technically not integrated, they are “out of sync” more often than not.</p><p>However, REST APIs are still the de facto standard and most used type of API, so there is a lot of tooling around them.</p><h3>OpenAPI</h3><p>One of these is the <a href="https://www.openapis.org/">OpenAPI</a> specification. In contrast to GraphQL, you do not create a schema that is your API. You first create your API in isolation, then describe it by creating a technical specification in the OpenAPI format.</p><p>From this OpenAPI specification, you can, for example, generate UIs that help you with visual documentation and use them as a sandbox environment for the API. Essentially, it is not far from a GraphQL API with its Playgrounds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yn_Wv9X1VGphUJJ6" /><figcaption>Strapi Swagger Documentation Plugin</figcaption></figure><h3>But is REST still any good?</h3><p>The commonality of a REST API is also its most significant advantage. No web developer is likely not familiar with REST APIs. Often, it is impossible to use any super modern and fancy technology, especially in environments with older IT systems or complicated IT Governance processes.</p><p>Another considerable advantage of simple REST APIs is that they are more likely to pass the test of time. Technologies and their best practices are still changing so fast. And the more common and uncomplicated the basic building blocks are, the more likely they can be used even years from now.</p><p>GraphQL, for example. In web projects, you typically use GraphQL in conjunction with very complex client libraries like Apollo. These libraries do a lot of things, like normalizing data, maintaining state, and caching. This comes with a larger payload of JavaScript. But when things change, you might not want to use all of its capabilities anymore, and they can become harder to integrate and use with new approaches.</p><p>Right now, we, as client-heavy JavaScript developers, are moving back to the server again. With next.js server components and lots of caching mechanisms baked into the framework itself, some complexities on the client side become obsolete again. Also, next.js is extending the native fetch API, so if you rely on tools that implement their own data fetching, things get more complex.</p><h3>The Plan</h3><p>This is why I tried an uncomplicated approach that still gives you great TypeScript support and works great with your favorite headless CMS, Strapi.</p><p>Conceptually, you need to have the OpenAPI schema of your REST API, a way to generate the TypeScript type definitions from it, and a way to actually use those type definitions. Luckily, there are packages that make the whole process effortless.</p><h3>Creating the OpenAPI schema in Strapi</h3><p>Strapi offers an official plugin called @strapi/plugin-documentation (<a href="https://docs.strapi.io/dev-docs/plugins/documentation">here</a>). Install it to your existing Strapi project using:</p><pre>npm run strapi install documentation</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HvJ79r5mekMH1YUX" /><figcaption>Strapi Documentation Plugin</figcaption></figure><p>This plugin gives you two important things</p><ol><li>It automatically generates the OpenAPI specifications for your Strapi service as a JSON file.</li><li>It provides you with a Swagger UI as a visual documentation to explore and try the REST API.</li></ol><p>In the Swagger UI you can see the endpoints for the Page collection type created inside Strapi. There are endpoints to create, read, update or delete pages automatically when you create a collection type in Strapi.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-ArADOyxP_LWVpsw" /><figcaption>Page Collection Type Endpoints</figcaption></figure><p>This UI is generated from the OpenAPI schema file which you will be able to find in your project under.</p><pre>src/extensions/documentation/documentation/1.0.0/full_documentation.json</pre><p>In the OpenAPI specifications you can find all existing paths of the API:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TudrwdU2hQQQBvYX" /><figcaption>OpenAI Specification for API Paths</figcaption></figure><p>And within a path you can also find a reference to its response schema, which will be very important later on:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*0u0_TGHcwHhHTLX1" /></figure><p>When you dig deeper into the PageResponse schema you will eventually end up at the actual schema for a Page collection type:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZdlW6lfDaa1ju_Aq" /><figcaption>The <strong>PageResponse</strong> Schema</figcaption></figure><p>As you can see there are some very relevant information about the Page collection type. It is of type object, well… that’s not a surprise. It does have a property path of type string and also a property blocks that has items that can be different types. A ContentHeroComponent or a ContentImageTextComponent. And those, as you might have guessed, are Strapi components which makes your blocks property a dynamic zone, just described within your OpenAPI specs.</p><p>In Strapi, the Page looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Evck2Z90_EOuDc0Y" /><figcaption>Page Collection Type</figcaption></figure><p>So indeed, the generated OpenAPI specifications match what you defined in Strapi.</p><p>From that, you should now be able to generate the TypeScript type definitions.</p><h3>Generating TypeScript Type Definitions</h3><p>To do so, all you need is a library called <a href="https://openapi-ts.pages.dev/6.x/introduction">openapi-typescript</a>. This library takes a file with the OpenAPI specs or a URL to those and outputs your TypeScript type definitions.</p><p>Note that you want to install this in your frontend application since you will use the TypeScript type definitions there.</p><pre>npm install openapi-typescript</pre><p>Once installed, you can simply add a script to your package.json that provides the path to the generated OpenAPI specs (or URL Endpoint) and the location where to output the type definitions.</p><p>In this example, the Next.js frontend and the Strapi backend are in the same folder on the root level:</p><pre>project-root<br>        /frontend<br>        /backend</pre><p>The resulting scripts in the package.json are therefore:</p><pre>&quot;scripts&quot;: {<br>    &quot;dev&quot;: &quot;next dev&quot;,<br>    &quot;build&quot;: &quot;next build&quot;,<br>    &quot;start&quot;: &quot;next start&quot;,<br>    &quot;types:generate&quot;: &quot;openapi-typescript ../backend/src/extensions/documentation/documentation/1.0.0/full_documentation.json -o src/api/strapi.d.ts&quot;,<br>    &quot;test:ts&quot;: &quot;tsc --noEmit&quot;,<br>    &quot;lint&quot;: &quot;next lint&quot;<br>}</pre><p>Running the script is as simple as:</p><pre>// in /frontend<br>npm run types:generate</pre><p>This command creates a strapi.d.ts file containing the TypeScript type definitions from your OpenAPI specifications file.</p><p>When you look at the generated file, you find familiar things:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/0*vKeZV47_5vrcngud" /><figcaption>Type Definitions for /pages endpoint</figcaption></figure><p>The interface for all available paths is critical down the line. As you can see, the API routes exist to create, read, update or delete the /pages route.</p><p>In the interface components of the same file, you then find the type for your Page collection type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZRuYShJCxwp_NAQN" /><figcaption>Type Definitions for Page Collection Type</figcaption></figure><p>This way, you could already be using the TypeScript types for the Page content type you created in your Strapi backend. That is great already. As you can see, even the blocks in the dynamic zone from Strapi are typed, as are the types of components that were generated.</p><p>The schema for the components shows the configuration that is available in your Strapi backend.</p><p>The referenced ContentImageTextComponent looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GjBfRA0-hWVwUbjW" /><figcaption>The ContentImageTextComponent</figcaption></figure><p>From the image above, the component has attributes like text and textAlign as an enum of left or right, and more. Those are valuable types when developing the graphical representation of your backend Strapi-Component as a react component in the frontend.</p><h3>Using the Types in a React Component</h3><p>Now that you have generated the types, you can use them directly for your React components.</p><p>You can import the { components } from the generated type definitions. And then use the [“schemas”] you need. Here, you type the ImageText component and get the autocomplete for the props.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*avsL7X62GcbvCuxU" /><figcaption>Autocomplete Feature For ImageText Component</figcaption></figure><p>In order to receive the props in the first place, you still need to fetch the data. And of course you want to leverage the types for data fetching as well.</p><h3>Using Typed Fetch</h3><p>In order to use fetch in conjunction with the generated type definitions, you can use a library called <a href="https://openapi-ts.pages.dev/openapi-fetch/">openapi-fetch</a>. This library is a small wrapper around the native fetch and consumes the output of the openapi-typescript library.</p><pre>npm i openapi-fetch</pre><p>All you need to do is create the client and reference the generated types for path :</p><pre>// in src/api/index.ts<br>import createClient from &quot;openapi-fetch&quot;;<br>import type { paths } from &quot;./strapi&quot;;<br>const client = createClient&lt;paths&gt;({<br>  baseUrl: &quot;http://127.0.0.1:1337/api&quot;,<br>  headers: {<br>    Accept: &quot;application/json&quot;,<br>  },<br>});<br>export { client };// in src/api/index.ts</pre><p>Now you can use the client to do your first data-fetching. For example, on a Next.js page, you want to fetch the data of a specific page. For example, the data of a page with id = 1.</p><pre>import { client } from &quot;@/api&quot;;</pre><pre>export default async function Page() {<br>  const pageResponse = await client.GET(&quot;/pages/{id}&quot;, {<br>    params: {<br>      path: {<br>        id: 1,<br>      },<br>    },<br>  });</pre><pre>  const pageData = pageResponse.data?.data?.attributes;<br>  return &lt;pre&gt;{JSON.stringify(pageData, null, 2)}&lt;/pre&gt;;<br>}</pre><p>When using the typed fetch client, you can see all available paths in your client.GET(PATH… :</p><p>But also the response is typed automatically for you:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u6P1xvXaW9w7m84_" /><figcaption>The Client.GET(PATH…</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*X0y_JeI0_pHp6A9S" /><figcaption>Autocompletion for Response Data</figcaption></figure><p>Here you can see the autocompletion of the actual data of your Page which includes the path attribute.</p><h3>Using qs to Provide Query Strings</h3><p>You will notice that the data fetching above does not return the data of the assigned blocks. This is because the Strapi REST API requires you to specify some specific query parameters to instruct the REST API to include those relations in the response.</p><p>With libraries, query parameters can be easier to use and maintain. For example, the GET request for including fields and using population might look like this</p><pre>GET /api/articles?fields[0]=title&amp;fields[1]=slug&amp;populate[headerImage][fields][0]=name&amp;populate[headerImage][fields][1]=url</pre><p>That would mean a bit of string concatenation. Luckily Strapi suggest a library called <a href="https://github.com/ljharb/qs">qs</a> to make this a bit more streamlined:</p><pre>const qs = require(&quot;qs&quot;);<br>const query = qs.stringify(<br>  {<br>    fields: [&quot;title&quot;, &quot;slug&quot;],<br>    populate: {<br>      headerImage: {<br>        fields: [&quot;name&quot;, &quot;url&quot;],<br>      },<br>    },<br>  },<br>  {<br>    encodeValuesOnly: true, // prettify URL<br>  },<br>);</pre><pre>await request(`/api/articles?${query}`);</pre><p>Since you are using fetch not directly but openapi-fetch you do not really pass a path that includes the query string as a simple string to fetch. The syntax for query parameters is like this:</p><pre>const pages = await client.GET(&quot;/pages&quot;, {<br>  params: {<br>    query: {<br>      //..<br>    },<br>  },<br>});</pre><p>Though by default you cannot really just add the object from the Strapi examples using qs . For example, if you would want to add the qs style query to filter pages for the path / and also populate all components used in the dynamic zone field blocks , you would do the following query:</p><pre>const pages = await client.GET(&quot;/pages&quot;, {<br>  params: {<br>    query: {<br>      filters: {<br>        // @ts-ignore - openapi generated from strapi results in Record&lt;string, never&gt;<br>        // https://github.com/strapi/strapi/issues/19644<br>        path: {<br>          $eq: path,<br>        },<br>      },<br>      // @ts-ignore<br>      populate: {<br>        blocks: { populate: &quot;*&quot; },<br>      },<br>    },<br>  },<br>});</pre><blockquote><strong>Note</strong>: The <em>@ts-ignore</em> annotations are necessary right now due to the fact how the OpenAPI documentation is generated by the Strapi documentation plugin.</blockquote><p>If you do it like this you will get an error like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QE5eiDch3hS8OMjH" /><figcaption>Unhandled Runtiime Error</figcaption></figure><p>Because you cannot pass complex objects as a query to openapi-fetch out of the box, you can override the part responsible for converting the query object that is passed to the client. So what you want is for the so-called querySerializer of opanapi-fetch to use qs, and you can do so when the client gets created:</p><pre>import createClient from &quot;openapi-fetch&quot;;<br>import type { paths } from &quot;./strapi&quot;;<br>import qs from &quot;qs&quot;;<br>const client = createClient&lt;paths&gt;({<br>  baseUrl: &quot;http://127.0.0.1:1337/api&quot;,<br>  headers: {<br>    Accept: &quot;application/json&quot;,<br>  },<br>  querySerializer(params) {<br>    console.log(&quot;querySerializer&quot;, params, qs.stringify(params));<br>    return qs.stringify(params, {<br>      encodeValuesOnly: true, // prettify URL<br>    });<br>  },<br>});<br>export { client };</pre><p>And with that the query string is generated by passing the query object to qs. So with that, you can create the queries exactly as shown in the Strapi documentation itself.</p><h3>Client Side Data Fetching</h3><p>What you have seen now works great especially when you are fetching data on the server, like in <a href="https://react.dev/">React</a> Server Components using <a href="https://nextjs.org/">Next.js</a>. But data fetching on the client side is often a bit more involved. At least what you want is for example some data loading indication and to know when the data is actually available in the client.</p><p>A library that fullfills this need, but still has a small payload in terms of bundle size, is <a href="https://tanstack.com/query/latest">react-query from tanstack</a>.</p><p>We will be loading Comments, which is also a data type defined in your Strapi backend.</p><p>A simple approach could be to create a client-side react component that uses react-query to fetch the data.</p><pre>&quot;use client&quot;;<br>import { getComments } from &quot;@/api/getComments&quot;;<br>import { Headline } from &quot;@/components/elements/Headline&quot;;<br>import { useQuery } from &quot;@tanstack/react-query&quot;;<br>import React from &quot;react&quot;;<br>export interface IComments {}<br>function Comments({}: IComments) {<br>  const { isPending, data } = useQuery({<br>    queryKey: [&quot;getComments&quot;],<br>    queryFn: () =&gt; getComments(),<br>  });<br>  return (<br>    &lt;div&gt;<br>      &lt;Headline variant=&quot;h2&quot;&gt;Comments&lt;/Headline&gt;<br>      {isPending &amp;&amp; &lt;p&gt;Loading comments...&lt;/p&gt;}<br>      {data &amp;&amp;<br>        data.map((comment) =&gt; (<br>          &lt;div key={comment.id} className=&quot;my-6&quot;&gt;<br>            &lt;Headline variant=&quot;h3&quot;&gt;{comment.attributes?.username}&lt;/Headline&gt;<br>            &lt;p&gt;{comment.attributes?.comment}&lt;/p&gt;<br>          &lt;/div&gt;<br>        ))}<br>    &lt;/div&gt;<br>  );<br>}<br>export { Comments };</pre><p>In react-query, you need to pass a function to the queryFn that returns a promise. As you can see, you do not use openapi-fetch here anywhere. But still the data is all typed by the type definitions generated directly from your Strapi backend.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*otskRfiIRWF__mpX" /><figcaption>Typed Data From Strapi Backend</figcaption></figure><p>And this is simply because in the queryFn you passed to react-query, you are leveraging out typed fetch approach again.</p><pre>import { client } from &quot;.&quot;;<br>export async function getComments() {<br>  const comments = await client.GET(&quot;/comments&quot;, {<br>    cache: &quot;no-cache&quot;,<br>  });<br>  return comments?.data?.data || [];<br>}</pre><p>As you can see, you are again using the typescript-fetch client and return the typed data. And with that you have everything typed, also on the client side.</p><h3>Conclusion</h3><p>As you can see there is a way to achieve a meaningful grade of type safety or type-safe fetch with Next.js without much effort and especially without adding lots of complicated technologies and bundle size.</p><p>Using a simple fetch that leverages the generated type definitions based on the also automatically generated OpenAPI specifications from within Strapi is very little work but provides tons of values.</p><p>Not only for the data fetching part. But also for developing react components that reflect the building blocks coming from your headless CMS.</p><p>And the best thing is, that all of this is achievable in any environment where you cannot use the latest and greatest of tools available in JavaScript land.</p><h3>Resources</h3><ul><li>The source code is available on <a href="https://github.com/manuel-schoebel/strapi-next-rsc-openapi-fetch">GitHub</a>.</li><li><a href="https://www.youtube.com/watch?v=Je5z-C9hoC8&amp;feature=youtu.be">Type-Safe Fetch with Next.js, Strapi, and OpenAPI</a></li><li><a href="https://openai.com/">https://openai.com/</a></li><li><a href="https://trpc.io/">https://trpc.io/</a></li><li><a href="https://docs.strapi.io/dev-docs/api/rest/interactive-query-builder">https://docs.strapi.io/dev-docs/api/rest/interactive-query-builder</a></li></ul><h3>Connect with Manuel!</h3><p>Stay up to date with my latest tutorials on my <a href="https://www.manuel-schoebel.com/">website</a> and feel free to connect with me on <a href="https://twitter.com/Manuel_Schoebel">Twitter</a> and <a href="https://www.youtube.com/@Manuel_Schoebel">YouTube</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d9b976c7360" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>