Auto Logout

Set idle time to sign out.

  • In your LinkerStudio/modules/authentication/common/constants/ConfigValues.ts file, modify the TIME_USER_INACTIVE property. By default, it is set to 10 minutes.

export default {
  //...other
  TIME_USER_INACTIVE: 1000 * 60 * 10,
  //...other
};

How to use?

  • In your ProtectedStackNavigator file, import the following block of code:

import {CONFIG_VALUES} from 'LinkerStudio/modules/authentication/common/constants';
import UserInactivity from 'react-native-user-inactivity';
import {logout} from 'LinkerStudio/modules/authentication/common/utils/AuthHelper';
  • Add the active state, which has the values true or false. true for when the session is active, and false for when the session should be closed.

const [active, setActive] = useState(true);
  • Wrap your Stack.Navigator with the UserInactivity component:

<UserInactivity
    isActive={active}
    timeForInactivity={CONFIG_VALUES.TIME_USER_INACTIVE}
    onAction={isActive => {
      setActive(isActive);
        if (!isActive) {
          logout(dispatch);
        }
    }}>
      <Stack.Navigator>
        {/*your screens*/}
      </Stack.Navigator>
</UserInactivity>

Last updated