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

Adding Authentication

This step of the tutorial covers adding Json Web Token authentication to your project.

JWT Auth setup

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:

routes/api.php
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.

Creating tokens

Make sure to follow the JWT Usage docs in order to generate tokens, check for authentication and more.