From 2ef61cca470c0f1b49e56a75796496eb2aa83f75 Mon Sep 17 00:00:00 2001 From: comst19 Date: Thu, 11 Jan 2024 15:54:49 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20KaKao=20Login=20=EA=B5=AC=ED=98=84=20-?= =?UTF-8?q?=20=EB=AA=A8=EB=93=88=ED=99=94=20=ED=95=84=EC=9A=94,=20?= =?UTF-8?q?=EC=84=9C=EB=B2=84=20=EC=97=B0=EA=B2=B0=20=ED=95=84=EC=9A=94=20?= =?UTF-8?q?/=20#ARCH-22?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/ARchive/app/build.gradle | 12 ++++++ .../ARchive/app/src/main/AndroidManifest.xml | 11 +++++ .../archive/ARchiveApplication.kt | 9 +++- .../presentation/ui/auth/SignInFragment.kt | 43 ++++++++++++++++++- .../presentation/ui/splash/SplashActivity.kt | 4 +- frontend/ARchive/settings.gradle | 1 + 6 files changed, 77 insertions(+), 3 deletions(-) diff --git a/frontend/ARchive/app/build.gradle b/frontend/ARchive/app/build.gradle index 49b9f73da..5457dfd27 100644 --- a/frontend/ARchive/app/build.gradle +++ b/frontend/ARchive/app/build.gradle @@ -6,6 +6,9 @@ plugins { id 'dagger.hilt.android.plugin' } +Properties properties = new Properties() +properties.load(project.rootProject.file('local.properties').newDataInputStream()) + android { namespace 'com.droidblossom.archive' compileSdk 33 @@ -18,6 +21,11 @@ android { versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + buildConfigField "String", "KAKAO_NATIVE_APP_KEY", properties['kakao_native_app_key'] + + manifestPlaceholders["KAKAO_NATIVE_APP_KEY"] = + properties.getProperty("kakao_native_app_key_no_quotes") } buildTypes { @@ -36,6 +44,7 @@ android { buildFeatures{ dataBinding = true viewBinding = true + buildConfig = true } } @@ -106,6 +115,9 @@ dependencies { // SMS Retriever API implementation 'com.google.android.gms:play-services-auth:20.7.0' implementation 'com.google.android.gms:play-services-auth-api-phone:18.0.1' + + // KaKao + implementation "com.kakao.sdk:v2-user:2.12.1" } kapt { correctErrorTypes true diff --git a/frontend/ARchive/app/src/main/AndroidManifest.xml b/frontend/ARchive/app/src/main/AndroidManifest.xml index 9b592e6ee..87ca48aa5 100644 --- a/frontend/ARchive/app/src/main/AndroidManifest.xml +++ b/frontend/ARchive/app/src/main/AndroidManifest.xml @@ -17,6 +17,17 @@ android:theme="@style/Theme.ARchive" android:usesCleartextTraffic="true" tools:targetApi="31"> + + + + + + + + + (R.l override val viewModel : AuthViewModelImpl by activityViewModels() + private val mCallback: (OAuthToken?, Throwable?) -> Unit = { token, error -> + if (error != null) { + Log.e("카카오", "로그인 실패 $error") + } else if (token != null) { + Log.e("카카오", "로그인 성공 ${token.accessToken}") + } + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) navController = Navigation.findNavController(view) binding.kakaoLoginBtn.setOnClickListener { - viewModel.signInToSignUp() + //viewModel.signInToSignUp() + //kakaoLogin() } binding.googleLoginBtn.setOnClickListener { @@ -48,6 +63,32 @@ class SignInFragment : BaseFragment(R.l } } } + } + private fun kakaoLogin(){ + // 카카오톡 설치 확인 + if (UserApiClient.instance.isKakaoTalkLoginAvailable(requireContext())) { + // 카카오톡 로그인 + UserApiClient.instance.loginWithKakaoTalk(requireContext()) { token, error -> + // 로그인 실패 부분 + if (error != null) { + Log.e("카카오", "로그인 실패 $error") + // 사용자가 취소 + if (error is ClientError && error.reason == ClientErrorCause.Cancelled ) { + return@loginWithKakaoTalk + } + // 다른 오류 + else { + UserApiClient.instance.loginWithKakaoAccount(requireContext(), callback = mCallback) // 카카오 이메일 로그인 + } + } + // 로그인 성공 부분 + else if (token != null) { + Log.e("카카오", "로그인 성공 ${token.accessToken}") + } + } + } else { + UserApiClient.instance.loginWithKakaoAccount(requireContext(), callback = mCallback) // 카카오 이메일 로그인 + } } } \ No newline at end of file diff --git a/frontend/ARchive/app/src/main/java/com/droidblossom/archive/presentation/ui/splash/SplashActivity.kt b/frontend/ARchive/app/src/main/java/com/droidblossom/archive/presentation/ui/splash/SplashActivity.kt index 4166a2972..8bf31625f 100644 --- a/frontend/ARchive/app/src/main/java/com/droidblossom/archive/presentation/ui/splash/SplashActivity.kt +++ b/frontend/ARchive/app/src/main/java/com/droidblossom/archive/presentation/ui/splash/SplashActivity.kt @@ -1,12 +1,13 @@ package com.droidblossom.archive.presentation.ui.splash -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.os.Handler import android.os.Looper +import androidx.appcompat.app.AppCompatActivity import com.droidblossom.archive.R import com.droidblossom.archive.presentation.ui.auth.AuthActivity + class SplashActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -17,4 +18,5 @@ class SplashActivity : AppCompatActivity() { finish() }, 1000) } + } \ No newline at end of file diff --git a/frontend/ARchive/settings.gradle b/frontend/ARchive/settings.gradle index d2925efc1..6af704e1d 100644 --- a/frontend/ARchive/settings.gradle +++ b/frontend/ARchive/settings.gradle @@ -11,6 +11,7 @@ dependencyResolutionManagement { google() mavenCentral() maven { url "https://jitpack.io" } + maven { url 'https://devrepo.kakao.com/nexus/content/groups/public/' } // 카카오 로그인 } } rootProject.name = "ARchive"