Skip to content

Commit

Permalink
Merge pull request #517 from BCSDLab/fix/user_info_login
Browse files Browse the repository at this point in the history
[Fix] 다른 계정으로 로그인 할 시 유저 정보 갱신 안되는 문제 수정
  • Loading branch information
nodobi authored Dec 24, 2024
2 parents d7e7439 + 00f867b commit 09e1276
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package `in`.koreatech.koin.data.repository

import `in`.koreatech.koin.data.mapper.toUser
import `in`.koreatech.koin.data.mapper.toUserRequest
import `in`.koreatech.koin.data.mapper.toUserRequestWithPassword
import `in`.koreatech.koin.data.request.owner.OwnerLoginRequest
import `in`.koreatech.koin.data.request.user.ABTestRequest
import `in`.koreatech.koin.data.mapper.toUserRequestWithPassword
import `in`.koreatech.koin.data.request.user.IdRequest
import `in`.koreatech.koin.data.request.user.LoginRequest
import `in`.koreatech.koin.data.request.user.PasswordRequest
Expand Down Expand Up @@ -43,18 +43,24 @@ class UserRepositoryImpl @Inject constructor(
}

override fun ownerTokenIsValid(): Boolean {
return runBlocking{
return runBlocking {
try {
userRemoteDataSource.ownerTokenIsValid()
true
} catch (e: HttpException){
} catch (e: HttpException) {
if (e.code() == 401) false
else throw e
}

}
}

override suspend fun fetchUserInfo() {
userRemoteDataSource.getUserInfo().toUser().also {
userLocalDataSource.updateUserInfo(it)
}
}

override suspend fun getUserInfo(): User {
return userRemoteDataSource.getUserInfo().toUser().also {
userLocalDataSource.updateUserInfo(it)
Expand Down Expand Up @@ -131,6 +137,7 @@ class UserRepositoryImpl @Inject constructor(
return ABTest(it.variableName, it.accessHistoryId)
}
}

override suspend fun updateUserPassword(user: User, hashedPassword: String) {
when (user) {
User.Anonymous -> throw IllegalAccessException("Updating anonymous user is not supported")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface UserRepository {
): AuthToken

fun ownerTokenIsValid(): Boolean
suspend fun fetchUserInfo()
suspend fun getUserInfo(): User
fun getUserInfoFlow(): Flow<User>
suspend fun requestPasswordResetEmail(email: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class UserLoginUseCase @Inject constructor(
val authToken = userRepository.getToken(email, password.toSHA256())
tokenRepository.saveAccessToken(authToken.token)
tokenRepository.saveRefreshToken(authToken.refreshToken)
userRepository.fetchUserInfo()
Unit to null
} catch (throwable: Throwable) {
null to userErrorHandler.handleGetTokenError(throwable)
Expand Down

0 comments on commit 09e1276

Please sign in to comment.