How to Create a Blog with SvelteKit & Strapi

Ah, I needed to add to __layout.svelte - this is why you refer to the docs and other intro tutorials :slight_smile:

Yeah, I’m facing the same issue too. I will test out the Next-Strapi template blog and see how it’s implemented

Yep I’m struggling with this now as well.

One way to get around it is to change the users-permission’s settings in the users & permissions plugin, and tick find and findOne; but unfortunately this exposes all user details in the API which really doesn’t seem wise.

But yes for some reason, the author field is not appearing in the posts JSON.

1 Like

Found the same problem when I tested the strapi-next template blog Strapi Next.js Blog Starter. The author name doesn’t appear.

Here’s the json for the api request

{
    "data": {
        "id": 1,
        "attributes": {
            "title": "What's inside a Black Hole",
            "description": "Maybe the answer is in this article, or not...",
            "content": "Well, we don't know yet...",
            "slug": "what-s-inside-a-black-hole",
            "createdAt": "2022-06-30T08:27:20.671Z",
            "updatedAt": "2022-06-30T08:27:20.671Z",
            "publishedAt": "2022-06-30T08:27:20.305Z"
        }
    },
    "meta": {}
}
1 Like

Following this tutorial I found a problem with this step:
“Like the post routes, Strapi doesn’t, by default, allow anyone to access this route either. So, let’s edit permissions like how we did earlier for the Authenticated role.” .
So, I thought to follow the same process of the post step as wrote, that means go to Settings → Role → Authenticated and find the new Auth section to enable the /auth/me API. But I couldn’t find any Auth section so I couldn’t enable any API.

I googled “add custom api strapi” and I found this tutorial, from Strapi: How to Create a Custom API Endpoint in Strapi . Following this tutorial, with the apposite code, I was able to enable the /auth/me API correctly.

Hope this can help somebody and thank you for the content.

For those who struggling with getting author username from rest api →

  1. First of all you should set in Settings → User and Permissions Plugin → Roles → Public ( Edit ) → User-permissions → User ( set find and findOne )
  2. Fetch should be like http://localhost:1337/api/posts/4?fields[0]=*&populate[author][fields][0]=username

End of course this tutorial is quite outdated, because routing in sveltekit changed in September 2022

End of course this tutorial is quite outdated, because routing in sveltekit changed in September 2022

Before reading an article, I always try to read comments like yours - such comments immediately put me out of my misery, allowing me not to step on the same rake again. Thank you for that comment :+1: If it doesn’t take much of your time, could you please correct the article. If you can, would you be so kind as to do a good deed for young people :pray: