]> git.r.bdr.sh - rbdr/dasein/blobdiff - app/components/login.js
Create and Show Posts (#3)
[rbdr/dasein] / app / components / login.js
diff --git a/app/components/login.js b/app/components/login.js
new file mode 100644 (file)
index 0000000..d900c72
--- /dev/null
@@ -0,0 +1,46 @@
+import Vue from 'vue';
+import AuthService from '../services/auth';
+
+const internals = {};
+
+export default internals.LoginComponent = Vue.component('login', {
+  template: '<div class="login-container">' +
+      '<p>{{message}}</p>' +
+      '</div>',
+
+  props: ['oAuthToken', 'oAuthVerifier'],
+
+  data() {
+
+    return {
+      message: 'Logging you in... Wait a sec.',
+      authService: new AuthService()
+    };
+  },
+  methods: {
+    login() {
+
+      if (this.authService.authenticated) {
+        return this.$router.push('/');
+      }
+
+      return this.authService.getUserObject(this.oAuthToken, this.oAuthVerifier).then((response) => {
+
+        console.log(response);
+
+        return this.authService.login(response.user, response.token, response.expiresAt);
+      }).then(() => {
+
+        this.$router.push('/');
+      }).catch((err) => {
+
+        console.error(err);
+        this.message = 'Oh no! There was a problem logging you in.';
+      });
+    }
+  },
+  mounted: function mounted() {
+
+    this.login();
+  }
+});