Last active
November 8, 2018 14:42
-
-
Save nriesco/abbfe784410bc0dabf5074b5d66a2025 to your computer and use it in GitHub Desktop.
Detecting logged users
This file contains hidden or 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
<template> | |
<div v-for="user in users" v-bind:key="item._id"> | |
{{ user.email }} | |
</div> | |
</template> | |
<script> | |
import { mapActions } from 'vuex' | |
const REDIRECT_PATH = '/some/url/to/login'; | |
export default { | |
name: 'login-example', | |
data () { | |
return { | |
users: [] | |
} | |
}, | |
mounted: function () { | |
this.loadItems() | |
}, | |
methods: { | |
...mapActions('users', { | |
findItems: 'find' | |
}), | |
loadItems () { | |
this.findItems({}) | |
.then(res => { | |
if (res.data.length) { | |
this.items = res.data | |
} else { | |
this.$router.push({ path: REDIRECT_PATH }) | |
} | |
}) | |
.catch(() => { | |
this.$router.push({ path: REDIRECT_PATH }) | |
}) | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment