Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save gdbate/92a35c14470987d3a6a49dc9b291f82f to your computer and use it in GitHub Desktop.

Select an option

Save gdbate/92a35c14470987d3a6a49dc9b291f82f to your computer and use it in GitHub Desktop.
Vue: Customizing Amplify Authentication - Handling Authentication Changes
{
watch: {
'$store.state.account.authorized': async function(n, o){
if(n, o){
//logic for user logging in
await this.$api('user', 'signin') //example for logging in user to server
if(this.$route.path !== '/' || !o)
this.$router.push('/')
}else{
//logic for user logging out
if(this.$route.path !== '/')
this.$router.push('/')
}
},
},
// attempt to login user from session
async created(){
await store.dispatch('account/fetchUser')
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment