yoake/webroot/lib/auth.js
2022-11-11 17:16:53 -05:00

47 lines
1.2 KiB
JavaScript

async function getAuth() {
let body = await fetch("/api/auth/auth.json?" + new Date(), { method: "GET" })
let bodyJSON = await body.json()
return bodyJSON
}
function submitLoginForm(target, e) {
e.preventDefault()
console.log("submitLoginForm", target)
let form = $(target);
var actionUrl = form.attr('action');
$.ajax({
type: 'POST',
url: actionUrl,
data: form.serialize(),
success: function (data) {
window.location.reload();
},
error: function (data) {
try {
let msg = data.responseJSON.message || data.responseJSON;
$('#login-form-error').removeClass('d-none').find('span').text(msg);
} catch (e) {
$('#login-form-error').removeClass('d-none').find('span').text(e.message);
}
}
});
}
function signin() {
$('#login-modal').modal('show');
}
function signout() {
$.ajax({
type: 'DELETE',
url: '/api/auth/login',
success: function (data) {
window.location.reload();
},
error: function (data) {
console.warn(data)
}
});
}