Skip to content

Commit 80b4daf

Browse files
committed
feat: create logout method in AuthController.php and add logout endpoint
1 parent 5d6a6bb commit 80b4daf

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

app/Http/Controllers/AuthController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Illuminate\Http\JsonResponse;
1313
use Illuminate\Http\Request;
1414
use Illuminate\Support\Facades\Hash;
15+
use Illuminate\Support\Facades\Log;
1516
use Illuminate\Validation\ValidationException;
1617
use Symfony\Component\HttpFoundation\Response;
1718

@@ -73,6 +74,15 @@ public function login(LoginRequest $request): JsonResponse
7374
], Response::HTTP_OK);
7475
}
7576

77+
public function logout(Request $request): JsonResponse
78+
{
79+
$request->user()->currentAccessToken()->delete();
80+
return response()->json([
81+
'success' => true,
82+
'message' => 'Logout successful',
83+
]);
84+
}
85+
7686
public function show(User $user): UserResource
7787
{
7888
return new UserResource($this->userService->show($user));

routes/api/api.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
Route::post('login', [AuthController::class, 'login']);
3131
Route::post('register', [AuthController::class, 'register']);
32+
Route::post('logout', [AuthController::class, 'logout'])->middleware('auth:sanctum');
3233

3334
Route::get('/google/redirect', [GoogleAuthController::class, 'redirectToGoogle']);
3435
Route::get('/google/callback', [GoogleAuthController::class, 'handleGoogleCallback']);

0 commit comments

Comments
 (0)