From af86ac101cef40773138d6e901720c3f75edae9c Mon Sep 17 00:00:00 2001 From: Jakub Satora Date: Tue, 24 Sep 2024 19:42:33 +0200 Subject: [PATCH] user section implemented --- app/(auth)/sign-in.tsx | 33 ++++++++++-- app/(root)/(tabs)/_layout.tsx | 95 +++++++++++++++++++++++++++++++++++ app/(root)/(tabs)/home.tsx | 3 ++ app/(root)/_layout.tsx | 14 ++++++ app/_layout.tsx | 3 +- 5 files changed, 143 insertions(+), 5 deletions(-) diff --git a/app/(auth)/sign-in.tsx b/app/(auth)/sign-in.tsx index d519da6..34f450d 100644 --- a/app/(auth)/sign-in.tsx +++ b/app/(auth)/sign-in.tsx @@ -1,4 +1,4 @@ -import { Link, router } from "expo-router"; +import { Link, router, useRouter } from "expo-router"; import { useState } from "react"; import { Alert, Image, ScrollView, Text, View } from "react-native"; @@ -6,15 +6,40 @@ import CustomButton from "@/components/CustomButton"; import InputField from "@/components/InputField"; import { icons, images } from "@/constants"; import OAuth from "@/components/OAuth"; +import { useSignIn } from "@clerk/clerk-expo"; +import React from "react"; const SignIn = () => { const [form, setForm] = useState({ email: '', password: '', }) - const onSignInPress = async () => { + const { signIn, setActive, isLoaded } = useSignIn() + const router = useRouter() + const onSignInPress = React.useCallback(async () => { + if (!isLoaded) { + return + } + + try { + const signInAttempt = await signIn.create({ + identifier: form.email, + password: form.password, + }) + + if (signInAttempt.status === 'complete') { + await setActive({ session: signInAttempt.createdSessionId }) + router.replace('/') + } else { + // See https://clerk.com/docs/custom-flows/error-handling + // for more info on error handling + console.error(JSON.stringify(signInAttempt, null, 2)) + } + } catch (err: any) { + console.error(JSON.stringify(err, null, 2)) + } + }, [isLoaded, form.email, form.password]) - } return ( @@ -43,7 +68,7 @@ const SignIn = () => { onChangeText={(value) => setForm({ ...form, password: value })} /> - + diff --git a/app/(root)/(tabs)/_layout.tsx b/app/(root)/(tabs)/_layout.tsx index e69de29..462fbda 100644 --- a/app/(root)/(tabs)/_layout.tsx +++ b/app/(root)/(tabs)/_layout.tsx @@ -0,0 +1,95 @@ +import { Tabs } from "expo-router"; +import { Image, ImageSourcePropType, View } from "react-native"; + +import { icons } from "@/constants"; + +const TabIcon = ({ + source, + focused, +}: { + source: ImageSourcePropType; + focused: boolean; +}) => ( + + + + + +); + +export default function Layout() { + return ( + + ( + + ), + }} + /> + ( + + ), + }} + /> + ( + + ), + }} + /> + ( + + ), + }} + /> + + ); +} \ No newline at end of file diff --git a/app/(root)/(tabs)/home.tsx b/app/(root)/(tabs)/home.tsx index fce8413..b1d3bdc 100644 --- a/app/(root)/(tabs)/home.tsx +++ b/app/(root)/(tabs)/home.tsx @@ -1,11 +1,13 @@ import { SignedIn, SignedOut, useUser } from '@clerk/clerk-expo' import { Link } from 'expo-router' import { Text, View } from 'react-native' +import { SafeAreaView } from 'react-native-safe-area-context' export default function Page() { const { user } = useUser() return ( + Hello {user?.emailAddresses[0].emailAddress} @@ -19,5 +21,6 @@ export default function Page() { + ) } \ No newline at end of file diff --git a/app/(root)/_layout.tsx b/app/(root)/_layout.tsx index e69de29..d191dc1 100644 --- a/app/(root)/_layout.tsx +++ b/app/(root)/_layout.tsx @@ -0,0 +1,14 @@ +import { Stack } from 'expo-router'; +import 'react-native-reanimated'; + + +const Layout=()=> { + + return ( + + + + ); +} + +export default Layout; \ No newline at end of file diff --git a/app/_layout.tsx b/app/_layout.tsx index a0b7092..472de01 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -6,6 +6,7 @@ import 'react-native-reanimated'; import { ClerkProvider, ClerkLoaded } from '@clerk/clerk-expo' import { Slot } from 'expo-router' +import { tokenCache } from '@/lib/auth'; const publishableKey = process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY! @@ -43,7 +44,7 @@ export default function RootLayout() { } return ( - +