feat: introduced Authentification Context

This commit is contained in:
Jakob Stornig 2023-12-08 14:51:05 +01:00
parent 7c9fdad01f
commit 6592864bc4
9 changed files with 215 additions and 16 deletions

View file

@ -1,15 +1,22 @@
import { Tabs } from "expo-router/tabs";
import {StyleSheet, View} from "react-native"
import {StyleSheet, View, Text} from "react-native"
import { FontAwesome } from "@expo/vector-icons";
import {useThemeColor} from "../../hooks/hooks";
import React from "react";
import React, { useEffect } from "react";
import { Redirect } from "expo-router";
import { useAuth } from "../contexts/AuthContext";
export default function Layout() {
// const selectedColor: string = useThemeColor( "tabIconSelected");
// const defaultColor: string = useThemeColor("tabIconDefault");
// const backgroundColor: string = useThemeColor("backgroundColor");
// const tabBarColor: string = useThemeColor("tabBarColor");
const {authState} = useAuth()
useEffect(()=>{
console.log(authState, "in root Layout")
},[authState])
const styles = StyleSheet.create({
sceneContainer: {
@ -27,6 +34,11 @@ export default function Layout() {
tabBarStyle: styles.tabBar,
}
if(!authState?.authenticated){
return (
<Redirect href={"/"} />)
}
return (
<Tabs sceneContainerStyle={styles.sceneContainer} screenOptions={screenOptions}>
<Tabs.Screen name="budget/index" options={

View file

@ -6,10 +6,11 @@ import { FlatList, TextInput} from 'react-native-gesture-handler';
import { useRef, useState, useEffect } from 'react';
import React from 'react';
import { useRouter } from "expo-router"
import { useAuth } from '../../contexts/AuthContext';
export default function Page() {
const router = useRouter()
const {onLogout} = useAuth();
const [plusShow, setPlusShow] = useState(true);
const prevOffset = useRef(0);
const styles = StyleSheet.create({
@ -52,7 +53,7 @@ export default function Page() {
return (
<View style={{flex: 1}}>
<SafeAreaView style={{flex: 1}}>
{plusShow && <Plus onPress={()=>{
router.push("/(tabs)/home/addItem")
}}/>}
@ -61,7 +62,7 @@ export default function Page() {
data={data}
ListHeaderComponent={
<>
<Welcome name="My Dude" image={profile} onPress={()=>console.log("hello")}></Welcome>
<Welcome name="My Dude" image={profile} onPress={onLogout!}></Welcome>
<SearchBar placeholder='Type to Search...'></SearchBar>
</>
}
@ -72,7 +73,7 @@ export default function Page() {
scrollEventThrottle={20}
>
</FlatList>
</View>
</SafeAreaView>
);
}