-
Notifications
You must be signed in to change notification settings - Fork 0
/
argus.vue
78 lines (74 loc) · 1.91 KB
/
argus.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<script lang="ts">
import axios from 'axios'
import { storeTokens, retrieveTokens } from `./argus.js`
const REFRESH_DURATION = 3*60*1000 // 3 minntes
export default {
name: 'ArgusApp',
data() {
return {
baseURL: "",
mdr: {
url: "",
tokens: {
refresh: "",
access: "",
},
},
}
},
created() {
let urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('aristotle')) {
this.baseURL = urlParams.get('aristotle')
}
// this.mdr = {
// url: urlParams.get('aristotle'),
// }
setInterval(this.refreshTokens, REFRESH_DURATION)
this.init()
},
mounted() {
// this.name // type: string | undefined
// this.msg // type: string
// this.count // type: number
this.mdr = retrieveTokens(this.baseURL)
window.addEventListener('message', this.keysListener);
},
methods: {
keysListener: function(event) {
this.mdr = JSON.parse(event.data)
this.init()
storeTokens(this.mdr)
this.refreshTokens()
},
retrieveTokens: function (){
this.mdr = retrieveTokens()
},
init: function() {
console.log("No init method provided")
},
aristotleApi: function(api, method, data){
return axios({
method: method,
url: `${this.mdr.url}${api}`,
// url: `http://127.0.0.1:8000${api}`,
data: data,
headers: {'Authorization': `Bearer ${this.mdr.tokens.access}`}
})
},
refreshTokens: function() {
this.aristotleApi("/api/jwt/token/refresh/", "post", {"refresh": this.mdr.tokens.refresh}).then(
response => {
this.mdr.tokens.access = response.data.access
console.log(response.data.access)
console.log(response)
}
)
}
}
}
</script>
<style>
#app {
}
</style>