From 5df221d210794c0c0488548f816b75574e52aa40 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 9 Nov 2017 14:24:59 +0100 Subject: [PATCH] made login work --- frontend/index.html | 10 ++++++-- frontend/package.json | 1 + frontend/src/auth/index.js | 17 +++++++++++-- frontend/src/components/Home.vue | 12 ++++++--- frontend/src/components/Login.vue | 41 ++++++++++++++++++++++++++++--- frontend/src/main.js | 7 ++++++ 6 files changed, 78 insertions(+), 10 deletions(-) diff --git a/frontend/index.html b/frontend/index.html index bf480c9..b3a11d3 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -1,8 +1,14 @@ - - library-frontend + + + + + + Books + +
diff --git a/frontend/package.json b/frontend/package.json index 130cb74..cc9f88a 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -13,6 +13,7 @@ "dependencies": { "axios": "^0.17.0", "vue": "^2.5.2", + "vue-awesome": "^2.3.4", "vue-resource": "^1.3.4", "vue-router": "^3.0.1" }, diff --git a/frontend/src/auth/index.js b/frontend/src/auth/index.js index 138f818..5eb8892 100644 --- a/frontend/src/auth/index.js +++ b/frontend/src/auth/index.js @@ -1,4 +1,5 @@ import {HTTP} from '../http-common' +import {router} from '../router' // const API_URL = 'http://localhost:8082/api/v1/' // const LOGIN_URL = 'http://localhost:8082/login' @@ -8,7 +9,7 @@ export default { authenticated: false }, - login (creds) { + login (context, creds, redirect) { HTTP.post('login', { username: creds.username, password: creds.password @@ -20,9 +21,21 @@ export default { // Tell others the user is autheticated this.user.authenticated = true + + // Hide the loader + context.loading = false + + // Redirect if nessecary + if (redirect) { + router.go(redirect) + } }) .catch(e => { - console.log(e) + // Hide the loader + context.loading = false + if (e.response) { + context.error = e.response.data.Message + } }) }, diff --git a/frontend/src/components/Home.vue b/frontend/src/components/Home.vue index 472c73f..5309b5d 100644 --- a/frontend/src/components/Home.vue +++ b/frontend/src/components/Home.vue @@ -1,7 +1,9 @@ @@ -13,9 +15,13 @@ export default { name: 'Home', data () { return { - msg: 'Welcome', user: auth.user } + }, + methods: { + logout () { + auth.logout() + } } } diff --git a/frontend/src/components/Login.vue b/frontend/src/components/Login.vue index 87ae58e..0335dc8 100644 --- a/frontend/src/components/Login.vue +++ b/frontend/src/components/Login.vue @@ -23,7 +23,12 @@
Login
-
+
+    + Loggig you in... +
+ +
{{ error }}
@@ -34,6 +39,7 @@ + + diff --git a/frontend/src/main.js b/frontend/src/main.js index 18e0369..4b3e86b 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -5,6 +5,13 @@ import App from './App' import router from './router' import auth from './auth' +// or import all icons if you don't care about bundle size +import 'vue-awesome/icons' +/* Register component with one of 2 methods */ +import Icon from 'vue-awesome/components/Icon' + +// globally (in your main .js file) +Vue.component('icon', Icon) // Check the user's auth status when the app starts auth.checkAuth()