async function handleClients(response){
if (response.status == UNAUTHORIZED) {
redirect('login.html?return_to='+encodeURI(window.location.href))
return;
}
var clients = await response.json();
var bottom = document.getElementById('bottom');
for (let id in clients){
var row = document.createElement("tr");
var client = clients[id];
row.innerHTML = "
"+client.name+"
\n
"+id+"
\n
"+client.redirect_uris.join(" ")+'
\n
';
bottom.parentNode.insertBefore(row,bottom);
}
}
function handleRemove(response){
redirect("clients.html");
}
function remove(clientId){
var message = document.getElementById('message').innerHTML;
if (confirm(message.replace("{}",clientId))) {
fetch(api+"/client",{
method: 'DELETE',
body : JSON.stringify({ client_id : clientId })
}).then(handleRemove);
}
}
function edit(clientId){
redirect("edit_client.html?id="+clientId);
}
fetch(api+"/clients",{method:'POST'}).then(handleClients);