You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB

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
})
}
},
})