This repository has been archived on 2025-09-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
resolver/app/api/AuthRouterAPI.jsx
2017-07-06 11:20:18 +04:30

31 lines
742 B
JavaScript

// - Import react components
import React, {Component} from 'react'
import {Route, Redirect} from 'react-router-dom'
// - Import API
import * as AuthAPI from 'AuthAPI'
export var PrivateRoute = ({component: Component, ...rest}) => {
console.log('is auth ; ', AuthAPI.isAuthorized());
return (
<Route
{...rest}
render={(props) => AuthAPI.isAuthorized()
? <Component {...props} />
: <Redirect to={{pathname: '/login', state: {from: props.location}}} />}
/>
)
}
export var PublicRoute = ({component: Component,...rest}) => {
return (
<Route
{...rest}
render={(props) => !(AuthRouterAPI.isAuthorized())
? <Component {...props} />
: <Redirect to='/' />}
/>
)
}