aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages/FetchToken.vue
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages/FetchToken.vue')
-rw-r--r--src/pages/FetchToken.vue68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/pages/FetchToken.vue b/src/pages/FetchToken.vue
new file mode 100644
index 0000000..6745377
--- /dev/null
+++ b/src/pages/FetchToken.vue
@@ -0,0 +1,68 @@
+<template>
+ <div>
+ <div v-if="!tokenValid">
+ <h6 class="text-negative">Received an invalid token!</h6>
+ <p>{{ tokenData.message }}</p>
+ </div>
+ <div v-else>
+ <h6 class="text-success">you have successfully logged in. You can close this window now!</h6>
+ </div>
+ </div>
+</template>
+
+<script>
+ import jwtDecode from 'jwt-decode'
+
+ export default {
+ components: {
+ },
+ data () {
+ return {
+ tokenValid: false,
+ }
+ },
+ computed: {
+ routeToken () {
+ return this.$route.params.token
+ },
+ tokenData () {
+ try {
+ return jwtDecode(this.routeToken)
+ }
+ catch (e) {
+ return {
+ invalid: true,
+ message: e.message
+ }
+ }
+ },
+ },
+ watch: {
+ tokenData: {
+ handler: function (val, oldVal) {
+ console.log({val, oldVal})
+ if (val !== oldVal) {
+ if (val.invalid || !val.username) {
+ this.tokenValid = false
+ }
+ else {
+ let that = this
+ this.$http.get('/uploads', {headers: {Authorization: `Bearer ${this.routeToken}`}}).then(response => {
+ that.tokenValid = true
+ that.$store.commit('user/setAuthToken', { authToken: that.routeToken })
+ window.close()
+ }).catch(error => {
+ console.warn(error)
+ that.tokenValid = false
+ })
+ }
+ }
+ },
+ immediate: true,
+ },
+ }
+ }
+</script>
+
+<style lang="styl" type="text/stylus" scoped>
+</style>