-
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
Feat/#13 카카오 로그인 기능 설정 #28
The head ref may contain hidden characters: "feat/#13-\uCE74\uCE74\uC624-\uB85C\uADF8\uC778-\uAE30\uB2A5-\uC124\uC815"
Changes from 2 commits
20e76ff
d23f3b0
c2c4f44
e8a365a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package com.owori.android | ||
|
||
import android.app.Application | ||
import com.kakao.sdk.common.KakaoSdk | ||
import dagger.hilt.android.HiltAndroidApp | ||
|
||
@HiltAndroidApp | ||
class OworiApplication: Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
KakaoSdk.init(this, "6c28960f69d4c7f00043b02d890dd6e0") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.owori.android.auth.data | ||
|
||
enum class AuthProvider(val value: String) { | ||
KAKAO("KAKAO"), GOOGLE("GOOGLE") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.owori.android.auth.data | ||
|
||
data class MemberRequest ( | ||
val token: String, | ||
val authProvider: AuthProvider | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,62 @@ | ||
package com.owori.android.auth.ui.viewmodel | ||
|
||
import android.content.ContentValues.TAG | ||
import android.content.Context | ||
import android.util.Log | ||
import androidx.lifecycle.LiveData | ||
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 com.owori.android.common.SingleLiveEvent | ||
import com.owori.android.common.ui.viewmodel.BaseViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import dagger.hilt.android.qualifiers.ActivityContext | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class LoginViewModel @Inject constructor() : BaseViewModel() { | ||
class LoginViewModel @Inject constructor(@ApplicationContext private val context: Context) : BaseViewModel() { | ||
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. context를 주입받지 않고 그냥 AndroidViewModel을 사용해도 될 거 같습니다. 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. 넵 context 필요한 로직은 viewmodel에서 분리하겠습니다! |
||
private val _callKakaoLogin: SingleLiveEvent<Unit> = SingleLiveEvent() | ||
val callKakaoLogin: LiveData<Unit> = _callKakaoLogin | ||
private val _callGoogleLogin: SingleLiveEvent<Unit> = SingleLiveEvent() | ||
val callGoogleLogin: LiveData<Unit> = _callGoogleLogin | ||
val userApiClient = UserApiClient() | ||
|
||
fun onClickKakaoLogin() { | ||
_callKakaoLogin.call() | ||
val callback: (OAuthToken?, Throwable?) -> Unit = { token, error -> | ||
if (error != null) { | ||
Log.e(TAG, "카카오계정으로 로그인 실패", error) | ||
} else if (token != null) { | ||
Log.i(TAG, "카카오계정으로 로그인 성공 ${token.accessToken}") | ||
Log.i(TAG, "카카오계정으로 로그인 성공 ${token.refreshToken}") | ||
_callKakaoLogin.call() | ||
} | ||
} | ||
|
||
|
||
if (userApiClient.isKakaoTalkLoginAvailable(context)) { | ||
userApiClient.loginWithKakaoTalk(context) { token, error -> | ||
if (error != null) { | ||
Log.e(TAG, "카카오톡으로 로그인 실패", error) | ||
|
||
if (error is ClientError && error.reason == ClientErrorCause.Cancelled) { | ||
return@loginWithKakaoTalk | ||
} | ||
|
||
userApiClient.loginWithKakaoAccount(context, callback = callback) | ||
} else if (token != null) { | ||
Log.i(TAG, "카카오톡으로 로그인 성공 ${token.accessToken}") | ||
} | ||
} | ||
} else { | ||
userApiClient.loginWithKakaoAccount(context, callback = callback) | ||
} | ||
} | ||
|
||
fun onClickGoogleLogin() { | ||
_callGoogleLogin.call() | ||
} | ||
|
||
|
||
} |
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.
서버키 같은 상수들은 따로 strings.xml 이나 별도의 configuration.xml 로 관리하는게 좋을거 같습니다.
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.
별도의 configuration.xml에서 관리할 수 있도록 하겠습니다!