mirror of
https://github.com/Sosokker/chefhai.git
synced 2025-12-18 21:44:09 +01:00
move auth-centext directory
This commit is contained in:
parent
e5b6b50376
commit
6b3b6765ef
@ -1,6 +1,6 @@
|
||||
import { useAuth } from "@/context/auth-context";
|
||||
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
|
||||
import { Tabs, Redirect } from "expo-router";
|
||||
import { useAuth } from ".././context/auth-context";
|
||||
import { Redirect, Tabs } from "expo-router";
|
||||
|
||||
export default function TabLayout() {
|
||||
const { isAuthenticated, isLoading } = useAuth();
|
||||
|
||||
@ -1,27 +1,27 @@
|
||||
import { AuthProvider } from "@/context/auth-context";
|
||||
import { Stack } from "expo-router";
|
||||
import { GestureHandlerRootView } from "react-native-gesture-handler";
|
||||
import { AuthProvider } from "./context/auth-context";
|
||||
import "../global.css";
|
||||
|
||||
export default function RootLayout() {
|
||||
return (
|
||||
<GestureHandlerRootView style={{ flex: 1 }}>
|
||||
<AuthProvider>
|
||||
<Stack screenOptions={{ headerShown: false }}>
|
||||
<Stack.Screen
|
||||
name="(tabs)"
|
||||
options={{
|
||||
headerShown: false,
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="recipe-detail"
|
||||
options={{
|
||||
headerShown: false,
|
||||
presentation: "card",
|
||||
}}
|
||||
/>
|
||||
</Stack>
|
||||
<Stack screenOptions={{ headerShown: false }}>
|
||||
<Stack.Screen
|
||||
name="(tabs)"
|
||||
options={{
|
||||
headerShown: false,
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="recipe-detail"
|
||||
options={{
|
||||
headerShown: false,
|
||||
presentation: "card",
|
||||
}}
|
||||
/>
|
||||
</Stack>
|
||||
</AuthProvider>
|
||||
</GestureHandlerRootView>
|
||||
);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import { View, ActivityIndicator } from 'react-native';
|
||||
import { Redirect } from 'expo-router';
|
||||
import { useAuth } from './context/auth-context';
|
||||
import { useAuth } from "@/context/auth-context";
|
||||
import { Redirect } from "expo-router";
|
||||
import React from "react";
|
||||
import { ActivityIndicator, View } from "react-native";
|
||||
|
||||
export default function Index() {
|
||||
const { isAuthenticated, isLoading } = useAuth();
|
||||
@ -9,7 +9,14 @@ export default function Index() {
|
||||
// Show loading indicator while checking auth status
|
||||
if (isLoading) {
|
||||
return (
|
||||
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: 'white' }}>
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
backgroundColor: "white",
|
||||
}}
|
||||
>
|
||||
<ActivityIndicator size="large" color="#ffd60a" />
|
||||
</View>
|
||||
);
|
||||
@ -21,4 +28,4 @@ export default function Index() {
|
||||
} else {
|
||||
return <Redirect href="/welcome" />;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,49 +1,57 @@
|
||||
import React, { useState } from 'react';
|
||||
import { View, Text, TextInput, TouchableOpacity, SafeAreaView, StatusBar, Alert } from 'react-native';
|
||||
import { router } from 'expo-router';
|
||||
import { Feather } from '@expo/vector-icons';
|
||||
import { useAuth } from './context/auth-context';
|
||||
import { useAuth } from "@/context/auth-context";
|
||||
import { Feather } from "@expo/vector-icons";
|
||||
import { router } from "expo-router";
|
||||
import React, { useState } from "react";
|
||||
import {
|
||||
Alert,
|
||||
SafeAreaView,
|
||||
StatusBar,
|
||||
Text,
|
||||
TextInput,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
} from "react-native";
|
||||
|
||||
export default function LoginScreen() {
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
|
||||
const { login } = useAuth();
|
||||
|
||||
|
||||
const handleLogin = async () => {
|
||||
if (!email || !password) {
|
||||
Alert.alert('Error', 'Please fill in all fields');
|
||||
Alert.alert("Error", "Please fill in all fields");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
setIsLoading(true);
|
||||
await login(email, password);
|
||||
} catch (error) {
|
||||
Alert.alert('Error', 'Failed to login. Please try again.');
|
||||
Alert.alert("Error", "Failed to login. Please try again.");
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<SafeAreaView className="flex-1 bg-white">
|
||||
<StatusBar barStyle="dark-content" />
|
||||
|
||||
|
||||
<View className="px-6 py-10 flex-1">
|
||||
{/* Back Button */}
|
||||
<TouchableOpacity
|
||||
<TouchableOpacity
|
||||
className="bg-[#ffd60a] p-3 rounded-lg w-12 mb-8"
|
||||
onPress={() => router.back()}
|
||||
>
|
||||
<Feather name="arrow-left" size={24} color="#bb0718" />
|
||||
</TouchableOpacity>
|
||||
|
||||
|
||||
{/* Header */}
|
||||
<Text className="text-3xl font-bold mb-8">Login to your account</Text>
|
||||
|
||||
|
||||
{/* Form */}
|
||||
<View className="space-y-6">
|
||||
<View>
|
||||
@ -57,7 +65,7 @@ export default function LoginScreen() {
|
||||
autoCapitalize="none"
|
||||
/>
|
||||
</View>
|
||||
|
||||
|
||||
<View>
|
||||
<Text className="text-gray-700 mb-2 font-medium">Password</Text>
|
||||
<View className="flex-row items-center bg-gray-100 rounded-xl">
|
||||
@ -69,38 +77,44 @@ export default function LoginScreen() {
|
||||
secureTextEntry={!showPassword}
|
||||
autoCapitalize="none"
|
||||
/>
|
||||
<TouchableOpacity
|
||||
<TouchableOpacity
|
||||
className="pr-4"
|
||||
onPress={() => setShowPassword(!showPassword)}
|
||||
>
|
||||
<Feather name={showPassword ? "eye-off" : "eye"} size={20} color="gray" />
|
||||
<Feather
|
||||
name={showPassword ? "eye-off" : "eye"}
|
||||
size={20}
|
||||
color="gray"
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
|
||||
<TouchableOpacity>
|
||||
<Text className="text-right text-[#bb0718] font-medium">Forgot Password?</Text>
|
||||
<Text className="text-right text-[#bb0718] font-medium">
|
||||
Forgot Password?
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
|
||||
<TouchableOpacity
|
||||
|
||||
<TouchableOpacity
|
||||
className="bg-[#ffd60a] py-4 rounded-xl mt-6"
|
||||
onPress={handleLogin}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<Text className="text-center font-bold text-lg">
|
||||
{isLoading ? 'Logging in...' : 'Login'}
|
||||
{isLoading ? "Logging in..." : "Login"}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
|
||||
{/* Sign Up Link */}
|
||||
<View className="flex-row justify-center mt-8">
|
||||
<Text className="text-gray-600">Don't have an account? </Text>
|
||||
<TouchableOpacity onPress={() => router.push('/signup')}>
|
||||
<Text className="text-gray-600">Don't have an account? </Text>
|
||||
<TouchableOpacity onPress={() => router.push("/signup")}>
|
||||
<Text className="text-[#bb0718] font-medium">Sign Up</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
</SafeAreaView>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,57 +1,66 @@
|
||||
import React, { useState } from 'react';
|
||||
import { View, Text, TextInput, TouchableOpacity, SafeAreaView, StatusBar, Alert, ScrollView } from 'react-native';
|
||||
import { router } from 'expo-router';
|
||||
import { Feather } from '@expo/vector-icons';
|
||||
import { useAuth } from './context/auth-context';
|
||||
import { useAuth } from "@/context/auth-context";
|
||||
import { Feather } from "@expo/vector-icons";
|
||||
import { router } from "expo-router";
|
||||
import React, { useState } from "react";
|
||||
import {
|
||||
Alert,
|
||||
SafeAreaView,
|
||||
ScrollView,
|
||||
StatusBar,
|
||||
Text,
|
||||
TextInput,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
} from "react-native";
|
||||
|
||||
export default function SignupScreen() {
|
||||
const [name, setName] = useState('');
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [confirmPassword, setConfirmPassword] = useState('');
|
||||
const [name, setName] = useState("");
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [confirmPassword, setConfirmPassword] = useState("");
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
|
||||
const { signup } = useAuth();
|
||||
|
||||
|
||||
const handleSignup = async () => {
|
||||
if (!name || !email || !password || !confirmPassword) {
|
||||
Alert.alert('Error', 'Please fill in all fields');
|
||||
Alert.alert("Error", "Please fill in all fields");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (password !== confirmPassword) {
|
||||
Alert.alert('Error', 'Passwords do not match');
|
||||
Alert.alert("Error", "Passwords do not match");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
setIsLoading(true);
|
||||
await signup(name, email, password);
|
||||
} catch (error) {
|
||||
Alert.alert('Error', 'Failed to sign up. Please try again.');
|
||||
Alert.alert("Error", "Failed to sign up. Please try again.");
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<SafeAreaView className="flex-1 bg-white">
|
||||
<StatusBar barStyle="dark-content" />
|
||||
|
||||
|
||||
<ScrollView className="flex-1">
|
||||
<View className="px-6 py-10">
|
||||
{/* Back Button */}
|
||||
<TouchableOpacity
|
||||
<TouchableOpacity
|
||||
className="bg-[#ffd60a] p-3 rounded-lg w-12 mb-8"
|
||||
onPress={() => router.back()}
|
||||
>
|
||||
<Feather name="arrow-left" size={24} color="#bb0718" />
|
||||
</TouchableOpacity>
|
||||
|
||||
|
||||
{/* Header */}
|
||||
<Text className="text-3xl font-bold mb-8">Create an account</Text>
|
||||
|
||||
|
||||
{/* Form */}
|
||||
<View className="space-y-6">
|
||||
<View>
|
||||
@ -63,7 +72,7 @@ export default function SignupScreen() {
|
||||
onChangeText={setName}
|
||||
/>
|
||||
</View>
|
||||
|
||||
|
||||
<View>
|
||||
<Text className="text-gray-700 mb-2 font-medium">Email</Text>
|
||||
<TextInput
|
||||
@ -75,7 +84,7 @@ export default function SignupScreen() {
|
||||
autoCapitalize="none"
|
||||
/>
|
||||
</View>
|
||||
|
||||
|
||||
<View>
|
||||
<Text className="text-gray-700 mb-2 font-medium">Password</Text>
|
||||
<View className="flex-row items-center bg-gray-100 rounded-xl">
|
||||
@ -87,17 +96,23 @@ export default function SignupScreen() {
|
||||
secureTextEntry={!showPassword}
|
||||
autoCapitalize="none"
|
||||
/>
|
||||
<TouchableOpacity
|
||||
<TouchableOpacity
|
||||
className="pr-4"
|
||||
onPress={() => setShowPassword(!showPassword)}
|
||||
>
|
||||
<Feather name={showPassword ? "eye-off" : "eye"} size={20} color="gray" />
|
||||
<Feather
|
||||
name={showPassword ? "eye-off" : "eye"}
|
||||
size={20}
|
||||
color="gray"
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
|
||||
<View>
|
||||
<Text className="text-gray-700 mb-2 font-medium">Confirm Password</Text>
|
||||
<Text className="text-gray-700 mb-2 font-medium">
|
||||
Confirm Password
|
||||
</Text>
|
||||
<View className="flex-row items-center bg-gray-100 rounded-xl">
|
||||
<TextInput
|
||||
className="flex-1 py-4 px-4"
|
||||
@ -107,30 +122,34 @@ export default function SignupScreen() {
|
||||
secureTextEntry={!showPassword}
|
||||
autoCapitalize="none"
|
||||
/>
|
||||
<TouchableOpacity
|
||||
<TouchableOpacity
|
||||
className="pr-4"
|
||||
onPress={() => setShowPassword(!showPassword)}
|
||||
>
|
||||
<Feather name={showPassword ? "eye-off" : "eye"} size={20} color="gray" />
|
||||
<Feather
|
||||
name={showPassword ? "eye-off" : "eye"}
|
||||
size={20}
|
||||
color="gray"
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<TouchableOpacity
|
||||
|
||||
<TouchableOpacity
|
||||
className="bg-[#ffd60a] py-4 rounded-xl mt-6"
|
||||
onPress={handleSignup}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<Text className="text-center font-bold text-lg">
|
||||
{isLoading ? 'Signing up...' : 'Sign Up'}
|
||||
{isLoading ? "Signing up..." : "Sign Up"}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
|
||||
{/* Login Link */}
|
||||
<View className="flex-row justify-center mt-8 mb-4">
|
||||
<Text className="text-gray-600">Already have an account? </Text>
|
||||
<TouchableOpacity onPress={() => router.push('/login')}>
|
||||
<TouchableOpacity onPress={() => router.push("/login")}>
|
||||
<Text className="text-[#bb0718] font-medium">Login</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
@ -138,4 +157,4 @@ export default function SignupScreen() {
|
||||
</ScrollView>
|
||||
</SafeAreaView>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user