aboutsummaryrefslogtreecommitdiff
path: root/app/dasein.js
blob: 699a01f3cfa854c2cd20ea92f9417f36c587ecae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import Vue from 'vue';
import VueRouter from 'vue-router';

import AuthService from './services/auth';

import LoginComponent from './components/login';
import WelcomeComponent from './components/welcome';
import PostsComponent from './components/posts';

/* global window */

const internals = {};

export default internals.Dasein = {

  start() {

    this._setupVue();

    internals.authService = new AuthService();

    this.vm = new Vue({
      router: this._setupRouter(),
      el: '#dasein',
      methods: {
        authenticated() {

          return internals.authService.authenticated;
        }
      }
    });

  },

  // Initializes vue options

  _setupVue() {

    Vue.use(VueRouter);
  },

  // Sets up the routes

  _setupRouter() {

    const routes = [
      {
        path: '/login',
        component: WelcomeComponent
      },
      {
        path: '/',
        component: PostsComponent
      },
      {
        path: '/login-callback',
        component: LoginComponent,
        props: (route) => {

          return {
            oAuthToken: route.query.oauth_token,
            oAuthVerifier: route.query.oauth_verifier
          };
        }
      }
    ];

    const router = new VueRouter({
      mode: 'history',
      routes
    });

    return router;
  }
};


internals.run = function () {

  internals.Dasein.start();
};

window.addEventListener('load', internals.run);