feat: Implement JWT authentication for client API and add transaction verification endpoint.
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Services\Api\Client;
|
||||
use App\Repositories\Api\Client\ClientRepositoryInterface;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Tymon\JWTAuth\Facades\JWTAuth;
|
||||
|
||||
class ClientAuthService
|
||||
{
|
||||
@@ -20,14 +21,13 @@ class ClientAuthService
|
||||
*/
|
||||
public function authenticateClient(array $credentials): array
|
||||
{
|
||||
if (!Auth::guard('client')->attempt($credentials)) {
|
||||
if (!$token = Auth::guard('client')->attempt($credentials)) {
|
||||
throw ValidationException::withMessages([
|
||||
'email' => ['Thông tin đăng nhập không chính xác.'],
|
||||
]);
|
||||
}
|
||||
|
||||
$client = Auth::guard('client')->user();
|
||||
$token = $client->createToken('client-token')->plainTextToken;
|
||||
|
||||
return [
|
||||
'client' => $client,
|
||||
@@ -47,7 +47,7 @@ class ClientAuthService
|
||||
'password' => bcrypt($data['password']),
|
||||
]);
|
||||
|
||||
$token = $client->createToken('client-token')->plainTextToken;
|
||||
$token = JWTAuth::fromUser($client);
|
||||
|
||||
return [
|
||||
'client' => $client,
|
||||
|
||||
Reference in New Issue
Block a user