From b736dbc1f0ea6f5c4bf6a34130ed0a846129f8af Mon Sep 17 00:00:00 2001 From: Arthur Jamet Date: Wed, 21 Jun 2023 14:47:24 +0100 Subject: [PATCH] Front: Navigation: Prevent Auth Loading from breaking access by URL --- front/Navigation.tsx | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/front/Navigation.tsx b/front/Navigation.tsx index 06c870c..b806bb8 100644 --- a/front/Navigation.tsx +++ b/front/Navigation.tsx @@ -36,14 +36,15 @@ const protectedRoutes = () => Song: { component: SongLobbyView, options: { title: translate('play') }, link: '/song/:songId' }, Artist: { component: ArtistDetailsView, options: { title: translate('artistFilter') }, link: '/artist/:artistId' }, Score: { component: ScoreView, options: { title: translate('score'), headerLeft: null }, link: undefined }, - Search: { component: SearchView, options: { title: translate('search') }, link: '/search/:query' }, + Search: { component: SearchView, options: { title: translate('search') }, link: '/search/:query?' }, User: { component: ProfileView, options: { title: translate('user') }, link: '/user' }, } as const); const publicRoutes = () => ({ - Start: { component: StartPageView, options: { title: 'Chromacase', headerShown: false }, link: undefined }, - Login: { component: AuthenticationView, options: { title: translate('signInBtn') }, link: undefined }, + Start: { component: StartPageView, options: { title: 'Chromacase', headerShown: false }, link: '/' }, + Login: { component: (params: RouteProps<{}>) => AuthenticationView({ isSignup: false, ...params }), options: { title: translate('signInBtn') }, link: '/login' }, + Signup: { component: (params: RouteProps<{}>) => AuthenticationView({ isSignup: true, ...params }), options: { title: translate('signUpBtn') }, link: '/signup' }, Oops: { component: ProfileErrorView, options: { title: 'Oops', headerShown: false }, link: undefined }, } as const); @@ -149,15 +150,12 @@ export const Router = () => { } return 'noAuth' }, [userProfile, accessToken]); - - const linking = useMemo(() => { + const routes = useMemo(() => { if (authStatus == 'authed') { - return routesToLinkingConfig(protectedRoutes()); - } else if (authStatus == 'noAuth') { - return routesToLinkingConfig(publicRoutes()); + return protectedRoutes(); } - return null; - }, [authStatus]) + return publicRoutes(); + }, [authStatus]); useEffect(() => { if (accessToken) { @@ -165,9 +163,14 @@ export const Router = () => { } }, [accessToken]); + if (authStatus == 'loading') { + // We dont want this to be a screen, as this lead to a navigator without the requested route, and fallback. + return ; + } + return ( } theme={colorScheme == 'light' ? DefaultTheme : DarkTheme} > @@ -179,12 +182,8 @@ export const Router = () => { userProfile.refetch()} /> ))} /> - ) : authStatus == 'loading' ? ( - ) : ( - routesToScreens( - authStatus == 'authed' ? protectedRoutes() : publicRoutes() - ) + routesToScreens(routes) )}