Skip to content

Commit 96e095d

Browse files
author
Carlos Macaneta
committed
AuthController@logout working
1 parent 9439daf commit 96e095d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

app/Http/Controllers/AuthController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Http\Requests\UserRequest;
88
use App\Models\User;
99
use Illuminate\Support\Facades\Auth;
10+
use Illuminate\Support\Facades\Cookie;
1011
use Illuminate\Support\Facades\Hash;
1112
use Symfony\Component\HttpFoundation\Response;
1213

@@ -47,4 +48,12 @@ public function user()
4748
return Auth::user();
4849
}
4950

51+
public function logout()
52+
{
53+
$cookie = Cookie::forget('jwt');
54+
55+
return response([
56+
'message' => 'Logged out successfully'
57+
])->withCookie($cookie);
58+
}
5059
}

routes/api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
Route::post('register', [AuthController::class, 'register']);
77
Route::post('login', [AuthController::class, 'login']);
8-
Route::post('logout', [AuthController::class, 'logout']);
98

109
Route::middleware('auth:sanctum')->group(function () {
1110
Route::get('user', [AuthController::class, 'user']);
11+
Route::post('logout', [AuthController::class, 'logout']);
1212
});

0 commit comments

Comments
 (0)