-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.vue
More file actions
71 lines (66 loc) · 1.43 KB
/
App.vue
File metadata and controls
71 lines (66 loc) · 1.43 KB
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
<template>
<div class="app">
<img alt="Vue logo" src="./assets/logo.png">
<HexaEightAuth :clientId="clientid" :tokenServerUrl="token_server_url" @authenticated="updateAuthenticationStatus" ref="hexaeightauth">
<router-view :hexaEightAuth="hexaEightAuth">
</router-view>
</HexaEightAuth>
</div>
</template>
<script>
import HexaEightAuth from './components/HexaEight.vue'
import { useRouter } from 'vue-router'
const app = {
data() {
return {
clientid: "<ClientID>",
token_server_url: "<TokenServerURL>",
isAuthenticated: false,
hexaEightAuth: undefined,
};
},
created() {
const self = this; // Store a reference to the Vue instance
const router = useRouter()
router.beforeEach((to, from, next) => {
if (to.meta.requiresAuth) {
if (self.$refs.hexaeightauth.authState === true) {
next()
} else {
next('/')
}
} else {
next()
}
});
},
methods: {
updateAuthenticationStatus(status) {
this.isAuthenticated = status;
if (status === true) {
this.hexaEightAuth = this.$refs.hexaeightauth.hexaeightSession;
this.$router.push('/profile');
}
}
}
}
export default {
name: 'App',
components: { HexaEightAuth },
data() {
return {
...app.data()
}
},
...app
}
</script>
<style>
#app {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
height: 100vh;
}
</style>