import React from 'react';
import { Route, Redirect } from 'react-router-dom';
import history from '../history';

import { authenticationService } from '../_services';

export const PublicRoute = ({ component: Component, restricted, ...rest }) => (
    <Route {...rest} render={props => {
        const currentUser = authenticationService.currentUserValue;
        if (currentUser) {
            //history.push("/dashboard");
            // not logged in so redirect to login page with the return url
            return <Redirect to={{ pathname: '/dashboard', state: { from: props.location } }} />
        }else{

        }

        // authorised so return component
        return <Component {...props} />
    }} />
)