Last active
January 4, 2018 16:02
-
-
Save brw/7f7359d70a5718becd112e6b1e8d3c52 to your computer and use it in GitHub Desktop.
Authentication with Auth0 using Horizon + Vue.js test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const horizon = Horizon({authType: 'token'}) | |
new Vue({ | |
el: '#app', | |
data: { | |
authenticated: false | |
}, | |
ready() { | |
this.authenticated = horizon.hasAuthToken() | |
}, | |
methods: { | |
signIn() { | |
if (!this.authenticated) { | |
horizon.authEndpoint('auth0').subscribe((endpoint) => { | |
window.location.replace(endpoint) | |
}) | |
} | |
}, | |
logUserInfo() { | |
if (this.authenticated) { | |
horizon.currentUser().fetch().subscribe((user) => console.log(JSON.stringify(user))) | |
} | |
}, | |
signOut() { | |
Horizon.clearAuthTokens() | |
window.location.href = '/' | |
} | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> | |
<script src="/horizon/horizon.js"></script> | |
<script src="https://npmcdn.com/vue/dist/vue.min.js"></script> | |
</head> | |
<body> | |
<div id="app"> | |
<button v-on:click="signIn()" v-show="!authenticated">Sign In</button> | |
<button v-on:click="signOut()" v-show="authenticated">Sign Out</button> | |
<button v-on:click="logUserInfo()" v-show="authenticated">Log User Info</button> | |
</div> | |
<script src="./app.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment