import { IS_LOGGED_IN_GETTER_NAME } from '@/config/defaults'
import router from '@/router'

export default store => {
  store.subscribe(mutation => {
    if (mutation.type === 'route/ROUTE_CHANGED' && store.getters[IS_LOGGED_IN_GETTER_NAME]) {
      let { requires, skipVerification } = store.getters.getVerifyContactStatus
      if (mutation.payload.to.name !== 'PreferredContact' && requires && !skipVerification) {
        router.push({ name: 'PreferredContact' })
      }
    }
  })
}
