Link to the repository
[Only for premium members]
[Only for premium members]
An API without authentication is like a house without a door. So, let's secure our API by adding an authentication system to it:
Let's get secure!
Let's start by securing our API endpoint with a Middleware:
routes/api.php
// ... Route::group(['middleware' => 'auth:sanctum'], function () { Route::apiResource('categories', CategoryController::class); Route::apiResource('transactions', TransactionController::class);});
Now, we can immediately try to make an API request using Postman:
This is good! However, we need to create a user registration and login API to authenticate our users.
So, let's create a way to register a new user. For this, we need a new Controller:
php artisan make:controller Api/AuthController
In there, let's add a new method to register a user...