'Set User as the owner of an item they created on Strapi v4. Relationships

I am creating a website which allows users to create an ad before they are registered.

I have the default User collection type and also created an Ads collection type. Ads have a relation to User as the creator of the ad. Note that when the Ad is created the user is not logged in.

Users visit the site and they start creating the ad by filling up a form with:

  • Title
  • Product Description

Then when they are done filling the ad info they are asked to register. When they click to register, the frontend calls Strapi and creates the user. Then it gets the user id and creates the ad with the user id as the 'creator'.

The problem is Strapi is not creating the relation unless I set my User 'find/findOne' function to public.

Is it possible to create the relation without making it so that people can find users through the api?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source