I have a Laravel 10 project that has both the front end and the back end within the same project.
This website renders information from a database. Everything works as expected.
I have two route files web.php and api.php
I have the following API route: https://example.com/api/product/1
This is an example of the output from that route:
{"id":1,"name":"name","description":"hello world"}
I have other routes that return much more complex data.
I need access to the API routes from inside my application. I have some internal react components that use axios to retrieve the data. This part works fine.
What I am trying to do is to "secure" the API route so that it cannot be accessed from outside my Laravel application. Therefore, if the request is coming from my blade views or my react app then the server will return the data. However, if someone types the API address on the browser I want it to throw an error (not authorized).
Update: I am using Laravel Sanctum for auth, however, I am not looking to make API requests accessible to users with an authorized token.
I want the data to be controlled by the view, I don't want users to easily access the API, copy the data and take everything away with one click.
What is the best approach to designing such a system like this?