new hooks

This commit is contained in:
Stef-00012 2025-01-26 18:17:38 +01:00
parent 5d4c788db9
commit b9591efc19
No known key found for this signature in database
GPG key ID: 28BE9A9E4EF0E6BF
18 changed files with 371 additions and 214 deletions

16
hooks/useAuth.ts Normal file
View file

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

14
hooks/useLoginAuth.ts Normal file
View file

@ -0,0 +1,14 @@
import { isAuthenticated } from "@/functions/zipline/auth";
import { useFocusEffect, useRouter } from "expo-router";
export const useLoginAuth = () => {
const router = useRouter()
useFocusEffect(() => {
(async () => {
const authenticated = await isAuthenticated();
if (authenticated) return router.replace("/");
})();
});
}

21
hooks/useShareIntent.ts Normal file
View file

@ -0,0 +1,21 @@
import { useRouter } from "expo-router";
import { useShareIntentContext } from "expo-share-intent";
import { useEffect } from "react";
export const useShareIntent = (skipRedirect = false) => {
const router = useRouter()
const { hasShareIntent, resetShareIntent } = useShareIntentContext();
if (skipRedirect) return resetShareIntent;
// biome-ignore lint/correctness/useExhaustiveDependencies: .
useEffect(() => {
if (hasShareIntent) {
router.replace({
pathname: "/shareintent",
});
}
}, [hasShareIntent]);
return resetShareIntent;
}