This project has been archived. If you're curious, check out one of my latest courses:
If you work with JavaScript, check out the fetch use cases and JavaScript projects.
Thank you! — Jad Joubran
Assuming you've follwed the JWT installation steps, follow the instructions below to require authentication when accessing the api/posts
endpoint.
Replace your previous API route with one the ways below:
Route::middleware('auth:api')->get('/posts', 'PostsController@index');
//or
Route::group(['middleware' => 'auth:api'], function () {
Route::get('/posts', 'PostsController@index');
});
Voila! You will need to provide an Authorization header to be able to access this endpoint.
Make sure to follow the JWT Usage docs in order to generate tokens, check for authentication and more.