import { Accounts } from 'meteor/accounts-base'
import { FlowRouter } from 'meteor/kadira:flow-router'

Accounts.onLogin(() => {
  const lastPath = FlowRouter.current().queryParams.path
  const currentPath = FlowRouter.current().path

  if (lastPath) {
    return FlowRouter.go(lastPath)
  } else if (currentPath === '/login' || currentPath === '/signup') {
    return FlowRouter.go('/')
  }
})
