Coming from socket.io I had on the server side the following code:
socket.on("disconnect", async () => {})
When the user closes the Tap or refreshes the page.
I need to know if I can implement the same functionality, (ofc different implementation) on the server side (in the attached highlighted)
or if it is doable
do I need to create an HttpTrigger that calls the process needed in the disconnect functionality?

After digging through the issue I had finally found a solution:
<script>
window.onbeforeunload = function (e) {
const data = {
userId: localStorage.getItem("outside"),
}
console.log("looog", data);
// alert("IUIUIU")
fetch("API_URL_ENDS_THE_SESSION", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
e = e || window.event;
// // For IE and Firefox prior to version 4
if (e) {
e.returnValue = 'Sure?';
}
// // For Safari
return 'Sure?';
}