Front: settings persistance (#108)

* Front: Add peristance dependencies

* Front: Fix Cross-platform persistance

* Front: Create Settings Slice

* Front: Use Redux State for settings

* Front: Check if access token is still valid

* Front: Create Language Gate to set correct language at startup

* Front: BEtter handling of Access Token validity
This commit is contained in:
Arthur Jamet
2022-11-26 14:18:06 +00:00
committed by GitHub
parent 8546c86332
commit 55526dbadc
10 changed files with 179 additions and 47 deletions
+14 -4
View File
@@ -8,6 +8,8 @@ import { NavigationContainer } from '@react-navigation/native';
import { useSelector } from './state/Store';
import SongLobbyView from './views/SongLobbyView';
import { translate } from './i18n/i18n';
import { useQuery } from 'react-query';
import API from './API';
const Stack = createNativeStackNavigator();
@@ -23,12 +25,20 @@ export const publicRoutes = <React.Fragment>
</React.Fragment>;
export const Router = () => {
const isAuthentified = useSelector((state) => state.user.accessToken !== undefined)
const isAuthentified = useSelector((state) => state.user.accessToken !== undefined);
const userProfile = useQuery(['user', 'me'], () => API.getUserInfo(), {
enabled: isAuthentified
});
return (
<NavigationContainer>
<Stack.Navigator>
{isAuthentified ? protectedRoutes : publicRoutes}
</Stack.Navigator>
{isAuthentified && !userProfile.isError
? <Stack.Navigator>
{protectedRoutes}
</Stack.Navigator>
: <Stack.Navigator>
{publicRoutes}
</Stack.Navigator>
}
</NavigationContainer>
)
}