I'm facing an issue regarding a text in Router-Flux.
In my App.js page, I have set up all the routes for the App. Specifically, I have added the text "Logout" for the homepageUtente.js.
Below is the code snippet from App.js
export default class App extends Component {
static redirectLogout() {
Alert.alert("Logout", "Logout successful");
Actions.authentication();
}
static logout() {
Utente.clearUtenteLoggato();
App.redirectLogout();
}
// This method that I tried does not work.
static checkUser() {
Utente.getUtenteLoggato();
const Roles = global.utente.data.Roles;
return Roles;
}
render() {
return (
<Router>
<Scene key="root">
<Scene
key="authentication"
component={Authentication}
navigationBarStyle={{ backgroundColor: "#64c7c0" }}
type="reset"
/>
<Scene
key="homepageutente"
component={HomepageUtente}
type="reset"
leftTitle="Home"
leftButtonTextStyle={{ color: "#ffffff" }}
onLeft={() => Actions.authentication()}
rightButtonTextStyle={{ color: "#ffffff" }}
rightTitle={App.checkUser !== "ROLE_PLUS" ? "Logout" : ""}
onRight={App.checkUser !== "ROLE_PLUS" ? () => App.logout() : () => {}}
// This is how to log out (but it does not differentiate between roles)
//rightTitle="Logout"
//onRight={() => App.logout()}
navigationBarStyle={{ backgroundColor: "#64c7c0" }}
/>
Now, let's take a look at the HomepageUser.js file
class HomepageUser extends Component {
constructor(props){
super(props);
}
render() {
const FirstName = global.utente.data.Person.FirstName;
const LastName = global.utente.data.Person.LastName;
const Roles = global.utente.data.Roles;
console.log(Roles);
return (
<View>
<Text style={{textAlign: 'center', fontSize: 20,}}>{"Welcome"}</Text>
<Text style={{textAlign: 'center', fontSize: 20, color: '#64c7c0', fontWeight: 'bold'}}>{FirstName} {LastName}</Text>
<Text>{Roles}</Text>
</View>
)
}
}
Finally, here is the function I used for handling UserLoggedIn
static async getUtenteLoggato() {
try {
return await AsyncStorage.getItem("@UtenteLoggato");
} catch (error) {
console.log(error.message);
return null;
}
}
My issue lies in ensuring that if the user has the role "ROLE_PLUS," they should not be able to logout. But I am unsure of how to hide the text for this particular role.