add required login

This commit is contained in:
2025-06-04 20:45:20 +02:00
parent 35efcbe3a8
commit 3bd3b9b70d
5 changed files with 51 additions and 21 deletions

View File

@@ -51,13 +51,13 @@ export default function Login() {
<VStack className="pb-4" space="xs">
<Heading className="leading-[30px]">Logowanie</Heading>
<Box className="flex flex-row">
<Link href="/registration" asChild>
<Button variant="link" size="sm" className="p-0">
{/* <Link href="/registration" asChild> */}
<Button variant="link" size="sm" className="p-0" onPress={() => router.replace("/registration")}>
<ButtonText style={styles.signupbutton}>Nie masz jeszcze konta? Załóz je
tutaj!</ButtonText>
<ButtonIcon className="mr-1" size="md" as={ArrowRightIcon}/>
</Button>
</Link>
{/* </Link> */}
</Box>
</VStack>
<VStack space="xl" className="py-2">

View File

@@ -48,21 +48,10 @@ export default function TabLayout() {
),
}}
/>
<Tabs.Screen
name="login"
options={{
headerShown: false, // Ukryj nagłówek dla Drawer
title: "Authentication",
tabBarLabel: "Authentication",
tabBarIcon: ({color, size}) => (
<Ionicons name="key" size={size} color={color}/>
),
}}
/>
<Tabs.Screen
name="dashboard"
options={{
headerShown: false, // Ukryj nagłówek dla Drawer
headerShown: false,
title: "Konto",
tabBarLabel: "Konto",
tabBarIcon: ({color, size}) => (

View File

@@ -5,8 +5,24 @@ import { NoticeSection } from "@/components/NoticeSection";
import { UserSection } from "@/components/UserSection";
import { SearchSection } from "@/components/SearchSection";
import { FlatList } from 'react-native';
import { useAuthStore } from "@/store/authStore";
import { useRouter } from "expo-router";
import { useEffect, useState } from "react";
export default function Home() {
const token = useAuthStore((state) => state.token);
const router = useRouter();
const [isReady, setIsReady] = useState(false);
useEffect(() => {
setIsReady(true);
}, []);
useEffect(() => {
if (isReady && !token) {
router.replace("/login");
}
}, [isReady, token, router]);
const notices = useNoticesStore((state) => state.notices);
const latestNotices = [...notices]
.sort((a, b) => new Date(b.publishDate) - new Date(a.publishDate))
@@ -14,6 +30,7 @@ export default function Home() {
const recomendedNotices = [...notices]
.sort(() => Math.random() - 0.5)
.slice(0, 6);
return (
<View>
<SearchSection/>

View File

@@ -1,9 +1,9 @@
import { Stack } from "expo-router";
import { Stack, Redirect } from "expo-router";
import "@/global.css";
import { GluestackUIProvider } from "@/components/ui/gluestack-ui-provider";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { useEffect } from "react";
import { useNoticesStore } from "@/store/noticesStore";
import { useEffect, useState } from "react";
import { useNoticesStore } from "@/store/noticesStore";
const queryClient = new QueryClient();
export default function RootLayout() {
@@ -12,9 +12,11 @@ export default function RootLayout() {
useEffect(() => {
fetchNotices();
}, []);
return (
return (
<QueryClientProvider client={queryClient}>
<GluestackUIProvider>
<Stack
screenOptions={{
headerTintColor: "#1c1c1e",
@@ -23,6 +25,12 @@ export default function RootLayout() {
}}
>
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen
name="(auth)/login"
options={{ headerShown: false }}/>
<Stack.Screen
name="registration"
options={{ headerShown: false }}/>
</Stack>
</GluestackUIProvider>
</QueryClientProvider>

View File

@@ -4,11 +4,13 @@ import {useAuthStore} from '@/store/authStore';
import {useRouter} from 'expo-router';
import {Box} from "@/components/ui/box"
import {Button, ButtonText} from "@/components/ui/button"
import {Button, ButtonText,ButtonIcon} from "@/components/ui/button"
import {ArrowRightIcon} from "@/components/ui/icon"
import {Center} from "@/components/ui/center"
import {Heading} from "@/components/ui/heading"
import {Input, InputField} from "@/components/ui/input"
import {VStack} from "@/components/ui/vstack"
import {Link} from "expo-router"
export default function Registration() {
const [email, setEmail] = useState('');
@@ -44,9 +46,18 @@ export default function Registration() {
return (
<SafeAreaView style={styles.container}>
<Center>
<Box className="p-5 w-[80%] border border-background-300 rounded-lg">
<VStack className="pb-4" space="xs">
<Heading className="leading-[30px]">Rejestracja</Heading>
<Box className="flex flex-row">
{/* <Link href="/login" asChild> */}
<Button variant="link" size="sm" className="p-0" onPress={() => router.replace("/login")}>
<ButtonText style={styles.signupbutton}>Masz już konto? Zaloguj się!</ButtonText>
<ButtonIcon className="mr-1" size="md" as={ArrowRightIcon}/>
</Button>
{/* </Link> */}
</Box>
</VStack>
<VStack space="xl" className="py-2">
<Input>
@@ -69,6 +80,7 @@ export default function Registration() {
</Button>
</VStack>
</Box>
</Center>
</SafeAreaView>
);
@@ -93,4 +105,8 @@ const styles = StyleSheet.create({
color: 'red',
marginBottom: 10,
},
signupbutton: {
fontWeight: '300',
textAlign: 'left',
},
});