Skip to content

Commit

Permalink
feat: KaKao Login 구현 - 모듈화 필요, 서버 연결 필요 / #ARCH-22
Browse files Browse the repository at this point in the history
  • Loading branch information
comst19 committed Jan 11, 2024
1 parent 5e2f37e commit 2ef61cc
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 3 deletions.
12 changes: 12 additions & 0 deletions frontend/ARchive/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -36,6 +44,7 @@ android {
buildFeatures{
dataBinding = true
viewBinding = true
buildConfig = true
}
}

Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions frontend/ARchive/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
android:theme="@style/Theme.ARchive"
android:usesCleartextTraffic="true"
tools:targetApi="31">

<activity android:name="com.kakao.sdk.auth.AuthCodeHandlerActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="oauth"
android:scheme="kakao${KAKAO_NATIVE_APP_KEY}" />
</intent-filter>
</activity>

<activity
android:name=".presentation.ui.capsule.CapsuleDetailActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package com.droidblossom.archive

import android.app.Application
import com.kakao.sdk.common.KakaoSdk
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class ARchiveApplication : Application() {}
class ARchiveApplication : Application() {
override fun onCreate() {
super.onCreate()
// Kakao Sdk 초기화
KakaoSdk.init(this, BuildConfig.KAKAO_NATIVE_APP_KEY)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.droidblossom.archive.presentation.ui.auth

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Lifecycle
Expand All @@ -11,6 +12,10 @@ import androidx.navigation.Navigation
import com.droidblossom.archive.R
import com.droidblossom.archive.databinding.FragmentSignInBinding
import com.droidblossom.archive.presentation.base.BaseFragment
import com.kakao.sdk.auth.model.OAuthToken
import com.kakao.sdk.common.model.ClientError
import com.kakao.sdk.common.model.ClientErrorCause
import com.kakao.sdk.user.UserApiClient
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.launch
Expand All @@ -23,12 +28,22 @@ class SignInFragment : BaseFragment<AuthViewModelImpl,FragmentSignInBinding>(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 {
Expand All @@ -48,6 +63,32 @@ class SignInFragment : BaseFragment<AuthViewModelImpl,FragmentSignInBinding>(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) // 카카오 이메일 로그인
}
}
}
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -17,4 +18,5 @@ class SplashActivity : AppCompatActivity() {
finish()
}, 1000)
}

}
1 change: 1 addition & 0 deletions frontend/ARchive/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2ef61cc

Please sign in to comment.