-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathApp.vue
119 lines (106 loc) · 2.73 KB
/
App.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<template>
<div id="app">
<div
v-if="globalLoading"
class="loading-container"
>
<KIcon
icon="spinner"
size="96"
color="var(--steel-300)"
/>
</div>
<template v-else>
<Nav v-if="isFullScreen" />
<router-view v-slot="{ Component }">
<component
:is="Component"
:class="{'page': isFullScreen }"
/>
</router-view>
</template>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import { mapState, mapActions } from 'pinia'
import { ApiServiceAuthErrorReason } from '@/services/PortalV2ApiService'
import removeElementFromDOMById from '@/helpers/removeElementFromDOMById'
import { isAuthRoute } from '@/router/route-utils'
import Nav from '@/components/Nav.vue'
import { portalApiV2 } from '@/services'
import { useAppStore } from '@/stores'
import { createRedirectHandler } from './helpers/auth'
import { useHead } from '@unhead/vue'
const initialLoadingId = 'initial-fullscreen-loading-container'
export default defineComponent({
name: 'App',
components: {
Nav
},
setup () {
const { canonicalDomain } = useAppStore()
useHead({
link: [{ rel: 'canonical', href: canonicalDomain }]
})
removeElementFromDOMById(initialLoadingId)
},
computed: {
...mapState(useAppStore, ['globalLoading']),
isFullScreen () {
return !isAuthRoute(this.$route.name) && this.$route.name !== 'not-found-redirect'
}
},
beforeMount () {
this.initializeApiClients()
},
methods: {
...mapActions(useAppStore, ['logout']),
initializeApiClients () {
// Konnect API Client
portalApiV2.setAuthErrorCallback(async (err, reason) => {
// redirect to 403 page if portal api returns HTTP 403 but the session is correct
if (reason === ApiServiceAuthErrorReason.RESPONSE_FORBIDDEN) {
this.$router.replace({ name: 'forbidden' })
return
}
if (err) {
await createRedirectHandler(this.$router, this.logout)()
}
})
}
}
})
</script>
<style lang="scss">
// Import Kongponent var overrides
@import './assets/kongponents-theme.scss';
#app {
hr {
border-color: var(--section_colors-stroke);
}
.product-version {
--KBadgeBorderRadius: 12px;
--KBadgeMinWidth: auto;
--KBadgePaddingY: 2px;
--KBadgePaddingX: var(--spacing-sm);
vertical-align: text-bottom;
}
}
</style>
<style lang="scss">
@import './assets/kongponents-theme.scss';
.loading-container {
position: fixed;
top: 0;
bottom: 0;
right: 0;
left: 0;
display: flex;
align-items: center;
justify-content: center;
z-index: 10500;
flex-direction: column;
background: var(--white)
}
</style>