T
Anderson, I've had to do this once and normally to pass parameters/data to other components we use the props or pass to the destructured data.
But in this specific case of authentication, I used Redux where I stored the data in the Redux state and this data is available for other components. This is the Login class, so it stayed:class Login extends Component {
constructor(props) {
super(props);
this.state = {};
}
login = () => {
const { username, password } = this.state;
const data = {};
data.client_id = Config.CLIENT_ID;
data.client_secret = Config.CLIENT_SECRET;
data.grant_type = 'password';
data.username = username;
data.password = password;
data.scope = '';
const { ...props } = this.props;
props.onLogin(data);
};
verificaToken = () => {
if (localStorage.str_storage_tk) {
Config.TOKEN = JSON.parse(localStorage.str_storage_tk);
Config.AUTH_TYPE = 'Bearer ';
}
};
render() {
if (isAuthenticated()) {
return <Redirect to="/perfil" />;
}
const { ...props } = this.props;
return (
<Loadable
active={props.isLoading}
spinner
background="rgba(245,245,245, 0.7)"
color="#000"
text="Aguarde..."
spinnerSize="115px"
>
Implementação do HTML
</Loadable>
);
}
}
const mapDispatchToProps = dispatch => ({
onLogin: data => dispatch(login(data)),
});
const mapStateToProps = state => ({
isLoading: state.ui.isLoading,
});
export default connect(
mapStateToProps,
mapDispatchToProps,
)(Login);