Strapi Version: 3.6.5
Operating System: Windows 10
Node Version: 14.16.1
NPM Version: 6.14.12
Yarn Version: N/A
I am trying to follow the tutorial here Is Owner - Strapi Developer Documentation
The problem I am having is that when creating a new article via the content manager, this custom controller is never called. This would only be called if a user was consuming the API to create the article. How can I set the author automatically when an article is being created in the content manager in the admin panel? I tried giving access to ctx.state.user in the lifecycle hooks but haven’t been able to figure this out. If anybody can help me I would be very appreciative. Thank you
That’s a important issue, and i would require it too.
Did you log what is coming with
Luis I think that the specific content type controller is not called when creating/updating through the admin panel. So I was never actually passing the ctx object. Only the core controller is called when using the admin panel I think, or something else is going on. I have more searching to do.
Hey @shwackd (& @LuisAlaguna),
The biggest thing to notice here is that the admin users and end users are different content-types/models and aren’t interchangeable. More about that here.
So that also means that the end-user uses the API (routes, core controllers, services and is defined under
ctx.state.user). If an entry is created/edited in the Admin panel it uses it’s own API (fom the content manager plugin). Both of the request do come in the lifecycle hooks, but they don’t have a ctx passed along
So you can’t really set automatically the author from the Admin panel because it uses it’s own API and the Admin user ID isn’t interchangeable with the End user ID (different collection types).
I hope this explains the situation/context a bit.
Thank you, this explains it very well. The workaround for me is that the editor is just going to have to select the author from a list of users. This will enable editors to say the article was authored by somebody else. It’s not perfect, but we’re a small team and I don’t think there will be a problem. I hope in the future there is some way to access the username of either admin username or end-user username in lifecycle hooks. I think this is a feature quite a few people would want.
If I’m correct it will be with the new layers in v4.
I have such problem too. But, I think the worst thing is when you can’t generate quality content. After all, the success of your blog depends on it. Fortunately, I can count on professional writers who can write my essay for me cheap uk quickly, efficiently and not expensively. Therefore, I usually commission them to write content for my online educational resource, which I try to promote. Most importantly, the articles are checked for plagiarism and are 100% unique. This allows you to increase traffic.
Curious to know if this is already implemented?