]> git.r.bdr.sh - rbdr/dasein/blob - app/components/login.js
Create and Show Posts (#3)
[rbdr/dasein] / app / components / login.js
1 import Vue from 'vue';
2 import AuthService from '../services/auth';
3
4 const internals = {};
5
6 export default internals.LoginComponent = Vue.component('login', {
7 template: '<div class="login-container">' +
8 '<p>{{message}}</p>' +
9 '</div>',
10
11 props: ['oAuthToken', 'oAuthVerifier'],
12
13 data() {
14
15 return {
16 message: 'Logging you in... Wait a sec.',
17 authService: new AuthService()
18 };
19 },
20 methods: {
21 login() {
22
23 if (this.authService.authenticated) {
24 return this.$router.push('/');
25 }
26
27 return this.authService.getUserObject(this.oAuthToken, this.oAuthVerifier).then((response) => {
28
29 console.log(response);
30
31 return this.authService.login(response.user, response.token, response.expiresAt);
32 }).then(() => {
33
34 this.$router.push('/');
35 }).catch((err) => {
36
37 console.error(err);
38 this.message = 'Oh no! There was a problem logging you in.';
39 });
40 }
41 },
42 mounted: function mounted() {
43
44 this.login();
45 }
46 });