Zipline-Android-App/hooks/useAuth.ts
2025-01-27 00:37:37 +01:00

16 lines
No EOL
479 B
TypeScript

import { isAuthenticated } from "@/functions/zipline/auth";
import { useFocusEffect, useRouter } from "expo-router";
export const useAuth = (adminOnly = false) => {
const router = useRouter()
useFocusEffect(() => {
(async () => {
const authenticated = await isAuthenticated();
if (!authenticated) return router.replace("/login");
if (adminOnly && authenticated === "USER") return router.replace("/")
})();
});
}