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

[Fix] 다른 계정으로 로그인 할 시 유저 정보 갱신 안되는 문제 수정 #517

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading