Can I authenticate specific blog articles, not the whole content type?

Hi!

You can create a custom controller on your content type to validate whenever a request isAuthenticated and a post requires authentication.

Something like this:

  async validateAuthenticatedPost(ctx){
    await this.validateQuery(ctx);

    const { user } = ctx.state
    const { id } = ctx.params

    const article = await strapi.entityService.findOne('api::article.article', id)

    if(article.requiresAuth !== user.id){
      throw strapi.errors.forbidden()
    }
  }

This is just an example, you will have to adapt it to your needs, but basically you will only return the authenticated post if there is an authenticated user

2 Likes