diff --git a/resources/assets/src/js/index.js b/resources/assets/src/js/index.js index bb8c2a83..3a1ab3b6 100644 --- a/resources/assets/src/js/index.js +++ b/resources/assets/src/js/index.js @@ -1,3 +1,4 @@ import './i18n'; import './net'; import './layout'; +import './logout'; diff --git a/resources/assets/src/js/logout.js b/resources/assets/src/js/logout.js new file mode 100644 index 00000000..a40de192 --- /dev/null +++ b/resources/assets/src/js/logout.js @@ -0,0 +1,25 @@ +import { post } from './net'; +import { swal } from './notify'; +import { trans } from './i18n'; + +export async function logout() { + const { dismiss } = await swal({ + text: trans('general.confirmLogout'), + type: 'warning', + showCancelButton: true, + confirmButtonText: trans('general.confirm'), + cancelButtonText: trans('general.cancel') + }); + if (dismiss) { + return; + } + + const { msg } = await post('/auth/logout'); + setTimeout(() => window.location = blessing.base_url, 1000); + swal({ + type: 'success', + html: msg + }); +} + +$('#logout-button').click(logout);