Auth: Save user ID instead of username in auth session
This commit is contained in:
parent
70093b1376
commit
b890432e5b
4 changed files with 22 additions and 7 deletions
|
|
@ -19,15 +19,15 @@ class UserHelper
|
|||
|
||||
public function isLoggedIn(): bool
|
||||
{
|
||||
return !empty($_SESSION['username']);
|
||||
return !empty($_SESSION['user_id']);
|
||||
}
|
||||
|
||||
public function getCurrentUser(): AdminUser
|
||||
{
|
||||
$username = $_SESSION['username'] ?? null;
|
||||
if (empty($username)) {
|
||||
$userId = $_SESSION['user_id'] ?? null;
|
||||
if (empty($userId)) {
|
||||
throw new RuntimeException('Not logged in!');
|
||||
}
|
||||
return $this->adminUserRepository->getUserByName($username);
|
||||
return $this->adminUserRepository->getUserById($userId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue