X-Git-Url: https://git.r.bdr.sh/rbdr/dasein/blobdiff_plain/7eb26514c478cfa06a797e9d63a29ef6a6d16d59..a3f9e2603dfdf8c492ec0dc355cd434fc6100f06:/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(); + } +});