LabiciIvan / php-api-nutritional-project

A PHP API nutritional project
0 stars 0 forks source link

AuthenticationMiddleware::class - check user is authenticated #35

Open LabiciIvan opened 1 month ago

LabiciIvan commented 1 month ago

Description:

Create a new directory in the App/ with the name of Middlewares.

In the /App/Middlewares/ create a new class AuthenticationMiddleware::class

This class will be responsible to check if the given user is authenticated in the application by returning a response to the user in cases where user is not authenticated or if user is authenticated continue the action.

AuthenticationMiddleware::class will have the following capabilities and methods:

public function isAuthenticated():

Register this middleware in the App/Classes/BaseMiddleware.php file in $registeredMiddlewares array variable.

LabiciIvan commented 1 month ago

Note:

Small refactorisation and enhancement in the BaseMiddleware::class, to use DependencyInjector::class and to inject all dependencies a middleware has.

Refactored the instance of the dependencies in case of Request::class to get it from the request.php file as there is the place the request is created and by creating a new instance of the Request::class we lose important data as it is no longer pointing to initial instance of the class.