native-kakao-login
v0.2.0
Published
kakao login modules for react native
Downloads
18
Readme
native-kakao-login
installation
1. iOS
first, add package and install pods
$ yarn add native-kakao-login
$ cd ios
$ pod install
and open .xcworkspace file
go to info.plist
add this two lines
<key>LSApplicationQueriesSchemes</key>
<array>
<!-- 카카오톡으로 로그인 -->
<string>kakaokompassauth</string>
<!-- 카카오링크 -->
<string>kakaolink</string>
</array>
go to URL Schemes in xcode (target -> info -> URL Types) add URL Schemes like this
kakao{KAKAO_APP_KEY}://oauth // ex) kakao12345678://oauth
and go to developer kakao site, add iOS platform with bundle ID
make this file KakaoLoginUtil.swift
import KakaoSDKAuth
import KakaoSDKCommon
@objc
class KakaoLoginUtil: NSObject {
@objc
static func initKakaoSDK() -> Void {
KakaoSDKCommon.initSDK(appKey: "{YOUR_KAKAO_APP_KEY}") // without kakao prefix, ex) 12345678abcde
}
@objc
static func handleOpenUrl(url: URL) -> Bool {
if (AuthApi.isKakaoTalkLoginUrl(url)) {
return AuthController.handleOpenUrl(url: url)
}
return false
}
}
AppDelegate.m
#import "{PLATFORM_NAME}-Swift.h"
...
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
return [KakaoLoginUtil handleOpenUrlWithUrl:url];
}
...
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#ifdef FB_SONARKIT_ENABLED
InitializeFlipper(application);
#endif
...
// add this line
[KakaoLoginUtil initKakaoSDK];
return YES;
}
2. android
open build.gradle(.)
// add this line
maven { url 'https://devrepo.kakao.com/nexus/content/groups/public/' }
open build.gradle(app)
// add this line
implementation "com.kakao.sdk:v2-user:2.5.0" // 카카오 로그인
make KakaoLoginUtil.java
package com.morearttopeople;
import android.content.Context;
import com.kakao.sdk.common.KakaoSdk;
public class KakaoLoginUtil {
public static void initKakaoSDK(Context context) {
KakaoSdk.init(context, "{NATIVE_APP_KEY}"); // without "kakao"prefix, ex) 123456678abcde
}
}
go to MainApplication.java
@Override
public void onCreate() {
super.onCreate();
// add this line
KakaoLoginUtil.initKakaoSDK(this);
}
open AndroidManifest.xml
and add this xml codes inside application xml
<activity android:name=“com.kakao.sdk.auth.AuthCodeHandlerActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Redirect URI: "kakao{NATIVE_APP_KEY}“ -->
<data android:host="oauth"
android:scheme="kakao{NATIVE_APP_KEY}" />
</intent-filter>
</activity>
in kakao developer site, set android platform
how to use
- login
import KakaoLogin from "native-kakao-login";
const login = async () => {
try {
const result = await KakaoLogin.login();
} catch (e) {
console.error(e)
}
}
- getProfile
import KakaoLogin from "native-kakao-login";
const getProfile = async () => {
try {
const result = await KakaoLogin.getProfile();
} catch (e) {
console.error(e)
}
}
- logout
import KakaoLogin from "native-kakao-login";
const logout = async () => {
try {
const result = await KakaoLogin.logout();
} catch (e) {
console.error(e)
}
}
- unlink
import KakaoLogin from "native-kakao-login";
const unlink = async () => {
try {
const result = await KakaoLogin.unlink();
} catch (e) {
console.error(e)
}
}
- getAccessTokenInfo
import KakaoLogin from "native-kakao-login";
const getAccessTokenInfo = async () => {
try {
const result = await KakaoLogin.getAccessTokenInfo();
} catch (e) {
console.error(e)
}
}