import observable from '@riotjs/observable' import notificationStore from '@tiny-components/notification/src/notificationStore.js' /** * * */ export default observable({ /** * * * @param {[type]} value * */ login(value) { // only start is no request is running if (!this.requestRunning) { this.requestRunning = true fetch('/api/auth/v1', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ 'authToken': value }) }) .then((response) => { if (response.code === '200') { this.trigger('authorized') notificationStore.success('Authorized!') } else { this.trigger('unauthorized') notificationStore.danger('Not Authorized!') } this.requestRunning = false }) } }, })