]> git.r.bdr.sh - rbdr/dasein/blob - app/dasein.js
699a01f3cfa854c2cd20ea92f9417f36c587ecae
[rbdr/dasein] / app / dasein.js
1 import Vue from 'vue';
2 import VueRouter from 'vue-router';
3
4 import AuthService from './services/auth';
5
6 import LoginComponent from './components/login';
7 import WelcomeComponent from './components/welcome';
8 import PostsComponent from './components/posts';
9
10 /* global window */
11
12 const internals = {};
13
14 export default internals.Dasein = {
15
16 start() {
17
18 this._setupVue();
19
20 internals.authService = new AuthService();
21
22 this.vm = new Vue({
23 router: this._setupRouter(),
24 el: '#dasein',
25 methods: {
26 authenticated() {
27
28 return internals.authService.authenticated;
29 }
30 }
31 });
32
33 },
34
35 // Initializes vue options
36
37 _setupVue() {
38
39 Vue.use(VueRouter);
40 },
41
42 // Sets up the routes
43
44 _setupRouter() {
45
46 const routes = [
47 {
48 path: '/login',
49 component: WelcomeComponent
50 },
51 {
52 path: '/',
53 component: PostsComponent
54 },
55 {
56 path: '/login-callback',
57 component: LoginComponent,
58 props: (route) => {
59
60 return {
61 oAuthToken: route.query.oauth_token,
62 oAuthVerifier: route.query.oauth_verifier
63 };
64 }
65 }
66 ];
67
68 const router = new VueRouter({
69 mode: 'history',
70 routes
71 });
72
73 return router;
74 }
75 };
76
77
78 internals.run = function () {
79
80 internals.Dasein.start();
81 };
82
83 window.addEventListener('load', internals.run);