diff --git a/data/src/main/java/in/koreatech/koin/data/repository/UserRepositoryImpl.kt b/data/src/main/java/in/koreatech/koin/data/repository/UserRepositoryImpl.kt index 6a696135c..2b6ac49e6 100644 --- a/data/src/main/java/in/koreatech/koin/data/repository/UserRepositoryImpl.kt +++ b/data/src/main/java/in/koreatech/koin/data/repository/UserRepositoryImpl.kt @@ -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 @@ -43,11 +43,11 @@ 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 } @@ -55,6 +55,12 @@ class UserRepositoryImpl @Inject constructor( } } + override suspend fun fetchUserInfo() { + userRemoteDataSource.getUserInfo().toUser().also { + userLocalDataSource.updateUserInfo(it) + } + } + override suspend fun getUserInfo(): User { return userRemoteDataSource.getUserInfo().toUser().also { userLocalDataSource.updateUserInfo(it) @@ -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") diff --git a/domain/src/main/java/in/koreatech/koin/domain/repository/UserRepository.kt b/domain/src/main/java/in/koreatech/koin/domain/repository/UserRepository.kt index 35a02fba9..afd433ac2 100644 --- a/domain/src/main/java/in/koreatech/koin/domain/repository/UserRepository.kt +++ b/domain/src/main/java/in/koreatech/koin/domain/repository/UserRepository.kt @@ -17,6 +17,7 @@ interface UserRepository { ): AuthToken fun ownerTokenIsValid(): Boolean + suspend fun fetchUserInfo() suspend fun getUserInfo(): User fun getUserInfoFlow(): Flow suspend fun requestPasswordResetEmail(email: String) diff --git a/domain/src/main/java/in/koreatech/koin/domain/usecase/user/UserLoginUseCase.kt b/domain/src/main/java/in/koreatech/koin/domain/usecase/user/UserLoginUseCase.kt index a975ea666..f6e35ed2c 100644 --- a/domain/src/main/java/in/koreatech/koin/domain/usecase/user/UserLoginUseCase.kt +++ b/domain/src/main/java/in/koreatech/koin/domain/usecase/user/UserLoginUseCase.kt @@ -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)