-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#72 [feat] 카카오 로그인 구현 #82
Merged
Merged
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
c6b808a
#72 [add] login activity 생성
stellar-halo bb712af
#72 [add] kakao login을 위한 build.gradle 수정 및 추가
stellar-halo 86e1ea6
#72 [chore] 불필요 파일 수정
stellar-halo 0362ba2
#72 [add] 더블 클릭 시, 앱 종료 확장 함수
stellar-halo 9a066b6
#72 [add] kakao login을 위한 setting.gradle maven 추가
stellar-halo fc11483
#72 [add] kakao login을 위한 com.kakao.sdk.auth.AuthCodeHandlerActivity 생성
stellar-halo 7259e21
#72 [feat] auth레포지토리 생성 및 module에서 Impl binding
stellar-halo 1e5a3fd
#72 [add] 터치 한 번만 가능한 singleClickListener
stellar-halo 57c17a5
#72 [add] string 추가
stellar-halo 7de912b
#72 [fix] SoftieApplication에 kakao native app key 설정
stellar-halo 635918d
#72 [chore] 카카오 로그인 이미지, 곰 인사 로티 파일 추가
stellar-halo ef535d6
#72 [add] postLogin을 위한 data class 생성
stellar-halo e77b9fb
#72 [feat] AuthDataSource 생성 및 postLogin
stellar-halo f70f84b
#72 [feat] AuthService에 postLogin 추가
stellar-halo 064d1c4
#72 [feat] kakaoLogin callback 클래스 생성
stellar-halo 5bfc823
#72 [feat] postLoginUseCase
stellar-halo 8d4c177
#72 [feat] token 저장하는 useCase 생성
stellar-halo afbaa62
#72 [feat] AuthRepositoryImpl 생성
stellar-halo 0f39f50
#72 [feat] sharedPreference에 token값 저장하는 localDataSource 생성
stellar-halo e96dd1f
#72 [feat] 카카오 앱이 있으면, 앱으로 연결하고 없으면 계정 로그인으로 연결하는 KakaoLoginService 생성
stellar-halo 2e7cee5
#72 [feat] 의존성 주입을 위한 SharedPrefModule 생성
stellar-halo 092e39d
#72 [feat] 로그인 로직을 위한 activity, viewModel 생성
stellar-halo 0cec856
#72 [fix] LocalDataSource에 저장된 access token을 기준으로 서버 통신
stellar-halo a7ba2bf
Merge remote-tracking branch 'origin/develop' into feature/#72-feat-k…
stellar-halo 73da622
#72 [feat] sharedPreference에 회원가입한 사용자인지 아닌지 분기처리를 위한 UseCase
stellar-halo 09714f7
#72 [feat] sharedPreference에 회원가입한 사용자인지 아닌지 boolean값 추가
stellar-halo 5e3f356
#72 [feat] splash에서 회원가입한 사용자인지 아닌지 구분한 후에 온보딩으로 보낼지 main으로 보낼지 처리
stellar-halo 371e981
#72 [fix] lint check
stellar-halo 5dd25e2
#72 [fix] lint check
stellar-halo 492a3b1
#72 [fix] 주석 삭제
stellar-halo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,16 @@ package com.sopetit.softie | |
|
||
import android.app.Application | ||
import androidx.appcompat.app.AppCompatDelegate | ||
import com.kakao.sdk.common.KakaoSdk | ||
import com.sopetit.softie.BuildConfig.KAKAO_NATIVE_APP_KEY | ||
import dagger.hilt.android.HiltAndroidApp | ||
import timber.log.Timber | ||
|
||
@HiltAndroidApp | ||
class SoftieApplication : Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
KakaoSdk.init(this, KAKAO_NATIVE_APP_KEY) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코드에 카카오가 들어가 있는게 묘하게 깐지나네요.. |
||
if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree()) | ||
|
||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) | ||
|
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/sopetit/softie/data/entity/request/LoginRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.sopetit.softie.data.entity.request | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class LoginRequest( | ||
@SerialName("socialType") | ||
val socialType: String | ||
) |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/sopetit/softie/data/entity/response/LoginResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.sopetit.softie.data.entity.response | ||
|
||
import com.sopetit.softie.domain.entity.Token | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class LoginResponse( | ||
val accessToken: String, | ||
val refreshToken: String | ||
) { | ||
fun toToken(): Token = Token( | ||
accessToken = this.accessToken, | ||
refreshToken = this.refreshToken | ||
) | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/sopetit/softie/data/repositoryImpl/AuthRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.sopetit.softie.data.repositoryImpl | ||
|
||
import com.sopetit.softie.data.source.AuthDataSource | ||
import com.sopetit.softie.data.source.LocalDataSource | ||
import com.sopetit.softie.domain.entity.Token | ||
import com.sopetit.softie.domain.repository.AuthRepository | ||
import javax.inject.Inject | ||
|
||
class AuthRepositoryImpl @Inject constructor( | ||
private val authDataSource: AuthDataSource, | ||
private val localDataSource: LocalDataSource | ||
) : AuthRepository { | ||
override suspend fun postLogin(socialPlatform: String): Result<Token> = | ||
kotlin.runCatching { authDataSource.postLogin(socialPlatform) }.map { response -> | ||
requireNotNull(response.data).toToken() | ||
} | ||
|
||
override fun initToken(accessToken: String, refreshToken: String) { | ||
localDataSource.accessToken = accessToken | ||
localDataSource.refreshToken = refreshToken | ||
} | ||
|
||
override fun initSignUpState(isSignUpState: Boolean) { | ||
localDataSource.isUserSignUp = isSignUpState | ||
} | ||
|
||
override fun getSignedUp(): Boolean = localDataSource.isUserSignUp | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/sopetit/softie/data/service/AuthService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.sopetit.softie.data.service | ||
|
||
import com.sopetit.softie.data.entity.BaseResponse | ||
import com.sopetit.softie.data.entity.request.LoginRequest | ||
import com.sopetit.softie.data.entity.response.LoginResponse | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface AuthService { | ||
@POST("api/v1/auth") | ||
suspend fun postLogin( | ||
@Body body: LoginRequest | ||
): BaseResponse<LoginResponse> | ||
} |
36 changes: 36 additions & 0 deletions
36
app/src/main/java/com/sopetit/softie/data/service/KakaoLoginService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.sopetit.softie.data.service | ||
|
||
import android.content.Context | ||
import com.kakao.sdk.auth.model.OAuthToken | ||
import com.kakao.sdk.user.UserApiClient | ||
import dagger.hilt.android.qualifiers.ActivityContext | ||
import javax.inject.Inject | ||
|
||
class KakaoLoginService @Inject constructor(@ActivityContext private val context: Context) { | ||
fun startKakaoLogin(kakaoLoginCallBack: (OAuthToken?, Throwable?) -> Unit) { | ||
val kakaoLoginState = | ||
if (UserApiClient.instance.isKakaoTalkLoginAvailable(context)) KAKAO_APP_LOGIN | ||
else KAKAO_ACCOUNT_LOGIN | ||
|
||
when (kakaoLoginState) { | ||
KAKAO_APP_LOGIN -> { | ||
UserApiClient.instance.loginWithKakaoTalk( | ||
context, | ||
callback = kakaoLoginCallBack | ||
) | ||
} | ||
|
||
KAKAO_ACCOUNT_LOGIN -> { | ||
UserApiClient.instance.loginWithKakaoAccount( | ||
context, | ||
callback = kakaoLoginCallBack | ||
) | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
const val KAKAO_APP_LOGIN = 0 | ||
const val KAKAO_ACCOUNT_LOGIN = 1 | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/sopetit/softie/data/source/AuthDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.sopetit.softie.data.source | ||
|
||
import com.sopetit.softie.data.entity.BaseResponse | ||
import com.sopetit.softie.data.entity.request.LoginRequest | ||
import com.sopetit.softie.data.entity.response.LoginResponse | ||
import com.sopetit.softie.data.service.AuthService | ||
import javax.inject.Inject | ||
|
||
class AuthDataSource @Inject constructor( | ||
private val authService: AuthService | ||
) { | ||
suspend fun postLogin(socialType: String): BaseResponse<LoginResponse> = | ||
authService.postLogin(LoginRequest(socialType)) | ||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/sopetit/softie/data/source/LocalDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.sopetit.softie.data.source | ||
|
||
import android.content.SharedPreferences | ||
import androidx.core.content.edit | ||
import javax.inject.Inject | ||
|
||
class LocalDataSource @Inject constructor( | ||
private val prefs: SharedPreferences | ||
) { | ||
var accessToken: String | ||
set(value) = prefs.edit { putString(ACCESS_TOKEN, value) } | ||
get() = prefs.getString(ACCESS_TOKEN, "") ?: "" | ||
|
||
var refreshToken: String | ||
set(value) = prefs.edit { putString(REFRESH_TOKEN, value) } | ||
get() = prefs.getString(REFRESH_TOKEN, "") ?: "" | ||
|
||
var isUserSignUp: Boolean | ||
set(value) = prefs.edit { putBoolean(USER, value) } | ||
get() = prefs.getBoolean(USER, false) | ||
|
||
companion object { | ||
private const val ACCESS_TOKEN = "access_token" | ||
private const val REFRESH_TOKEN = "refresh_token" | ||
private const val USER = "user" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/sopetit/softie/di/SharedPrefModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.sopetit.softie.di | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import androidx.security.crypto.EncryptedSharedPreferences | ||
import androidx.security.crypto.MasterKey | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object SharedPrefModule { | ||
@Provides | ||
@Singleton | ||
fun providesLocalPreferences(@ApplicationContext context: Context): SharedPreferences = | ||
EncryptedSharedPreferences.create( | ||
context, | ||
context.packageName, | ||
MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build(), | ||
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, | ||
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.sopetit.softie.domain.entity | ||
|
||
data class Token( | ||
val accessToken: String = "", | ||
val refreshToken: String = "" | ||
) |
9 changes: 8 additions & 1 deletion
9
app/src/main/java/com/sopetit/softie/domain/repository/AuthRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
package com.sopetit.softie.domain.repository | ||
|
||
interface AuthRepository | ||
import com.sopetit.softie.domain.entity.Token | ||
|
||
interface AuthRepository { | ||
suspend fun postLogin(socialPlatform: String): Result<Token> | ||
fun getSignedUp(): Boolean | ||
fun initToken(accessToken: String, refreshToken: String) | ||
fun initSignUpState(isSignUpState: Boolean) | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/sopetit/softie/domain/usecase/GetSignedUpUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.sopetit.softie.domain.usecase | ||
|
||
import com.sopetit.softie.domain.repository.AuthRepository | ||
import javax.inject.Inject | ||
|
||
class GetSignedUpUseCase @Inject constructor( | ||
private val authRepository: AuthRepository | ||
) { | ||
operator fun invoke() = authRepository.getSignedUp() | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/sopetit/softie/domain/usecase/InitSIgnUpStateUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.sopetit.softie.domain.usecase | ||
|
||
import com.sopetit.softie.domain.repository.AuthRepository | ||
import javax.inject.Inject | ||
|
||
class InitSIgnUpStateUseCase @Inject constructor( | ||
private val authRepository: AuthRepository | ||
) { | ||
operator fun invoke(isSignUpState: Boolean) = | ||
authRepository.initSignUpState(isSignUpState) | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/sopetit/softie/domain/usecase/InitTokenUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.sopetit.softie.domain.usecase | ||
|
||
import com.sopetit.softie.domain.repository.AuthRepository | ||
import javax.inject.Inject | ||
|
||
class InitTokenUseCase @Inject constructor( | ||
private val authRepository: AuthRepository | ||
) { | ||
operator fun invoke(accessToken: String, refreshToken: String) = | ||
authRepository.initToken(accessToken, refreshToken) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
singleTask가 어떤 역할인가요?