in src/components/ProtectedRoute/ProtectedRoute.js [38:79]
componentDidMount() {
Auth.currentAuthenticatedUser()
.then(() => {
this.setState({ isAuthenticated: true });
this.props.setAuth(true);
Auth.currentUserInfo()
.then((user) => {
this.props.setUser(user);
this.props.setLang(user.attributes.locale);
/*
* Check if the user need to "Sign" or "Resign" the ToS
* For reasons of simplicity we load the current ToS version from 'i18n - VERSION_ID'
*/
const tosSigned = (user.attributes['custom:tos_signed'] === "true") || false;
const tosSignedVersionInt = parseInt(user.attributes['custom:tos_version']) || 0;
const tosCurrentVersionInt = I18n.get('TERMS_OF_SERVICE_VERSION_ID') || 0
/*
* If the current ToS are newer or the actual ToS are not sigened we redirect the user to '/tos'
* To redirect the user back to '/settings' after sign the ToS we add Query Param 'redirect'
*/
if ((tosCurrentVersionInt > tosSignedVersionInt) || !tosSigned)
this.setState({ resignToS: true })
})
.catch(err => {
console.log(err);
this.setState({ isAuthenticated: false })
this.props.setAuth(false);
this.props.setUser(null);
});
})
.catch(err => {
if (err !== "not authenticated") console.log(err)
this.setState({ isAuthenticated: false })
this.props.setAuth(false);
this.props.setUser(null);
});
}