NextJS recursively call API route.ts from API route.ts
I have Site, Place, and Element in my database using Planetscale.
Sites are the root, they can have Places and Elements.
Places can also have Places and Elements.
Elements are final.
The API that deletes Sites would call the API to delete Places if any, in the current Site, and call the API to delete Elements would do the same.
The Place delete API would check if there are sub-Places, and call the API for all of them, same as for Elements.
So, calling the delete API on a Site would delete all of its Places and Elements.
Calling the API on a Place do the same
Is this doable? or should I try something else?
I am getting issues with authentication when I try to fetch those APIs inside an API.
Delete functions that call the APIs:
Part of the api that deletes (try) every Place/Element:
What happens when I call these APIs is that I am unauthenticated:
Terminal from when I run it:
I hope you can point me in the right direction. Thx
Solution:Jump to solution
lmao this was dumb, I can make external function and import them wherever I need.
I made a delete.ts file where:
deleteElement deletes all related to the element, including stuff from supabase storage.
...
1 Reply
Solution
lmao this was dumb, I can make external function and import them wherever I need.
I made a delete.ts file where:
deleteElement deletes all related to the element, including stuff from supabase storage.
deletePlace deletes the place and its places and its elements, by calling itself and deleteElement.
deleteSite does the same.