handle user menu, finish server settings, add tmporary WIP page for undone pages

This commit is contained in:
Stef-00012 2025-01-29 21:04:09 +01:00
parent 8d295153bc
commit c05a29c21d
No known key found for this signature in database
GPG key ID: 28BE9A9E4EF0E6BF
14 changed files with 1686 additions and 1109 deletions

View file

@ -1,16 +1,21 @@
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 = (adminOnly = false) => {
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 (adminOnly && authenticated === "USER") return router.replace("/")
if (userPosition < minimumPosition) return router.replace("/")
})();
});
}