navigate to intro when the state actually changes

This commit is contained in:
unclekingpin 2023-07-20 15:19:29 -07:00
parent 1d259137ee
commit dc85e938bd
2 changed files with 7 additions and 4 deletions

View file

@ -97,10 +97,6 @@ const App = () => {
React.useEffect(() => {
const onCoreEvent = ({ event, args }) => {
switch (event) {
case 'UserLoggedOut': {
window.location = '#/intro';
break;
}
case 'SettingsUpdated': {
if (args && args.settings && typeof args.settings.interfaceLanguage === 'string') {
i18n.changeLanguage(args.settings.interfaceLanguage);

View file

@ -7,6 +7,13 @@ const { useProfile } = require('stremio/common');
const withProtectedRoutes = (Component) => {
return function withProtectedRoutes(props) {
const profile = useProfile();
const previousProfileRef = React.useRef(null);
React.useEffect(() => {
if (previousProfileRef.current?.auth !== null && profile.auth === null) {
window.location = '#/intro';
}
previousProfileRef.current = profile;
}, [profile])
const onRouteChange = React.useCallback((routeConfig) => {
if (profile.auth !== null && routeConfig.component === Intro) {
window.location.replace('#/');