Skip to content

Instantly share code, notes, and snippets.

@acacha
Created October 10, 2016 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acacha/98a8f580e213d6a2c947af32d3985865 to your computer and use it in GitHub Desktop.
Save acacha/98a8f580e213d6a2c947af32d3985865 to your computer and use it in GitHub Desktop.
<div id="app">
<div v-if="userId">
<p>You are logged in! Your user ID is: {{userId}}</p>
<p>Click <a @click="logout">here</a> to logout</p>
</div>
<div v-if="!userId">
<p>I don't know you. You should <a @click="login">login</a>.</p>
</div>
</div>
<script>
const horizon = Horizon();
let app = new Vue({
el: "#app",
data: {userId: null},
ready() {
if (horizon.hasAuthToken())
horizon.currentUser().fetch().subscribe(user => this.userId = user.id);
},
methods: {
login(ev) {
horizon.authEndpoint("github").subscribe(endpoint =>
window.location.replace(endpoint);
},
logout(ev) {
Horizon.clearAuthTokens();
}
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment