<commit_before>import router from '@/router'

export default store => {
  let isLoggedIn = () => store.getters['auth/isLoggedIn']
  let hasActiveGroup = () => !!store.getters['groups/activeGroup']
  let getUserGroupId = () => isLoggedIn() && store.getters['auth/user'].currentGroup
  let getUserId = () => isLoggedIn() && store.getters['auth/user'].id

  router.beforeEach((to, from, next) => {
    if (to.matched.some(m => m.meta.requireLoggedIn) && !isLoggedIn()) {
      let {name, params} = to
      store.dispatch('auth/setRedirectTo', {name, params})
      next({name: 'login'})
    }
    else {
      next()
    }
  })

  router.beforeEach((to, from, next) => {
    if (to.matched.some(m => m.meta.requireLoggedOut) && isLoggedIn()) {
      next({name: 'index'})
    }
    else {
      next()
    }

    let path = to.path
    // redirect homescreen correctly
    if (path === '/') {
      if (getUserGroupId()) {
        next({name: 'group', params: { groupId: getUserGroupId() }})
      }
      else {
        next({name: 'group', params: { groupId: 1 }})
      }
    }
    console.log(to)
    // set default params correctly
    if (path.includes('groupId') && !to.params.groupId && getUserGroupId()) {
      console.log('group redirect...')
      next({path: to.path, params: { groupId: getUserGroupId() }})
    }

    // set default params correctly
    if ((path.includes('userId') || to.name === 'user') && !to.params.userId && getUserId()) {
      console.log('user redirect')
      next({path: to.path, params: { userId: getUserId() }})
    }
    console.log('route fine')
    console.log(path.includes('userId'))
    next()
  })

  router.afterEach((to, from) => {
    // save Breadcrumbs to store
    if (!(to.meta) || !(to.meta.breadcrumbs)) {
      store.dispatch('breadcrumbs/setAll', {breadcrumbs: [{name: 'not defined'}]})
    }
    store.dispatch('breadcrumbs/setAll', {breadcrumbs: to.meta.breadcrumbs || []})

    // save active group/store/user
    if (to.params.groupId) {
      store.dispatch('groups/selectGroup', {groupId: to.params.groupId})
    }
    if (to.params.storeId) {
      store.dispatch('stores/selectStore', {storeId: to.params.storeId})
    }
    if (to.params.userId) {
      store.dispatch('users/selectUser', {userId: to.params.userId})<commit_msg>Removed default params for now<commit_after>import router from '@/router'

export default store => {
  let isLoggedIn = () => store.getters['auth/isLoggedIn']
  let hasActiveGroup = () => !!store.getters['groups/activeGroup']
  let getUserGroupId = () => isLoggedIn() && store.getters['auth/user'].currentGroup

  router.beforeEach((to, from, next) => {
    if (to.matched.some(m => m.meta.requireLoggedIn) && !isLoggedIn()) {
      let {name, params} = to
      store.dispatch('auth/setRedirectTo', {name, params})
      next({name: 'login'})
    }
    else {
      next()
    }
  })

  router.beforeEach((to, from, next) => {
    if (to.matched.some(m => m.meta.requireLoggedOut) && isLoggedIn()) {
      next({name: 'index'})
    }
    else {
      next()
    }

    let path = to.path
    // redirect homescreen correctly
    if (path === '/') {
      if (getUserGroupId()) {
        next({name: 'group', params: { groupId: getUserGroupId() }})
      }
      else {
        next({name: 'group', params: { groupId: 1 }})
      }
    }
    next()
  })

  router.afterEach((to, from) => {
    // save Breadcrumbs to store
    if (!(to.meta) || !(to.meta.breadcrumbs)) {
      store.dispatch('breadcrumbs/setAll', {breadcrumbs: [{name: 'not defined'}]})
    }
    store.dispatch('breadcrumbs/setAll', {breadcrumbs: to.meta.breadcrumbs || []})

    // save active group/store/user
    if (to.params.groupId) {
      store.dispatch('groups/selectGroup', {groupId: to.params.groupId})
    }
    if (to.params.storeId) {
      store.dispatch('stores/selectStore', {storeId: to.params.storeId})
    }
    if (to.params.userId) {
      store.dispatch('users/selectUser', {userId: to.params.userId})
{'fraction_non_alphanumeric': 0.1838014042126379, 'fraction_numerical': 0.0005015045135406219, 'mean_word_length': 2.9146221786064768, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1048091', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1347, 'n_words': 249}