Skip to content

Commit c3ab67c

Browse files
authored
Merge pull request #13 from JECT-Study/feat/kakao-login
splash, app icon, login
2 parents fba71a9 + a62328b commit c3ab67c

17 files changed

Lines changed: 343 additions & 56 deletions

File tree

app.config.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
owner: "scorchedrice",
77
version: "1.0.0",
88
orientation: "portrait",
9-
icon: "./assets/images/icon.png",
9+
icon: "./assets/mycode_icon.png",
1010
scheme: "mycode",
1111
userInterfaceStyle: "automatic",
1212
newArchEnabled: true,
@@ -15,6 +15,7 @@ export default {
1515
supportsTablet: true,
1616
usesAppleSignIn: true,
1717
bundleIdentifier: process.env.MYCODE_BUNDLE_IDENTIFIER,
18+
// bundleIdentifier: process.env.MYCODE_SERVICE_IDENTIFIER,
1819
infoPlist: {
1920
LSApplicationQueriesSchemes: [
2021
"kakaokompassauth",
@@ -52,10 +53,10 @@ export default {
5253
[
5354
"expo-splash-screen",
5455
{
55-
image: "./assets/images/splash-icon.png",
56+
image: "./assets/images/mycode_splash.png",
5657
imageWidth: 200,
5758
resizeMode: "contain",
58-
backgroundColor: "#ffffff",
59+
backgroundColor: "#111111",
5960
},
6061
],
6162
[
@@ -104,6 +105,7 @@ export default {
104105

105106
extra: {
106107
kakaoNativeAppKey: process.env.MYCODE_KAKAO_NATIVE_APP_KEY,
108+
kakaoWebAppKey: process.env.MYCODE_KAKAO_REST_API_KEY,
107109
BACKEND_URL: process.env.MYCODE_BACKEND_URL,
108110
NAVER_MAP_CLIENT_ID: process.env.NAVER_MAP_CLIENT_ID,
109111
eas: {

app/(tabs)/my/like.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default function Like() {
1717
const [infodummy, setInfodummy] = useState(DUMMY_EVENT_POSTS);
1818
const selected = useCategorySelected();
1919

20-
// TODO : api test
20+
// TODO : api test, 에러로 확인 필요.
2121
useEffect(() => {
2222
const fetchResult = async () => {
2323
try {

app/(tabs)/my/plan.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
1+
import { useEffect } from "react";
2+
3+
import axios, { AxiosError } from "axios";
14
import { router } from "expo-router";
25
import { SafeAreaView, View, Text } from "react-native";
36

47
import CustomHeader from "@/components/ui/CustomHeader";
8+
import { UsersScheduleUrl } from "@/constants/ApiUrls";
59

610
export default function Plan() {
11+
useEffect(() => {
12+
const getSchedule = async () => {
13+
try {
14+
const response = await axios(`${UsersScheduleUrl}/check`, {
15+
params: {
16+
month: "2025-06", // TODO: 실제 날짜로 변경
17+
},
18+
});
19+
console.log(response);
20+
} catch (e) {
21+
const axiosError = e as AxiosError;
22+
console.error(axiosError);
23+
}
24+
};
25+
getSchedule();
26+
// test
27+
}, []);
28+
729
return (
830
<>
931
<SafeAreaView className="w-full flex-1 bg-white">

app/_layout.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,35 @@ import {
88
import Constants from "expo-constants";
99
import { useFonts } from "expo-font";
1010
import { Stack } from "expo-router";
11+
import * as SplashScreen from "expo-splash-screen";
1112
import { StatusBar } from "expo-status-bar";
1213
import { View } from "react-native";
1314
import { GestureHandlerRootView } from "react-native-gesture-handler";
1415
import "react-native-reanimated";
1516

1617
import { useColorScheme } from "@/hooks/useColorScheme";
1718

19+
import { useEffect } from "react";
20+
21+
SplashScreen.setOptions({
22+
duration: 1000,
23+
fade: true,
24+
});
25+
26+
SplashScreen.preventAutoHideAsync();
27+
1828
export default function RootLayout() {
1929
const colorScheme = useColorScheme();
2030
const [loaded] = useFonts({
2131
SpaceMono: require("../assets/fonts/SpaceMono-Regular.ttf"),
2232
});
2333

34+
useEffect(() => {
35+
if (loaded) {
36+
SplashScreen.hideAsync();
37+
}
38+
}, [loaded]);
39+
2440
if (!loaded) {
2541
// Async font loading only occurs in development.
2642
return null;

app/index.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
1+
import { useEffect } from "react";
2+
3+
import { useRouter } from "expo-router";
4+
import * as SecureStore from "expo-secure-store";
15
import { View, Text } from "react-native";
26

37
import LoginCardSlider from "@/components/login/LoginCardSlider";
48
import SocialLoginButtons from "@/components/login/SocialLoginButtons";
59

610
export default function Login() {
11+
const router = useRouter();
12+
13+
useEffect(() => {
14+
const checkTokens = async () => {
15+
console.log("토큰 확인 - useEffect 실행됨");
16+
const storeAccessToken = await SecureStore.getItemAsync("accessToken");
17+
const storeRefreshToken = await SecureStore.getItemAsync("refreshToken");
18+
console.log("토큰 상태:", { storeAccessToken, storeRefreshToken });
19+
if (storeAccessToken && storeRefreshToken) {
20+
console.log("토큰 존재 - 탭으로 이동");
21+
router.replace("/(tabs)");
22+
} else {
23+
console.log("토큰 없음 - 로그인 화면 유지");
24+
}
25+
};
26+
27+
checkTokens();
28+
}); // 의존성 배열 없음 - 매 렌더링마다 실행
29+
730
return (
831
<View className="flex-1 items-center bg-black">
932
<LoginCardSlider />

assets/images/mycode_splash.png

4.31 KB
Loading

assets/mycode_icon.png

1.26 KB
Loading

components/login/KakaoLogin.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
11
import { useEffect } from "react";
22

33
import { initializeKakaoSDK } from "@react-native-kakao/core";
4-
import { login } from "@react-native-kakao/user";
4+
import { login, me } from "@react-native-kakao/user";
55
import Constants from "expo-constants";
6+
import { router } from "expo-router";
7+
import * as SecureStore from "expo-secure-store";
68
import { Pressable, Text } from "react-native";
79

810
import KakaoIcon from "@/components/icons/KakaoIcon";
11+
import { LoginUrl } from "@/constants/ApiUrls";
12+
import { publicApi } from "@/features/axios/axiosInstance";
913

1014
export default function KakaoLogin() {
1115
const kakaoNativeAppKey =
1216
Constants.expoConfig?.extra?.kakaoNativeAppKey ?? "";
17+
1318
useEffect(() => {
1419
initializeKakaoSDK(kakaoNativeAppKey);
1520
}, [kakaoNativeAppKey]);
1621

17-
// TODO : 추후 로그인 기능 관련 논의 필요
1822
async function kakaoLogin() {
1923
try {
20-
const res = await login();
21-
console.log(res);
24+
await login();
25+
const profile = await me();
26+
const id = profile.id;
27+
28+
const response = await publicApi.post(LoginUrl, {
29+
socialId: id,
30+
socialType: "KAKAO",
31+
});
32+
const accessToken = response.data.result.accessToken;
33+
const refreshToken = response.data.result.refreshToken;
34+
await SecureStore.setItemAsync("accessToken", accessToken);
35+
await SecureStore.setItemAsync("refreshToken", refreshToken);
36+
router.push("/(tabs)");
2237
} catch (error) {
23-
console.log(error);
38+
// 카카오 로그인 취소 시에는 에러 메시지를 표시하지 않음
39+
console.log("카카오 로그인 취소 또는 에러:", error);
2440
}
2541
}
2642

components/login/SocialLoginButtons.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { LinearGradient } from "expo-linear-gradient";
22
import { router } from "expo-router";
3-
import { Pressable, Text, View } from "react-native";
3+
import { Platform, Pressable, Text, View } from "react-native";
44
import { useSafeAreaInsets } from "react-native-safe-area-context";
55

66
import AppleLogin from "@/components/login/AppleLogin";
77
import KakaoLogin from "@/components/login/KakaoLogin";
88

99
export default function SocialLoginButtons() {
1010
const insets = useSafeAreaInsets();
11+
const isIOS = Platform.OS === "ios";
1112
return (
1213
<View className="w-full">
1314
<LinearGradient
@@ -21,7 +22,7 @@ export default function SocialLoginButtons() {
2122
<View className="w-full items-center">
2223
<KakaoLogin />
2324
<View className="my-2" />
24-
<AppleLogin />
25+
{isIOS ? <AppleLogin /> : null}
2526
</View>
2627
<Pressable
2728
onPress={() => router.push("/(tabs)")}

components/mypage/MyPageMenus.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
import { AxiosError } from "axios";
2+
import { router } from "expo-router";
3+
import * as SecureStore from "expo-secure-store";
14
import { Alert, View } from "react-native";
25

36
import MyPageMenu from "@/components/mypage/MyPageMenu";
7+
import { LogoutUrl } from "@/constants/ApiUrls";
8+
import { authApi } from "@/features/axios/axiosInstance";
49
import usePageNavigation from "@/hooks/usePageNavigation";
510

6-
const handleLogout = () => {
11+
const handleLogout = async () => {
712
Alert.alert(
813
"로그아웃", // 타이틀
914
"정말 로그아웃 하시겠어요?", // 메시지
@@ -14,9 +19,19 @@ const handleLogout = () => {
1419
},
1520
{
1621
text: "로그아웃",
17-
onPress: () => {
18-
// TODO 실제 로그아웃 로직
19-
console.log("로그아웃!");
22+
onPress: async () => {
23+
try {
24+
// await authApi.post(LogoutUrl);
25+
await SecureStore.deleteItemAsync("accessToken");
26+
await SecureStore.deleteItemAsync("refreshToken");
27+
alert("로그아웃이 완료되었습니다.");
28+
29+
router.dismissAll();
30+
router.push("/");
31+
} catch (error) {
32+
const axiosError = error as AxiosError;
33+
alert(`로그아웃 도중 에러가 발생했습니다. ${axiosError.message}`);
34+
}
2035
},
2136
style: "default",
2237
},

0 commit comments

Comments
 (0)