mirror of
https://github.com/Stef-00012/Zipline-Android-App.git
synced 2025-05-11 10:25:59 +02:00
21 lines
630 B
TypeScript
21 lines
630 B
TypeScript
import { isAuthenticated } from "@/functions/zipline/auth";
|
|
import { useFocusEffect, useRouter } from "expo-router";
|
|
import type { APIUser } from "@/types/zipline";
|
|
import { roles } from "@/constants/auth";
|
|
|
|
export const useAuth = (minimumRole: APIUser["role"] = "USER") => {
|
|
const router = useRouter();
|
|
const minimumPosition = roles[minimumRole];
|
|
|
|
useFocusEffect(() => {
|
|
(async () => {
|
|
const authenticated = await isAuthenticated();
|
|
|
|
if (!authenticated) return router.replace("/login");
|
|
|
|
const userPosition = roles[authenticated];
|
|
|
|
if (userPosition < minimumPosition) return router.replace("/");
|
|
})();
|
|
});
|
|
};
|