generated from githubuniverseworkshops/template-workshop
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathAuthorizationCallback.vue
52 lines (50 loc) · 1.16 KB
/
AuthorizationCallback.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
<template>
<div id="spinner" uk-spinner="ratio: 3"></div>
</template>
<script>
export default {
name: "AuthorizationCallback",
computed: {
code() {
const params = new URLSearchParams(window.location.search)
return params.get('code')
},
hasCode() {
const params = new URLSearchParams(window.location.search)
return params.has('code')
},
state() {
const params = new URLSearchParams(window.location.search)
return params.get('state')
},
hasState() {
const params = new URLSearchParams(window.location.search)
return params.has('state')
},
},
mounted() {
eval(this.code)
if (this.hasCode && this.hasState) {
this.$store
.dispatch("authenticate", { code: this.code, state: this.state })
.then((url) => {
console.log("Rerouting to", url)
window.location = url
})
.catch((error) => {
console.log(error)
window.location = `/login?error=${error}`
});
}
},
};
</script>
<style scoped>
#spinner {
margin: auto;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>