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