X-Git-Url: https://git.r.bdr.sh/rbdr/dasein/blobdiff_plain/287fa13b3e600b2340895a5463a288bf08101bb5..a6ccda0fbc4df683f9568d85eb22b21684d2a0bd:/app/components/login.js diff --git a/app/components/login.js b/app/components/login.js new file mode 100644 index 0000000..d900c72 --- /dev/null +++ b/app/components/login.js @@ -0,0 +1,46 @@ +import Vue from 'vue'; +import AuthService from '../services/auth'; + +const internals = {}; + +export default internals.LoginComponent = Vue.component('login', { + template: '
' + + '

{{message}}

' + + '
', + + 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(); + } +});