/* eslint-disable no-console */ import loadPolyfills from '@app/common/polyfills'; import { NODE_ID } from '@app/common/constants'; import { approveDeleteMe, getUser } from '@app/common/api'; import { token } from '@app/common/settings'; import { ApiError } from './common/types'; if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } async function init(): Promise { __webpack_public_path__ = window.location.origin + '/web/'; await loadPolyfills(); const node = document.getElementById(NODE_ID); if (!node) { console.error("Remark42: Can't find root node."); return; } getUser().then(user => { if (!user || !user.admin) { handleNotAuthorizedError(node); return; } approveDeleteMe(token!).then( data => { node.innerHTML = `

User deleted successfully

${JSON.stringify(data, null, 4)}
`; }, (err: Error | ApiError | string) => { const message = err instanceof Error ? err.message : typeof err === 'object' && err !== null && err.error ? err.error : err; console.error(err); node.innerHTML = `

Something went wrong

${message}
`; } ); }); } function handleNotAuthorizedError(node: HTMLElement): void { node.innerHTML = `

You are not logged in

Sign in as admin to delete user information

`; }