From 8769fc4dc19447f67a42eb941fb43ba7223772eb Mon Sep 17 00:00:00 2001
From: Arne Schauf <git@asw.io>
Date: Sat, 3 Mar 2018 01:06:44 +0100
Subject: upgrade quasar to latest version

---
 src/pages/FetchToken.vue | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 src/pages/FetchToken.vue

(limited to 'src/pages/FetchToken.vue')

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>
-- 
cgit v1.2.3-54-g00ecf

