mirror of
https://github.com/Stef-00012/Zipline-Android-App.git
synced 2025-05-11 18:35:58 +02:00
new hooks
This commit is contained in:
parent
5d4c788db9
commit
b9591efc19
18 changed files with 371 additions and 214 deletions
16
hooks/useAuth.ts
Normal file
16
hooks/useAuth.ts
Normal 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
14
hooks/useLoginAuth.ts
Normal 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
21
hooks/useShareIntent.ts
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue