Skip to content

Instantly share code, notes, and snippets.

@askz
Last active March 17, 2017 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save askz/1a7312e0aadbd58bb5e32eba4bfc1fb3 to your computer and use it in GitHub Desktop.
Save askz/1a7312e0aadbd58bb5e32eba4bfc1fb3 to your computer and use it in GitHub Desktop.
import Vue from 'vue'
import auth from '../../auth'
Vue.use(require('vue-full-calendar'))
window.jQuery = window.$ = require('jquery')
var self = this
export default {
data() {
return {
eventSources: [
{
events(start, end, timezone, callback) {
console.log(this)
this.$http.get('/events', {timezone: timezone}).then(response => {
callback(response.data.data)
})
},
color: 'blue',
textColor: 'black',
}
]
}
},
methods: {
getUsers() {
// THIS IS WORKING.
this.$http
.get('http://localhost:5000/api/v1/users', (data) => {
this.quote = data
}, {
//attach jwt header
headers: auth.getAuthHeader()
})
.error((err) => console.log(err))
}
},
route: {
// hook to check user auth status before allowing nav to route
canActivate() {
return auth.user.authenticated
}
}
}
// file used to setup main imports and configs such as routing
import Vue from 'vue'
import Home from './components/Home.vue'
import Calendar from './components/Calendar.vue'
import Signup from './components/Signup.vue'
import Login from './components/Login.vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
import axios from 'axios'
const AUTH_TOKEN = 'Bearer ' + localStorage.getItem('access_token')
Vue.prototype.$http = axios.create({
baseURL: 'http://127.0.0.1:5000',
headers: {'Authorization': AUTH_TOKEN},
responseType: 'json'
})
// Vue.prototype.$http.defaults.headers.common['Authorization'] = AUTH_TOKEN
// Vue.prototype.$http.defaults.
// Vue.use(VueResource)
Vue.config.debug = true
// check if user has jwt auth when first starting page
import auth from './auth'
//set a global auth header instead of setting at each http request
auth.checkAuth()
// // redirect all other routes to home page
// router.redirect({
// '*': '/home'
// })
const App = Vue.extend(require('./components/App.vue'))
export const router = new VueRouter({
routes: [
{path: '/home', component: Home},
{path: '/calendar', component: Calendar},
{path: '/login', component: Login},
{path: '/signup', component: Signup},
{path: '*', redirect: '/home'}
],
mode: 'hash',
linkActiveClass: 'active'
})
const app = new App({
router,
}).$mount('app')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment