aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/helpers/higher-order-components/authenticated/authenticated.component.js
blob: c195d0e21a52db44f24f6e4b8edf8a0701fdfd57 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import React from 'react'
import PropTypes from 'prop-types'
import { Redirect, Route } from 'react-router-dom'
import { UNLOCK_ROUTE, INITIALIZE_ROUTE } from '../../constants/routes'

export default function Authenticated (props) {
  const { isUnlocked, completedOnboarding } = props

  switch (true) {
    case isUnlocked && completedOnboarding:
      return <Route { ...props } />
    case !completedOnboarding:
      return <Redirect to={{ pathname: INITIALIZE_ROUTE }} />
    default:
      return <Redirect to={{ pathname: UNLOCK_ROUTE }} />
  }
}

Authenticated.propTypes = {
  isUnlocked: PropTypes.bool,
  completedOnboarding: PropTypes.bool,
}