diff --git a/src/auth/index.js b/src/auth/index.js index 1935df59..2cff69d9 100644 --- a/src/auth/index.js +++ b/src/auth/index.js @@ -44,6 +44,29 @@ export default { }) }, + register (context, creds, redirect) { + HTTP.post('register', { + username: creds.username, + email: creds.email, + password: creds.password + }) + .then(response => { + // eslint-disable-next-line + console.log(response) + this.login(context, creds, redirect) + }) + .catch(e => { + // Hide the loader + context.loading = false + if (e.response) { + context.error = e.response.data.message + if (e.response.status === 401) { + context.error = 'Wrong username or password.' + } + } + }) + }, + logout () { localStorage.removeItem('token') router.push({ name: 'login' }) diff --git a/src/components/Login.vue b/src/components/user/Login.vue similarity index 90% rename from src/components/Login.vue rename to src/components/user/Login.vue index abca443a..2f05beab 100644 --- a/src/components/Login.vue +++ b/src/components/user/Login.vue @@ -18,6 +18,7 @@