mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-12-07 17:49:03 +01:00
00d72866a3
Port 00d94f3ffa
to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { signOutLink } from 'flavours/glitch/utils/backend_links';
|
|
|
|
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 = document.querySelector<HTMLMetaElement>(
|
|
'meta[name=csrf-token]',
|
|
);
|
|
|
|
const csrfParam = document.querySelector<HTMLMetaElement>(
|
|
'meta[name=csrf-param]',
|
|
);
|
|
|
|
if (csrfParam && csrfToken) {
|
|
const csrfInput = document.createElement('input');
|
|
csrfInput.setAttribute('name', csrfParam.content);
|
|
csrfInput.setAttribute('value', csrfToken.content);
|
|
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();
|
|
};
|