Skip to content

Commit 4a2af78

Browse files
committed
added okta
1 parent 704c925 commit 4a2af78

File tree

11 files changed

+225
-51
lines changed

11 files changed

+225
-51
lines changed

package-lock.json

+101-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
"lint": "vue-cli-service lint"
99
},
1010
"dependencies": {
11+
"@okta/okta-vue": "^2.0.0",
1112
"axios": "^0.19.2",
1213
"core-js": "^3.6.5",
1314
"vue": "^2.6.11",
15+
"vue-router": "^3.2.0",
1416
"vuex": "^3.4.0"
1517
},
1618
"devDependencies": {
1719
"@vue/cli-plugin-babel": "~4.4.0",
1820
"@vue/cli-plugin-eslint": "~4.4.0",
21+
"@vue/cli-plugin-router": "^4.4.6",
1922
"@vue/cli-plugin-vuex": "^4.4.6",
2023
"@vue/cli-service": "~4.4.0",
2124
"@vue/eslint-config-airbnb": "^5.0.2",

src/App.vue

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
<template>
22
<div id="app">
3-
<img alt="Vue logo" src="./assets/logo.png">
4-
<HelloWorld msg="Welcome to Your Vue.js App"/>
3+
<div id="nav">
4+
<router-link to="/">Home</router-link> |
5+
<router-link to="/about">About</router-link>
6+
</div>
7+
<router-view/>
58
</div>
69
</template>
710

8-
<script>
9-
import HelloWorld from './components/HelloWorld.vue';
10-
11-
export default {
12-
name: 'App',
13-
components: {
14-
HelloWorld,
15-
},
16-
};
17-
</script>
18-
1911
<style>
2012
#app {
2113
font-family: Avenir, Helvetica, Arial, sans-serif;
2214
-webkit-font-smoothing: antialiased;
2315
-moz-osx-font-smoothing: grayscale;
24-
text-align: center;
2516
color: #2c3e50;
26-
margin-top: 60px;
17+
}
18+
19+
#nav {
20+
padding: 30px;
21+
}
22+
23+
#nav a {
24+
font-weight: bold;
25+
color: #2c3e50;
26+
}
27+
28+
#nav a.router-link-exact-active {
29+
color: #42b983;
2730
}
2831
</style>

src/components/HelloWorld.vue

+31-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
<template>
22
<div class="hello">
33
<div v-if="this.$httpClient.isLoadingGetPosts">Loading</div>
4-
<h1>{{ msg }}</h1>
4+
<button v-if='authenticated' v-on:click='logout' id='logout-button'> Logout </button>
5+
<button v-else v-on:click='login' id='login-button'> Login </button>
6+
<ul>
7+
<li
8+
v-for="(p, i) in posts"
9+
:key="i"
10+
>
11+
{{ p.title }}
12+
</li>
13+
</ul>
514
</div>
615
</template>
716

@@ -11,32 +20,34 @@ export default {
1120
props: {
1221
msg: String,
1322
},
23+
data() {
24+
return {
25+
authenticated: false,
26+
posts: [],
27+
};
28+
},
1429
created() {
30+
this.isAuthenticated();
1531
this.fetchData();
1632
},
1733
methods: {
34+
async isAuthenticated() {
35+
this.authenticated = await this.$auth.isAuthenticated();
36+
},
1837
async fetchData() {
1938
const { data } = await this.$httpClient.getPosts();
20-
console.log(data);
39+
this.posts = data;
40+
},
41+
login() {
42+
this.$auth.loginRedirect('/');
43+
},
44+
async logout() {
45+
await this.$auth.logout();
46+
await this.isAuthenticated();
47+
48+
// Navigate back to home
49+
this.$router.push({ path: '/' });
2150
},
2251
},
2352
};
2453
</script>
25-
26-
<!-- Add "scoped" attribute to limit CSS to this component only -->
27-
<style scoped>
28-
h3 {
29-
margin: 40px 0 0;
30-
}
31-
ul {
32-
list-style-type: none;
33-
padding: 0;
34-
}
35-
li {
36-
display: inline-block;
37-
margin: 0 10px;
38-
}
39-
a {
40-
color: #42b983;
41-
}
42-
</style>

src/main.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import Vue from 'vue';
22
import App from './App.vue';
3+
import '@/plugins/okta';
34
import '@/plugins/httpClient';
45
import store from './store';
6+
import router from './router';
57

68
Vue.config.productionTip = false;
79

810
new Vue({
911
store,
12+
router,
1013
render: (h) => h(App),
1114
}).$mount('#app');

0 commit comments

Comments
 (0)