wwAuth.js 1.02 KB
const DEVELOPMENT_HOSTNAME = 'scrm.dev.glsx.com.cn'
const EVECTION_AUTH_PATHS = ['/evection/department', '/evection/personage', '/evection/company']
const APPROVAL_AUTH_PATHS = ['/orderapproval', '/accountapproval']

function getHashRoutePath(href) {
  const hashIndex = href.indexOf('#')
  if (hashIndex === -1) return ''
  let routePath = href.slice(hashIndex + 1).split('?')[0].toLowerCase()
  if (routePath && !routePath.startsWith('/')) routePath = `/${routePath}`
  if (routePath.length > 1) routePath = routePath.replace(/\/+$/, '')
  return routePath
}

function shouldRequireWwAuth({ href = '', hostname = '', pushId } = {}) {
  const routePath = getHashRoutePath(href)
  const isEvectionPath = EVECTION_AUTH_PATHS.includes(routePath)
  const isApprovalPath = APPROVAL_AUTH_PATHS.includes(routePath)

  if (isApprovalPath) return true
  if (isEvectionPath && hostname === DEVELOPMENT_HOSTNAME) return false
  if (isEvectionPath && pushId && pushId * 1 > 744) return true
  return false
}

module.exports = {
  shouldRequireWwAuth
}