@huseyinfiliz @luceos thanks for your suggestions š
I found a solution:
I'm using this SSO extension. During login, I save the flarum session token.
I use the session token + cURL on /api to fetch unreadNotificationCount
`
public function fetch_community_notification_count()
{
// š¹ Get the session token from cookies
$sessionToken = $_COOKIE['flarum_community_token'] ?? null;
if (!$sessionToken) {
return json_encode(["error" => "User is not logged in"]);
}
// š¹ API URL for fetching forum details (includes unreadNotificationCount)
$apiUrl = "{$this->communityApiBaseUrl}";
// š¹ Send cURL request with session token
$response = $this->send_curl_request($apiUrl, $sessionToken);
if (!$response) {
return json_encode(["error" => "Failed to fetch user details"]);
}
// š¹ Decode response
$forumData = json_decode($response, true);
// š¹ Check if "actor" (logged-in user) data exists
if (!isset($forumData['data']['relationships']['actor']['data']['id'])) {
return json_encode(["error" => "Failed to retrieve user ID"]);
}
$userId = $forumData['data']['relationships']['actor']['data']['id'];
// š¹ Search for user data in the "included" array
foreach ($forumData['included'] as $included) {
if ($included['type'] === 'users' && $included['id'] == $userId) {
return $included['attributes']['unreadNotificationCount'] ?? 0;
}
}
// š¹ If user not found, return 0
return 0;
}
`
Let me know your thoughts š