Skip to content

Instantly share code, notes, and snippets.

@brunokunace
Created March 7, 2019 21:23
Show Gist options
  • Save brunokunace/81a44f284ec511f8ed9201e83607829b to your computer and use it in GitHub Desktop.
Save brunokunace/81a44f284ec511f8ed9201e83607829b to your computer and use it in GitHub Desktop.
import firebase from '@store/firebase'
import store from '@store'
import { USER } from '@store/types'
export default async (to, from, next) => {
if (to.name === 'Sign in') {
next()
return
}
await firebase.auth().onAuthStateChanged(user => {
if (user) {
store.dispatch(USER, user)
next()
}
else next({ name: 'Sign in' })
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment