2020-03-22 15:10:44 +00:00
|
|
|
import Rails from '@rails/ujs';
|
2023-05-28 14:38:10 +00:00
|
|
|
|
2022-10-11 08:41:15 +00:00
|
|
|
import { signOutLink } from 'flavours/glitch/utils/backend_links';
|
2019-08-26 16:24:10 +00:00
|
|
|
|
|
|
|
export const logOut = () => {
|
|
|
|
const form = document.createElement('form');
|
|
|
|
|
|
|
|
const methodInput = document.createElement('input');
|
|
|
|
methodInput.setAttribute('name', '_method');
|
|
|
|
methodInput.setAttribute('value', 'delete');
|
|
|
|
methodInput.setAttribute('type', 'hidden');
|
|
|
|
form.appendChild(methodInput);
|
|
|
|
|
|
|
|
const csrfToken = Rails.csrfToken();
|
|
|
|
const csrfParam = Rails.csrfParam();
|
|
|
|
|
|
|
|
if (csrfParam && csrfToken) {
|
|
|
|
const csrfInput = document.createElement('input');
|
|
|
|
csrfInput.setAttribute('name', csrfParam);
|
|
|
|
csrfInput.setAttribute('value', csrfToken);
|
|
|
|
csrfInput.setAttribute('type', 'hidden');
|
|
|
|
form.appendChild(csrfInput);
|
|
|
|
}
|
|
|
|
|
|
|
|
const submitButton = document.createElement('input');
|
|
|
|
submitButton.setAttribute('type', 'submit');
|
|
|
|
form.appendChild(submitButton);
|
|
|
|
|
|
|
|
form.method = 'post';
|
|
|
|
form.action = signOutLink;
|
|
|
|
form.style.display = 'none';
|
|
|
|
|
|
|
|
document.body.appendChild(form);
|
|
|
|
submitButton.click();
|
|
|
|
};
|