let m = require('mithril') var user = { current: {}, login: function() { return m.request({ method: 'POST', url: '/login', data: user.current, withCredentials: true, headers: {client: 'api'} }) .then(function(response) { if (response.status == true) { window.location = response.redirect_to } else { console.log(response.status); } }) }, logout: function() { return m.request({ method: 'GET', url: '/logout', withCredentials: true, headers: {client: 'api', 'x-query': window.location.search} }) .then(function(response) { console.log(response); if (response.status) { window.location = response.redirect_to } }) }, register: function() { return m.request({ method: 'POST', url: '/post', data: user.current, withCredentials: true, headers: {client: 'api', 'x-query': window.location.search} }) .then(function(response) { if (response.status == true) { m.route.set(response.route_to) } else { console.log(response); } }) } } module.exports = user