I make an online auction site and I want the user who previously had the highest bid to be able to receive a real-time notification, when another user has submitted a higher bid than his. So I want to target my user using cookies.
And I tried this:
public function returnNotification(HubInterface $hub, string $message, string $userIdd){
$userId = Uuid::fromString($userIdd);
$userIdCookie = new Cookie('user_id', $userId, 0, '/', null, true, true, false, Cookie::SAMESITE_NONE);
$update = new Update(
"https://127.0.0.1:8000/instrumenthol",
json_encode(['status' => $message]),
true,
$userIdCookie
);
$hub->publish($update);
return new Response('published!');
}
And on the client side I get the notification with:
<script>const url= new URL("https://localhost/.well-known/mercure");
urlToAppend = 'https://127.0.0.1:8000/instrumenthol';
const eventSource = new EventSource(url,{
withCredentials: true,
});
eventSource.onmessage = (e) => {
console.log(e.data);
document.getElementById("message").insertAdjacentHTML('afterend', '<div class="alert alert-success">Ping</div>');
window.setTimeout(()=>{
const alert = document.querySelector('.alert');
alert.parentNode.removeChild(alert);
}, 50000);
}
</script>
My browser recovers the cookie but refuses it, firefox displays the error in the console: GET https://localhost/.well-known/mercure [HTTP/1.1 400 Bad Request 54ms] Firefox can’t establish a connection to the server at https://localhost/.well-known/mercure. firefox error firefox error I don't know how to solve the problem, can you help me solve the problem please?