/* eslint-disable no-console */ import { NODE_ID, BASE_URL } from 'common/constants'; import { approveDeleteMe, getUser } from 'common/api'; import { token } from 'common/settings'; if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } function init() { const node = document.getElementById(NODE_ID); if (!node) { console.error("Remark42: Can't find root node."); return; } getUser() .then(user => { if (!user.admin) { handleNotAuthorizedError(node); return; } approveDeleteMe(token).then( data => (node.innerHTML = `

User deleted successfully

${JSON.stringify(data, null, 4)}
`), err => (node.innerHTML = `

Something went wrong

${err}
`) ); }) .catch(() => handleNotAuthorizedError(node)); } function handleNotAuthorizedError(node) { node.innerHTML = `

You are not logged in

Sign in as admin to delete user information

`; }