mirror of
https://github.com/funamitech/mastodon
synced 2024-11-24 23:26:42 +09:00
fd3d45d38f
* [WiP] Add a confirmation modal before logging out from the web interface * Add confirmation to logout link in getting started footer * Please CodeClimate
34 lines
974 B
JavaScript
34 lines
974 B
JavaScript
import Rails from 'rails-ujs';
|
|
|
|
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 = '/auth/sign_out';
|
|
form.style.display = 'none';
|
|
|
|
document.body.appendChild(form);
|
|
submitButton.click();
|
|
};
|