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