Auto Logout
Set idle time to sign out.
In your
LinkerStudio/modules/authentication/common/constants/ConfigValues.tsfile, modify theTIME_USER_INACTIVEproperty. By default, it is set to 10 minutes.
export default {
//...other
TIME_USER_INACTIVE: 1000 * 60 * 10,
//...other
};How to use?
In your
ProtectedStackNavigatorfile, 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
activestate, which has the valuestrueorfalse.truefor when the session is active, andfalsefor when the session should be closed.
const [active, setActive] = useState(true);Wrap your
Stack.Navigatorwith theUserInactivitycomponent:
<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
Was this helpful?