mirror of
https://github.com/khairul169/vaulterm.git
synced 2026-09-15 17:03:30 +07:00
feat: add auth, hosts, & keychains ownership
This commit is contained in:
@@ -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]);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
import ServerPage from "@/pages/server/page";
|
||||
|
||||
export default ServerPage;
|
||||
Reference in New Issue
Block a user