I am trying to hide a menu button if there is . Baiscly if the user is not allowed to see the menu i receive an empty rol from the token ( basicly rol : [''] , otherwise if it is allowed is rol : ['_DECLARATION']. I have tried with a conditional rendering but maybe i am mistaken of my methods that i use. If somebody could give a hand would be very nice .
constructor(props) {
super(props);
this.state = {
roles: ''
}
async componentDidMount() {
const base64Url = token.split('.')[1];
const decodedValue = JSON.parse(window.atob(base64Url))
const roles = decodedValue.roles;
render() {
const { roles } = this.state
return (
{ roles
? <Button className="emptyRollButtonDec"/>
: <Button
onClick={this.changeActiveComponent
style= {{
background: branding.color.colorPrimary,
color: branding.color.colorTextPrimary
}}>
Declaration
</Button>
}
I dont know and i dont understand where i am wrong .
!roles.length.rolesis always defined.