Skip to content

Commit

Permalink
lint fixes. Auth service for auth0
Browse files Browse the repository at this point in the history
  • Loading branch information
Basaingeal committed Jan 5, 2019
1 parent 4a8f628 commit 2807c1b
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 34 deletions.
10 changes: 7 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<template>
<div id="app">
<div id="nav">
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link>
<router-link to="/">
Home
</router-link> |
<router-link to="/about">
About
</router-link>
</div>
<router-view/>
<router-view />
</div>
</template>

Expand Down
148 changes: 133 additions & 15 deletions src/components/HelloWorld.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,148 @@
<p>
For a guide and recipes on how to configure / customize this project,<br>
check out the
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
<a
href="https://cli.vuejs.org"
target="_blank"
rel="noopener"
>
vue-cli documentation
</a>.
</p>
<h3>Installed CLI Plugins</h3>
<ul>
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa" target="_blank" rel="noopener">pwa</a></li>
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-unit-mocha" target="_blank" rel="noopener">unit-mocha</a></li>
<li>
<a
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel"
target="_blank"
rel="noopener"
>
babel
</a>
</li>
<li>
<a
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa"
target="_blank"
rel="noopener"
>
pwa
</a>
</li>
<li>
<a
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint"
target="_blank"
rel="noopener"
>
eslint
</a>
</li>
<li>
<a
href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-unit-mocha"
target="_blank"
rel="noopener"
>
unit-mocha
</a>
</li>
</ul>
<h3>Essential Links</h3>
<ul>
<li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
<li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
<li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
<li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
<li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
<li>
<a
href="https://vuejs.org"
target="_blank"
rel="noopener"
>
Core Docs
</a>
</li>
<li>
<a
href="https://forum.vuejs.org"
target="_blank"
rel="noopener"
>
Forum
</a>
</li>
<li>
<a
href="https://chat.vuejs.org"
target="_blank"
rel="noopener"
>
Community Chat
</a>
</li>
<li>
<a
href="https://twitter.com/vuejs"
target="_blank"
rel="noopener"
>
Twitter
</a>
</li>
<li>
<a
href="https://news.vuejs.org"
target="_blank"
rel="noopener"
>
News
</a>
</li>
</ul>
<h3>Ecosystem</h3>
<ul>
<li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
<li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
<li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
<li>
<a
href="https://router.vuejs.org"
target="_blank"
rel="noopener"
>
vue-router
</a>
</li>
<li>
<a
href="https://vuex.vuejs.org"
target="_blank"
rel="noopener"
>
vuex
</a>
</li>
<li>
<a
href="https://github.com/vuejs/vue-devtools#vue-devtools"
target="_blank"
rel="noopener"
>
vue-devtools
</a>
</li>
<li>
<a
href="https://vue-loader.vuejs.org"
target="_blank"
rel="noopener"
>
vue-loader
</a>
</li>
<li>
<a
href="https://github.com/vuejs/awesome-vue"
target="_blank"
rel="noopener"
>
awesome-vue
</a>
</li>
</ul>
</div>
</template>
Expand Down
71 changes: 71 additions & 0 deletions src/services/AuthService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import auth0 from 'auth0-js'
import EventEmitter from 'eventemitter3'
import router from '../router'

const AuthService = () => ({
accessToken: null,
idToken: null,
expiresAt: null,
authenticated: this.isAuthenticated(),
authNotifier: new EventEmitter(),
auth0Client: new auth0.WebAuth({
domain: 'basaingeal.auth0.com',
clientID: 'azsRdIUydF66WsEjdQaClnrAonfBUExE',
redirectUri: 'http://localhost:3000/callback',
responseType: 'token id_token',
scope: 'openid'
}),
login () {
return this.auth0Client.authorize()
},
handleAuthentication () {
this.auth0Client.parseHash((err, authResult) => {
if (authResult && authResult.accessToken && authResult.idToken) {
this.setSession(authResult)
router.replace('home')
} else if (err) {
router.replace('home')
console.log(err)
window.alert(`Error: ${err.error}. Check the console for further details.`)
}
})
},
setSession (authResult) {
this.accessToken = authResult.accessToken
this.idToken = authResult.idToken
this.expiresAt = authResult.expiresIn * 1000 + new Date().getTime()

this.authNotifier.emit('authChange', { authenticated: true })

window.localStorage.setItem('loggedIn', true)
},
renewSession () {
this.auth0Client.checkSession({}, (err, authResult) => {
if (authResult && authResult.accessToken && authResult.idToken) {
this.setSession(authResult)
} else if (err) {
this.logout()
console.log(err)
window.alert(`Could not get a new token (${err.error}: ${err.error_description}).`)
}
})
},
logout () {
this.accessToken = null
this.idToken = null
this.expiresAt = null

this.authNotifier.emit('authChange', { authenticated: false })

window.localStorage.removeItem('loggedIn')

router.replace('home')
},
isAuthenticated () {
// Check whether the current time is past the
// access token's expiry time
return new Date().getTime() < this.expiresAt && window.localStorage.getItem('loggedIn') === 'true'
}
})

export default new AuthService()
Empty file added src/views/Callback.vue
Empty file.
9 changes: 6 additions & 3 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<template>
<div class="home">
<img alt="Vue logo" src="../assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App"/>
<img
alt="Vue logo"
src="../assets/logo.png"
>
<HelloWorld msg="Welcome to Your Vue.js App" />
</div>
</template>

Expand All @@ -10,7 +13,7 @@
import HelloWorld from '@/components/HelloWorld.vue'
export default {
name: 'home',
name: 'Home',
components: {
HelloWorld
}
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/example.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect } from 'chai'
import { shallowMount } from '@vue/test-utils'
import HelloWorld from '@/components/HelloWorld.vue'
// import { expect } from 'chai'
// import { shallowMount } from '@vue/test-utils'
// import HelloWorld from '@/components/HelloWorld.vue'

describe('HelloWorld.vue', () => {
it('renders props.msg when passed', () => {
const msg = 'new message'
const wrapper = shallowMount(HelloWorld, {
propsData: { msg }
})
expect(wrapper.text()).to.include(msg)
})
})
// describe('HelloWorld.vue', () => {
// it('renders props.msg when passed', () => {
// const msg = 'new message'
// const wrapper = shallowMount(HelloWorld, {
// propsData: { msg }
// })
// expect(wrapper.text()).to.include(msg)
// })
// })
2 changes: 1 addition & 1 deletion vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ module.exports = {
css: {
sourceMap: true
}
}
}

0 comments on commit 2807c1b

Please sign in to comment.