$authGuard = new AuthGuard(); if ($authGuard->login($_POST['username'], $_POST['password'])) { // User is authenticated, continue with app logic } else { // Authentication failed, display error message }
$authGuard = new AuthGuard(); $token = $authGuard->createToken(['user_id' => $currentUser->id]); // Send token to client-side for further requestsIn this example, the AuthGuard library automatically generates a JWT token using the user's ID as the payload. The token can be sent to the client-side and used to authenticate subsequent requests. The PHP Auth Guard package can be found on Packagist (https://packagist.org/packages/php-auth-guard/auth-guard) and can be installed using Composer.