Skip to content
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

[Hotfix/#105] auth dto 핫픽스 #106

Merged
merged 12 commits into from
Jan 14, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ data class AuthResponseDto(
val accessToken: String,
@SerialName("refreshToken")
val refreshToken: String,
@SerialName("userId")
val userId: Long,
) {
fun toAuthTokenModel() =
AuthTokenModel(accessToken = accessToken, refreshToken = refreshToken)
AuthTokenModel(accessToken = accessToken, refreshToken = refreshToken, userId = userId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ data class SignInResponseDto(
val refreshToken: String,
@SerialName("isResult")
val isResult: Boolean,
@SerialName("userId")
val userId: Long,
) {
fun toSignInModel() =
SignInModel(accessToken, refreshToken, isResult)
SignInModel(accessToken, refreshToken, isResult, userId)
}
1 change: 1 addition & 0 deletions data/src/main/java/com/going/data/local/GoingDataStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package com.going.data.local
interface GoingDataStore {
var accessToken: String
var refreshToken: String
var userId: Long
}
5 changes: 5 additions & 0 deletions data/src/main/java/com/going/data/local/GoingDataStoreImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ class GoingDataStoreImpl @Inject constructor(
get() = dataStore.getString(REFRESH_TOKEN, "") ?: ""
set(value) = dataStore.edit { putString(REFRESH_TOKEN, value) }

override var userId: Long
get() = dataStore.getLong(USER_ID, 0L)
set(value) = dataStore.edit { putLong(USER_ID, value) }
Comment on lines +19 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 사용하는 거군ㅇ요 오늘도 멋진 코드 보고갑니다요


companion object {
private const val ACCESS_TOKEN = "ACCESS_TOKEN"
private const val REFRESH_TOKEN = "REFRESH_TOKEN"
private const val USER_ID = "USER_ID"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class TokenRepositoryImpl @Inject constructor(
goingDataStore.refreshToken = refreshToken
}

override fun setUserId(userId: Long) {
goingDataStore.userId = userId
}

override fun clearTokens() {
goingDataStore.accessToken = ""
goingDataStore.refreshToken = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package com.going.domain.entity.response
data class AuthTokenModel(
val accessToken: String,
val refreshToken: String,
val userId: Long,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ data class SignInModel(
val accessToken: String,
val refreshToken: String,
val isResult: Boolean,
val userId: Long,
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ interface TokenRepository {

fun setTokens(accessToken: String, refreshToken: String)

fun setUserId(userId: Long)

fun clearTokens()
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class SignInViewModel @Inject constructor(
viewModelScope.launch {
authRepository.postSignIn(accessToken, SignInRequestModel(platform)).onSuccess {
tokenRepository.setTokens(it.accessToken, it.refreshToken)
tokenRepository.setUserId(it.userId)

if (it.isResult) {
_postChangeTokenState.value = AuthState.SUCCESS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.going.domain.entity.AuthState
import com.going.domain.entity.NameState
import com.going.domain.entity.request.SignUpRequestModel
import com.going.domain.repository.AuthRepository
import com.going.domain.repository.TokenRepository
import com.kakao.sdk.auth.AuthApiClient
import com.kakao.sdk.auth.TokenManagerProvider
import com.kakao.sdk.user.UserApiClient
Expand All @@ -20,6 +21,7 @@ import javax.inject.Inject
@HiltViewModel
class OnboardingProfileSettingViewModel @Inject constructor(
private val authRepository: AuthRepository,
private val tokenRepository: TokenRepository,
) : ViewModel() {

val name = MutableStateFlow("")
Expand Down Expand Up @@ -88,6 +90,8 @@ class OnboardingProfileSettingViewModel @Inject constructor(
kakaoAccessToken,
SignUpRequestModel(name.value, info.value, KAKAO),
).onSuccess {
tokenRepository.setTokens(it.accessToken, it.refreshToken)
tokenRepository.setUserId(it.userId)
_isSignUpState.value = AuthState.SUCCESS
}.onFailure {
_isSignUpState.value = AuthState.FAILURE
Expand Down