Skip to content

Commit

Permalink
feat ios kakao login
Browse files Browse the repository at this point in the history
  • Loading branch information
Siby1lA committed Sep 1, 2023
1 parent 9bd070f commit da4ee46
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 43 deletions.
143 changes: 104 additions & 39 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,122 @@
import React from "react";
import { Button, StyleSheet, Text, View } from "react-native";
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native";
import React, { useState } from "react";
import {
login,
logout,
getProfile as getKakaoProfile,
shippingAddresses as getKakaoShippingAddresses,
unlink,
} from "@react-native-seoul/kakao-login";

export type Props = {
name: string;
baseEnthusiasmLevel?: number;
};
const App = () => {
const [result, setResult] = useState<string>("");

const signInWithKakao = async (): Promise<void> => {
try {
const token = await login();
setResult(JSON.stringify(token));
} catch (err) {
console.error("login err", err);
}
};

const signOutWithKakao = async (): Promise<void> => {
try {
const message = await logout();

setResult(message);
} catch (err) {
console.error("signOut error", err);
}
};

const getProfile = async (): Promise<void> => {
try {
const profile = await getKakaoProfile();

setResult(JSON.stringify(profile));
} catch (err) {
console.error("signOut error", err);
}
};

const getShippingAddresses = async (): Promise<void> => {
try {
const shippingAddresses = await getKakaoShippingAddresses();

const App: React.FC<Props> = ({ name, baseEnthusiasmLevel = 0 }) => {
const [enthusiasmLevel, setEnthusiasmLevel] =
React.useState(baseEnthusiasmLevel);
setResult(JSON.stringify(shippingAddresses));
} catch (err) {
console.error("signOut error", err);
}
};

const onIncrement = () => setEnthusiasmLevel(enthusiasmLevel + 1);
const onDecrement = () =>
setEnthusiasmLevel(enthusiasmLevel > 0 ? enthusiasmLevel - 1 : 0);
const unlinkKakao = async (): Promise<void> => {
try {
const message = await unlink();

const getExclamationMarks = (numChars: number) =>
numChars > 0 ? Array(numChars + 1).join("!") : "";
setResult(message);
} catch (err) {
console.error("signOut error", err);
}
};

return (
<View style={styles.container}>
<Text style={styles.greeting}>
Hello {name}
{getExclamationMarks(enthusiasmLevel)}
</Text>
<View>
<Button
title="Increase enthusiasm"
accessibilityLabel="increment"
onPress={onIncrement}
color="blue"
/>
<Button
title="Decrease enthusiasm"
accessibilityLabel="decrement"
onPress={onDecrement}
color="red"
/>
<View style={styles.resultContainer}>
<ScrollView>
<Text>{result}</Text>
<View style={{ height: 100 }} />
</ScrollView>
</View>
<Pressable
style={styles.button}
onPress={() => {
signInWithKakao();
}}
>
<Text style={styles.text}>카카오 로그인</Text>
</Pressable>
<Pressable style={styles.button} onPress={() => getProfile()}>
<Text style={styles.text}>프로필 조회</Text>
</Pressable>
<Pressable style={styles.button} onPress={() => getShippingAddresses()}>
<Text style={styles.text}>배송주소록 조회</Text>
</Pressable>
<Pressable style={styles.button} onPress={() => unlinkKakao()}>
<Text style={styles.text}>링크 해제</Text>
</Pressable>
<Pressable style={styles.button} onPress={() => signOutWithKakao()}>
<Text style={styles.text}>카카오 로그아웃</Text>
</Pressable>
</View>
);
};

export default App;

const styles = StyleSheet.create({
container: {
flex: 1,
height: "100%",
justifyContent: "flex-end",
alignItems: "center",
justifyContent: "center",
paddingBottom: 100,
},
resultContainer: {
flexDirection: "column",
width: "100%",
padding: 24,
},
greeting: {
fontSize: 20,
fontWeight: "bold",
margin: 16,
button: {
backgroundColor: "#FEE500",
borderRadius: 40,
borderWidth: 1,
width: 250,
height: 40,
paddingHorizontal: 20,
paddingVertical: 10,
marginTop: 10,
},
text: {
textAlign: "center",
},
});

export default App;
29 changes: 29 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PODS:
- Alamofire (5.7.1)
- boost (1.76.0)
- DoubleConversion (1.1.6)
- EXApplication (5.3.0):
Expand Down Expand Up @@ -49,6 +50,22 @@ PODS:
- hermes-engine (0.72.4):
- hermes-engine/Pre-built (= 0.72.4)
- hermes-engine/Pre-built (0.72.4)
- kakao-login (5.3.0):
- KakaoSDKAuth (= 2.11.1)
- KakaoSDKCommon (= 2.11.1)
- KakaoSDKUser (= 2.11.1)
- React
- KakaoSDKAuth (2.11.1):
- KakaoSDKCommon (= 2.11.1)
- KakaoSDKCommon (2.11.1):
- KakaoSDKCommon/Common (= 2.11.1)
- KakaoSDKCommon/Network (= 2.11.1)
- KakaoSDKCommon/Common (2.11.1)
- KakaoSDKCommon/Network (2.11.1):
- Alamofire (~> 5.1)
- KakaoSDKCommon/Common (= 2.11.1)
- KakaoSDKUser (2.11.1):
- KakaoSDKAuth (= 2.11.1)
- libevent (2.1.12)
- PromisesObjC (2.3.1)
- RCT-Folly (2021.07.22.00):
Expand Down Expand Up @@ -482,6 +499,7 @@ DEPENDENCIES:
- FBReactNativeSpec (from `../node_modules/react-native/React/FBReactNativeSpec`)
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
- hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
- "kakao-login (from `../node_modules/@react-native-seoul/kakao-login`)"
- libevent (~> 2.1.12)
- RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)
- RCTRequired (from `../node_modules/react-native/Libraries/RCTRequired`)
Expand Down Expand Up @@ -521,11 +539,15 @@ DEPENDENCIES:

SPEC REPOS:
trunk:
- Alamofire
- Firebase
- FirebaseCore
- FirebaseCoreInternal
- fmt
- GoogleUtilities
- KakaoSDKAuth
- KakaoSDKCommon
- KakaoSDKUser
- libevent
- PromisesObjC
- SocketRocket
Expand Down Expand Up @@ -560,6 +582,8 @@ EXTERNAL SOURCES:
hermes-engine:
:podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec"
:tag: hermes-2023-08-07-RNv0.72.4-813b2def12bc9df02654b3e3653ae4a68d0572e0
kakao-login:
:path: "../node_modules/@react-native-seoul/kakao-login"
RCT-Folly:
:podspec: "../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec"
RCTRequired:
Expand Down Expand Up @@ -630,6 +654,7 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/yoga"

SPEC CHECKSUMS:
Alamofire: 0123a34370cb170936ae79a8df46cc62b2edeb88
boost: 57d2868c099736d80fcd648bf211b4431e51a558
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
EXApplication: 02655a251434d564bb0e73291f5a490c74b5b76f
Expand All @@ -649,6 +674,10 @@ SPEC CHECKSUMS:
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
GoogleUtilities: 13e2c67ede716b8741c7989e26893d151b2b2084
hermes-engine: 81191603c4eaa01f5e4ae5737a9efcf64756c7b2
kakao-login: 3d7afeb8d49d4fa9a3ee579edb1b68c65bf20dac
KakaoSDKAuth: bb2dfa7be30daa8403c9cfc8001aa6fde7a5b779
KakaoSDKCommon: 555e1bb46595b842ded01cf7888cc17bbae4e113
KakaoSDKUser: 08c0a4f40bebdebdf948a9e3d0e44ed5c2754f99
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
PromisesObjC: c50d2056b5253dadbd6c2bea79b0674bd5a52fa4
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
Expand Down
8 changes: 8 additions & 0 deletions ios/SwiftBridge.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// SwiftBridge.swift
// reactnativefirebase
//
// Created by Subin on 2023/09/01.
//

import Foundation
6 changes: 6 additions & 0 deletions ios/reactnativefirebase.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
3E461D99554A48A4959DE609 /* SplashScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AA286B85B6C04FC6940260E9 /* SplashScreen.storyboard */; };
49DC11E02AA0D87E0028BD91 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 49DC11DF2AA0D87D0028BD91 /* GoogleService-Info.plist */; };
49DC11E52AA1C6810028BD91 /* SwiftBridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49DC11E42AA1C6810028BD91 /* SwiftBridge.swift */; };
9FBB96B857FC5539366DCC37 /* Pods_reactnativefirebase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EB7E0079442A524A54723E8E /* Pods_reactnativefirebase.framework */; };
B18059E884C0ABDD17F3DC3D /* ExpoModulesProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC715A2D49A985799AEE119 /* ExpoModulesProvider.swift */; };
BB2F792D24A3F905000567C9 /* Expo.plist in Resources */ = {isa = PBXBuildFile; fileRef = BB2F792C24A3F905000567C9 /* Expo.plist */; };
Expand All @@ -25,6 +26,7 @@
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = reactnativefirebase/Info.plist; sourceTree = "<group>"; };
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = reactnativefirebase/main.m; sourceTree = "<group>"; };
49DC11DF2AA0D87D0028BD91 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
49DC11E42AA1C6810028BD91 /* SwiftBridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftBridge.swift; sourceTree = "<group>"; };
6C2E3173556A471DD304B334 /* Pods-reactnativefirebase.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-reactnativefirebase.debug.xcconfig"; path = "Target Support Files/Pods-reactnativefirebase/Pods-reactnativefirebase.debug.xcconfig"; sourceTree = "<group>"; };
7A4D352CD337FB3A3BF06240 /* Pods-reactnativefirebase.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-reactnativefirebase.release.xcconfig"; path = "Target Support Files/Pods-reactnativefirebase/Pods-reactnativefirebase.release.xcconfig"; sourceTree = "<group>"; };
AA286B85B6C04FC6940260E9 /* SplashScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = SplashScreen.storyboard; path = reactnativefirebase/SplashScreen.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -57,6 +59,7 @@
13B07FB61A68108700A75B9A /* Info.plist */,
13B07FB71A68108700A75B9A /* main.m */,
AA286B85B6C04FC6940260E9 /* SplashScreen.storyboard */,
49DC11E42AA1C6810028BD91 /* SwiftBridge.swift */,
);
name = reactnativefirebase;
sourceTree = "<group>";
Expand Down Expand Up @@ -341,6 +344,7 @@
files = (
13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */,
13B07FC11A68108700A75B9A /* main.m in Sources */,
49DC11E52AA1C6810028BD91 /* SwiftBridge.swift in Sources */,
B18059E884C0ABDD17F3DC3D /* ExpoModulesProvider.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -355,6 +359,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = K6CUWBN4AM;
ENABLE_BITCODE = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
Expand Down Expand Up @@ -388,6 +393,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = K6CUWBN4AM;
INFOPLIST_FILE = reactnativefirebase/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
20 changes: 16 additions & 4 deletions ios/reactnativefirebase/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#import <React/RCTLinkingManager.h>

#import <Firebase.h>
#import <RNKakaoLogins.h>

@implementation AppDelegate

Expand All @@ -28,10 +29,21 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
}

// Linking API
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {

[FIRApp configure];
return [super application:application openURL:url options:options] || [RCTLinkingManager application:application openURL:url options:options];
//- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
//
// [FIRApp configure];
// return [super application:application openURL:url options:options] || [RCTLinkingManager application:application openURL:url options:options];
//}

// kakao
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
if([RNKakaoLogins isKakaoTalkLoginUrl:url]) {
return [RNKakaoLogins handleOpenUrl: url];
}

return NO;
}

// Universal Links
Expand Down
20 changes: 20 additions & 0 deletions ios/reactnativefirebase/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,28 @@
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>kakao57d57082a5f5c39156a2510a61729f7d</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>KAKAO_APP_KEY</key>
<string>57d57082a5f5c39156a2510a61729f7d</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>kakao0123456789</string>
<string>kakaokompassauth</string>
<string>storykompassauth</string>
<string>kakaolink</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@react-native-firebase/app": "^18.3.1",
"@react-native-seoul/kakao-login": "^5.3.0",
"expo": "~49.0.8",
"expo-splash-screen": "~0.20.5",
"expo-status-bar": "~1.6.0",
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,13 @@
opencollective-postinstall "^2.0.1"
superstruct "^0.6.2"

"@react-native-seoul/kakao-login@^5.3.0":
version "5.3.0"
resolved "https://registry.yarnpkg.com/@react-native-seoul/kakao-login/-/kakao-login-5.3.0.tgz#1c0cf2ecb9f8e7f7dc7adaa12167a843d957573a"
integrity sha512-f0srcY39rFnPxj9+OEJirDXKl+5KPfw48o8CzVPQCJh6tcf9OgWK5yj4lJ28wmxMxDc4RSxSPvTWJ/HnTJPi5w==
dependencies:
dooboolab-welcome "^1.3.2"

"@react-native/assets-registry@^0.72.0":
version "0.72.0"
resolved "https://registry.yarnpkg.com/@react-native/assets-registry/-/assets-registry-0.72.0.tgz#c82a76a1d86ec0c3907be76f7faf97a32bbed05d"
Expand Down Expand Up @@ -2979,6 +2986,11 @@ dir-glob@^3.0.1:
dependencies:
path-type "^4.0.0"

dooboolab-welcome@^1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/dooboolab-welcome/-/dooboolab-welcome-1.3.2.tgz#4928595312f0429b4ea1b485ba8767bae6acdab7"
integrity sha512-2NbMaIIURElxEf/UAoVUFlXrO+7n/FRhLCiQlk4fkbGRh9cJ3/f8VEMPveR9m4Ug2l2Zey+UCXjd6EcBqHJ5bw==

dotenv-expand@~10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-10.0.0.tgz#12605d00fb0af6d0a592e6558585784032e4ef37"
Expand Down

0 comments on commit da4ee46

Please sign in to comment.