fix auth
This commit is contained in:
+31
-13
@@ -25,20 +25,25 @@ readonly class AuthService
|
||||
|
||||
public function currentUserId(): ?string
|
||||
{
|
||||
|
||||
if (app()->runningInConsole()) {
|
||||
return config("lucent.systemUserId");
|
||||
} elseif(request()->segment(1) !== "lucent") {
|
||||
return config("lucent.systemUserId");
|
||||
} else {
|
||||
return $this->session->get("user.id") || config("lucent.systemUserId");
|
||||
return $this->session->get("user.id");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function currentUserRoles(): array
|
||||
public
|
||||
function currentUserRoles(): array
|
||||
{
|
||||
return $this->session->get("user.roles") ?? [];
|
||||
}
|
||||
|
||||
public function isLoggedIn(): bool
|
||||
public
|
||||
function isLoggedIn(): bool
|
||||
{
|
||||
return !empty($this->currentUserId());
|
||||
}
|
||||
@@ -46,7 +51,8 @@ readonly class AuthService
|
||||
/**
|
||||
* @throws LucentException
|
||||
*/
|
||||
public function login(string $email, string $token): void
|
||||
public
|
||||
function login(string $email, string $token): void
|
||||
{
|
||||
|
||||
$user = $this->userRepo->findByEmail(new Email($email));
|
||||
@@ -74,7 +80,11 @@ readonly class AuthService
|
||||
$this->session->put(["user" => $user->get()->safe()]);
|
||||
}
|
||||
|
||||
public function refreshSession(){
|
||||
public
|
||||
function refreshSession()
|
||||
{
|
||||
|
||||
|
||||
$user = $this->userRepo->findById($this->currentUserId());
|
||||
|
||||
if ($user->isEmpty()) {
|
||||
@@ -90,7 +100,8 @@ readonly class AuthService
|
||||
}
|
||||
|
||||
|
||||
public function create(string $name, string $email, array $roles): User
|
||||
public
|
||||
function create(string $name, string $email, array $roles): User
|
||||
{
|
||||
$user = new User(
|
||||
id: (string)Str::uuid(),
|
||||
@@ -111,7 +122,8 @@ readonly class AuthService
|
||||
/**
|
||||
* @throws LucentException
|
||||
*/
|
||||
public function sendLoginEmail(string $email): void
|
||||
public
|
||||
function sendLoginEmail(string $email): void
|
||||
{
|
||||
$emailAddress = (new Email($email));
|
||||
$user = $this->userRepo->findByEmail($emailAddress);
|
||||
@@ -140,7 +152,8 @@ readonly class AuthService
|
||||
/**
|
||||
* @throws LucentException
|
||||
*/
|
||||
public function changeRoles(string $userId, array $roles): void
|
||||
public
|
||||
function changeRoles(string $userId, array $roles): void
|
||||
{
|
||||
$user = $this->userRepo->findById($userId);
|
||||
|
||||
@@ -157,7 +170,8 @@ readonly class AuthService
|
||||
/**
|
||||
* @throws LucentException
|
||||
*/
|
||||
public function updateName(string $name): void
|
||||
public
|
||||
function updateName(string $name): void
|
||||
{
|
||||
$name = (new Name($name));
|
||||
$this->userRepo->updateName($this->currentUserId(), $name);
|
||||
@@ -168,7 +182,8 @@ readonly class AuthService
|
||||
/**
|
||||
* @throws LucentException
|
||||
*/
|
||||
public function updateEmail(string $email): void
|
||||
public
|
||||
function updateEmail(string $email): void
|
||||
{
|
||||
$email = (new Email($email));
|
||||
$user = $this->userRepo->findByEmail($email);
|
||||
@@ -185,7 +200,8 @@ readonly class AuthService
|
||||
/**
|
||||
* @throws LucentException
|
||||
*/
|
||||
public function invite(
|
||||
public
|
||||
function invite(
|
||||
string $name,
|
||||
string $email,
|
||||
array $roles
|
||||
@@ -199,7 +215,8 @@ readonly class AuthService
|
||||
/**
|
||||
* @throws LucentException
|
||||
*/
|
||||
public function registerAdmin(
|
||||
public
|
||||
function registerAdmin(
|
||||
string $name,
|
||||
string $email
|
||||
): User
|
||||
@@ -209,7 +226,8 @@ readonly class AuthService
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function validateRoles(array $roles): array
|
||||
public
|
||||
function validateRoles(array $roles): array
|
||||
{
|
||||
return collect($roles)
|
||||
->filter(fn(string $role) => in_array($role, $this->channelService->channel->roles))
|
||||
|
||||
Reference in New Issue
Block a user