26 lines
No EOL
632 B
TypeScript
26 lines
No EOL
632 B
TypeScript
import React, { Component } from "react";
|
|
import { connect } from "react-redux";
|
|
import { Redirect } from "react-router-dom";
|
|
|
|
import { ServerSelectors } from "store";
|
|
import { RouteEnum } from "types";
|
|
|
|
import { AuthenticationService } from "api";
|
|
|
|
class AuthGuard extends Component<AuthGuardProps> {
|
|
render() {
|
|
return !AuthenticationService.isConnected(this.props.state)
|
|
? <Redirect from="*" to={RouteEnum.SERVER} />
|
|
: "";
|
|
}
|
|
};
|
|
|
|
interface AuthGuardProps {
|
|
state: number;
|
|
}
|
|
|
|
const mapStateToProps = state => ({
|
|
state: ServerSelectors.getState(state),
|
|
});
|
|
|
|
export default connect(mapStateToProps)(AuthGuard); |