Skip to content

Commit

Permalink
feat: ✨ 로그인 후 username 렌더링
Browse files Browse the repository at this point in the history
  • Loading branch information
JAM-PARK committed Jan 12, 2025
1 parent f47af45 commit 88f05ec
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/reaction-speed-test/app/(pages)/measurement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const Measurement: FC = () => {
</Button>
<Button
className="w-40 bg-slate-500"
onPress={() => router.push("/")}
onPress={() => router.push("/menu")}
>
<ButtonText>홈으로 가기</ButtonText>
</Button>
Expand Down
53 changes: 53 additions & 0 deletions apps/reaction-speed-test/app/(pages)/menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { supabase } from "@/utils/supabase";
import { Link, Stack } from "expo-router";
import { useEffect, useState } from "react";
import { SafeAreaView, Text, View } from "react-native";

export default function MenuScreen() {
const [username, setUsername] = useState<string | null>(null);

useEffect(() => {
(async () => {
try {
const {
data: { user },
} = await supabase.auth.getUser();
if (user) {
const { data: profileData } = await supabase
.from("profiles")
.select("username")
.eq("id", user.id)
.single();

if (profileData) {
setUsername(profileData.username);
}
}
} catch (error) {
console.error("Error fetching username:", error);
}
})();
}, []);

return (
<View className="flex-1 items-center justify-center">
<Stack.Screen options={{ title: "메뉴 페이지", headerShown: false }} />
<SafeAreaView className="h-full">
<View className="flex-auto items-center justify-center gap-y-10">
<Text className="text-lg dark:text-gray-50">
{`${username || "이름"}님 반갑습니다!`}
</Text>
<Link href={{ pathname: "./measurement" }}>
<Text className="dark:text-gray-50">시작하기</Text>
</Link>
<Link href={{ pathname: "./results" }}>
<Text className="dark:text-gray-50">기록보기</Text>
</Link>
<Link href={{ pathname: "./settings" }}>
<Text className="dark:text-gray-50">설정</Text>
</Link>
</View>
</SafeAreaView>
</View>
);
}
4 changes: 1 addition & 3 deletions apps/reaction-speed-test/components/login/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ export default function LoginForm() {
}
return;
}

// 로그인 성공 시 홈 또는 지정된 페이지로 이동
router.replace("/");
router.replace("/menu");
} catch (error) {
console.error("로그인 중 문제가 발생했습니다", error);
} finally {
Expand Down

0 comments on commit 88f05ec

Please sign in to comment.