Skip to content

Commit

Permalink
fix: auth redirect issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1230 committed Apr 21, 2024
1 parent d0c8c77 commit 73942d3
Show file tree
Hide file tree
Showing 18 changed files with 479 additions and 513 deletions.
13 changes: 13 additions & 0 deletions client/src/app/(app)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Redirect } from "expo-router";

import Drawer from "@/components/DrawerNav/Drawer";
import { useUserData } from "@/hooks/stores/useUserData";

export default function HomeLayout() {
const session = useUserData.use.session();

if (!session) return <Redirect href={{ pathname: "/(auth)" }} />;
return <Drawer />;
}

export { ErrorBoundary } from "expo-router";
File renamed without changes.
File renamed without changes.
18 changes: 5 additions & 13 deletions client/src/app/(auth)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import { Redirect, Stack, useLocalSearchParams } from "expo-router";
import { Redirect, Stack } from "expo-router";

import { useUser } from "@/hooks/useUser";
import { useUserData } from "@/hooks/stores/useUserData";

export default function AuthLayout() {
const params = useLocalSearchParams();
const { loading, data: session } = useUser();
const session = useUserData.use.session();

if (loading) return null;
if (session) return <Redirect href={{ pathname: "/(main)", params }} />;
return (
<Stack screenOptions={{ headerShown: false }}>
<Stack.Screen name="index" />
<Stack.Screen name="login" />
<Stack.Screen name="signup" />
</Stack>
);
if (session) return <Redirect href={{ pathname: "/(app)" }} />;
return <Stack screenOptions={{ headerShown: false }} />;
}

export { ErrorBoundary } from "expo-router";
15 changes: 0 additions & 15 deletions client/src/app/(main)/_layout.tsx

This file was deleted.

72 changes: 38 additions & 34 deletions client/src/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,55 @@ import Head from "expo-router/head";
import { PortalHost } from "@/components/primitives/portal";
import { Providers } from "@/providers";

export const unstable_settings = { initialRouteName: "(main)" };
export const unstable_settings = {
initialRouteName: "(app)/index",
auth: { initialRouteName: "(auth)/index" },
};

// Prevent the splash screen from auto-hiding before asset loading is complete.
SplashScreen.preventAutoHideAsync();

export default function RootLayout() {
const [loaded, error] = useFonts({
SpaceMono: require("../../assets/fonts/SpaceMono-Regular.ttf"),
...FontAwesome.font,
});
const [loaded, error] = useFonts({
SpaceMono: require("../../assets/fonts/SpaceMono-Regular.ttf"),
...FontAwesome.font,
});

useEffect(() => {
if (error) throw error;
}, [error]);
useEffect(() => {
if (error) throw error;
}, [error]);

useEffect(() => {
if (loaded) SplashScreen.hideAsync();
}, [loaded]);
useEffect(() => {
if (loaded) SplashScreen.hideAsync();
}, [loaded]);

return loaded ? <RootProviders /> : null;
return loaded ? <RootProviders /> : null;
}

function RootProviders() {
return (
<Providers>
<Head>
<title>myChat</title>
</Head>
<Stack
screenOptions={{
headerShown: false,
contentStyle: { backgroundColor: "#fff" },
}}
>
<Stack.Screen name="(main)" />
<Stack.Screen name="(auth)" />
<Stack.Screen name="file/[id]" options={{ presentation: "modal" }} />
<Stack.Screen name="agent/index" options={{ presentation: "modal" }} />
<Stack.Screen name="agent/[id]" options={{ presentation: "modal" }} />
<Stack.Screen name="agent/create/index" />
<Stack.Screen name="settings" options={{ presentation: "modal" }} />
</Stack>
<PortalHost />
</Providers>
);
return (
<Providers>
<Head>
<title>myChat</title>
</Head>
<Stack
initialRouteName="(app)/index.tsx"
screenOptions={{
headerShown: false,
contentStyle: { backgroundColor: "#fff" },
}}
>
<Stack.Screen name="(app)" />
<Stack.Screen name="(auth)" />
<Stack.Screen name="file/[id]" options={{ presentation: "modal" }} />
<Stack.Screen name="agent/index" options={{ presentation: "modal" }} />
<Stack.Screen name="agent/[id]" options={{ presentation: "modal" }} />
<Stack.Screen name="agent/create/index" />
<Stack.Screen name="settings" options={{ presentation: "modal" }} />
</Stack>
<PortalHost />
</Providers>
);
}

export { ErrorBoundary } from "expo-router";
Loading

0 comments on commit 73942d3

Please sign in to comment.