feat: add auth, hosts, & keychains ownership

This commit is contained in:
2024-11-10 18:49:35 +07:00
parent b2cc6778a6
commit 38e81049a1
31 changed files with 579 additions and 92 deletions
+12 -3
View File
@@ -12,6 +12,7 @@ import { router, usePathname, useRootNavigationState } from "expo-router";
import { useAuthStore } from "@/stores/auth";
import { PortalProvider } from "tamagui";
import { queryClient } from "@/lib/api";
import { useAppStore } from "@/stores/app";
type Props = PropsWithChildren;
@@ -53,16 +54,24 @@ const AuthProvider = () => {
const pathname = usePathname();
const rootNavigationState = useRootNavigationState();
const { isLoggedIn } = useAuthStore();
const { curServer } = useAppStore();
useEffect(() => {
if (!rootNavigationState?.key) {
return;
}
if (!pathname.startsWith("/auth") && !isLoggedIn) {
if (!curServer && !pathname.startsWith("/server")) {
router.replace("/server");
return;
}
const isProtected = !["/auth", "/server"].find((path) =>
pathname.startsWith(path)
);
if (isProtected && !isLoggedIn) {
router.replace("/auth/login");
} else if (pathname.startsWith("/auth") && isLoggedIn) {
router.replace("/");
}
}, [pathname, rootNavigationState, isLoggedIn]);
+2 -13
View File
@@ -1,14 +1,3 @@
import { View, Text, Button } from "tamagui";
import React from "react";
import authStore from "@/stores/auth";
import LoginPage from "@/pages/auth/login";
export default function LoginPage() {
return (
<View>
<Text>LoginPage</Text>
<Button onPress={() => authStore.setState({ token: "123" })}>
Login
</Button>
</View>
);
}
export default LoginPage;
+6
View File
@@ -1,9 +1,15 @@
import React from "react";
import { Redirect } from "expo-router";
import { useTermSession } from "@/stores/terminal-sessions";
import { useAppStore } from "@/stores/app";
export default function index() {
const { sessions, curSession } = useTermSession();
const { servers, curServer } = useAppStore();
if (!servers.length || !curServer) {
return <Redirect href="/server" />;
}
return (
<Redirect
+3
View File
@@ -0,0 +1,3 @@
import ServerPage from "@/pages/server/page";
export default ServerPage;