Skip to content

Commit

Permalink
feat: completed logout, and another fucking controller
Browse files Browse the repository at this point in the history
Signed-off-by: Hanif Dwy Putra S <[email protected]>
  • Loading branch information
hansputera committed Apr 15, 2023
1 parent 8f2f689 commit 0f151fa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
15 changes: 15 additions & 0 deletions app/Http/Controllers/Api/Auth/LogoutController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace App\Http\Controllers\Api\Auth;
use App\Http\Controllers\ApiController;

class LogoutController extends ApiController {
public function logout()
{
auth()->logout();

return response()->json([
'data' => ['_' => 'OK'],
]);
}
}
?>
13 changes: 13 additions & 0 deletions app/Http/Controllers/Api/Auth/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Api\Auth;

use App\Http\Controllers\ApiController;
use Carbon\Carbon;
use Illuminate\Http\Request;

class ProfileController extends ApiController
Expand All @@ -14,4 +15,16 @@ public function self(Request $request)
'data' => $u,
], isset($u) ? 200 : 401);
}

public function refresh()
{
$new_token = auth()->refresh(true);

return response()->json([
'data' => [
'token' => $new_token,
'expires_at' => Carbon::now(config('APP_TIMEZONE'))->timestamp + auth()->factory()->getTTL() * 60,
],
]);
}
}
8 changes: 7 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

use App\Http\Controllers\Api\Auth\LoginController;
use App\Http\Controllers\Api\Auth\LogoutController;
use App\Http\Controllers\Api\Auth\ProfileController;
use App\Http\Controllers\Api\Auth\RegisterController;
use App\Http\Controllers\Api\Users\DeleteUserController;
use App\Http\Controllers\Api\Users\ShowUserController;
use App\Http\Middleware\JwtLogged;
use App\Http\Middleware\OnlyActiveUser;
use App\Http\Middleware\OnlyFAUser;
use Illuminate\Support\Facades\Route;

Expand All @@ -31,9 +31,15 @@
OnlyFAUser::class,
]);
Route::post('login', [LoginController::class, 'login'])->middleware('guest');
Route::get('logout', [LogoutController::class, 'logout'])->middleware([
JwtLogged:: class,
]);
Route::get('profile', [ProfileController::class, 'self'])->middleware([
JwtLogged::class,
]);
Route::post('refresh', [ProfileController::class, 'refresh'])->middleware([
JwtLogged::class,
]);
});

// /api/users
Expand Down

0 comments on commit 0f151fa

Please sign in to comment.