fix: login sessions
This commit is contained in:
parent
dc91d0ab8c
commit
cf46450f5f
11 changed files with 179 additions and 27 deletions
|
@ -288,7 +288,7 @@
|
|||
`/rooms/${room_id}/events?type=chat&limit=100&sort=newest`,
|
||||
);
|
||||
if (!events_response.ok) {
|
||||
const error = await room_response.json();
|
||||
const error = await events_response.json();
|
||||
alert(error.message ?? JSON.stringify(error));
|
||||
return;
|
||||
}
|
||||
|
@ -327,6 +327,11 @@
|
|||
window.addEventListener("locationchange", update_chat_rooms);
|
||||
|
||||
function check_for_room_in_url() {
|
||||
const user_json = document.body.dataset.user;
|
||||
if (!user_json) {
|
||||
return;
|
||||
}
|
||||
|
||||
const hash = window.location.hash;
|
||||
const talk_in_url = hash.indexOf("#/talk") === 0;
|
||||
if (!talk_in_url) {
|
||||
|
@ -503,16 +508,6 @@
|
|||
`<li id="room-selector-${new_room.id}" class="room"><a href="#/room/${new_room.id}">${new_room.name}</a></li>`,
|
||||
);
|
||||
|
||||
const room_selectors = document.querySelectorAll("li.room");
|
||||
for (const room_selector of room_selectors) {
|
||||
room_selector.classList.remove("active");
|
||||
}
|
||||
|
||||
const new_room_selector = document.getElementById(
|
||||
`room-selector-${new_room.id}`,
|
||||
);
|
||||
new_room_selector.classList.add("active");
|
||||
|
||||
window.location.hash = `/talk/room/${new_room.id}`;
|
||||
});
|
||||
});
|
||||
|
|
|
@ -53,5 +53,24 @@
|
|||
<div class="username-container">
|
||||
<span class="username" data-bind-user_username></span>
|
||||
</div>
|
||||
|
||||
<form data-smart="true" action="/api/auth" method="DELETE">
|
||||
<script>
|
||||
{
|
||||
const form = document.currentScript.closest("form");
|
||||
form.on_response = (response) => {
|
||||
if (!response.ok) {
|
||||
alert("error logging out!");
|
||||
return;
|
||||
}
|
||||
|
||||
delete document.body.dataset.user;
|
||||
delete document.body.dataset.perms;
|
||||
window.location = "/";
|
||||
};
|
||||
}
|
||||
</script>
|
||||
<button class="primary">Log Out</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue