mirror of
https://github.com/Stef-00012/Zipline-Android-App.git
synced 2025-05-11 18:35:58 +02:00
handle user menu, finish server settings, add tmporary WIP page for undone pages
This commit is contained in:
parent
8d295153bc
commit
c05a29c21d
14 changed files with 1686 additions and 1109 deletions
|
@ -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("/")
|
||||
})();
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue