From ea3e503d13b7be477c064b02b9b2e5a9ef06c9a9 Mon Sep 17 00:00:00 2001
From: Pitu <heyitspitu@gmail.com>
Date: Fri, 29 Mar 2019 00:35:58 +0900
Subject: Added middleware for pages and switched to $axios

---
 src/site/pages/register.vue | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

(limited to 'src/site/pages/register.vue')

diff --git a/src/site/pages/register.vue b/src/site/pages/register.vue
index 9b882d6..bb17298 100644
--- a/src/site/pages/register.vue
+++ b/src/site/pages/register.vue
@@ -72,24 +72,26 @@ export default {
 		return { title: 'Register' };
 	},
 	methods: {
-		register() {
+		async register() {
 			if (this.isLoading) return;
 			if (this.password !== this.rePassword) {
 				this.$showToast('Passwords don\'t match', true);
 				return;
 			}
 			this.isLoading = true;
-			this.axios.post(`${this.config.baseURL}/auth/register`, {
-				username: this.username,
-				password: this.password
-			}).then(response => {
-				this.$showToast(response.data.message);
-				this.isLoading = false;
+
+			try {
+				const response = await this.$axios.$post(`auth/register`, {
+					username: this.username,
+					password: this.password
+				});
+				this.$showToast(response.message);
 				return this.$router.push('/login');
-			}).catch(err => {
+			} catch (error) {
+				this.$onPromiseError(error);
+			} finally {
 				this.isLoading = false;
-				this.$onPromiseError(err);
-			});
+			}
 		}
 	}
 };
-- 
cgit v1.2.3

