mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
check session
This commit is contained in:
@@ -382,17 +382,35 @@ function router(Http $utopia, Database $dbForPlatform, callable $getProjectDB, S
|
||||
// isExecutionAllowed remains false
|
||||
}
|
||||
|
||||
$userExists = false;
|
||||
$userId = $payload['userId'] ?? '';
|
||||
if (!empty($userId)) {
|
||||
/** @var \Appwrite\Utopia\Database\Documents\User */
|
||||
$user = $authorization->skip(fn () => $dbForProject->getDocument('users', $userId));
|
||||
if (!$user->isEmpty() && $user->getAttribute('status', false)) {
|
||||
foreach ($user->getRoles($authorization) as $role) {
|
||||
$authorization->addRole($role);
|
||||
}
|
||||
$isExecutionAllowed = $authorization->isValid(new Input('execute', $permissions));
|
||||
$userExists = true;
|
||||
}
|
||||
}
|
||||
|
||||
$sessionExists = false;
|
||||
$jwtSessionId = $payload['sessionId'] ?? '';
|
||||
if (!empty($jwtSessionId) && isset($user)) {
|
||||
$sessionExists = !empty($user->find('$id', $jwtSessionId, 'sessions'));
|
||||
}
|
||||
|
||||
$membershipExists = false;
|
||||
$project = $authorization->skip(fn () => $dbForPlatform->getDocument('projects', $projectId));
|
||||
if (!$project->isEmpty() && isset($user)) {
|
||||
$teamId = $project->getAttribute('teamId', '');
|
||||
$membershipExists = !empty($user->find('teamId', $teamId, 'memberships'));
|
||||
}
|
||||
|
||||
if ($userExists && $sessionExists && $membershipExists) {
|
||||
foreach ($user->getRoles($authorization) as $role) {
|
||||
$authorization->addRole((string) $role);
|
||||
}
|
||||
$isExecutionAllowed = $authorization->isValid(new Input('execute', $permissions));
|
||||
}
|
||||
}
|
||||
|
||||
if (!$isExecutionAllowed) {
|
||||
|
||||
Reference in New Issue
Block a user