@@ -6,6 +6,7 @@ import com.idle.domain.model.auth.BusinessRegistrationInfo
66import com.idle.domain.model.auth.UserType
77import com.idle.domain.repositorry.auth.AuthRepository
88import com.idle.domain.repositorry.auth.TokenRepository
9+ import com.idle.domain.repositorry.profile.ProfileRepository
910import com.idle.network.model.auth.ConfirmAuthCodeRequest
1011import com.idle.network.model.auth.GenerateNewPasswordRequest
1112import com.idle.network.model.auth.SendPhoneRequest
@@ -17,12 +18,12 @@ import com.idle.network.model.auth.WithdrawalCenterRequest
1718import com.idle.network.model.auth.WithdrawalWorkerRequest
1819import com.idle.network.model.token.TokenResponse
1920import com.idle.network.source.auth.AuthDataSource
20- import kotlinx.coroutines.Dispatchers
21+ import kotlinx.coroutines.coroutineScope
2122import kotlinx.coroutines.launch
22- import kotlinx.coroutines.withContext
2323import javax.inject.Inject
2424
2525class AuthRepositoryImpl @Inject constructor(
26+ private val profileRepository : ProfileRepository ,
2627 private val authDataSource : AuthDataSource ,
2728 private val tokenDataSource : TokenDataSource ,
2829 private val userInfoDataSource : UserInfoDataSource ,
@@ -62,8 +63,16 @@ class AuthRepositoryImpl @Inject constructor(
6263 SignInCenterRequest (identifier = identifier, password = password)
6364 ).fold(
6465 onSuccess = { tokenResponse ->
65- handleSignInSuccess(tokenResponse, UserType .CENTER .apiValue)
66- Result .success(Unit )
66+ coroutineScope {
67+ handleSignInSuccess(tokenResponse, UserType .CENTER .apiValue)
68+
69+ val profile = profileRepository.getMyCenterProfile().getOrNull()
70+ if (profile != null ) {
71+ userInfoDataSource.setUserInfo(profile.toString())
72+ }
73+
74+ Result .success(Unit )
75+ }
6776 },
6877 onFailure = { Result .failure(it) }
6978 )
@@ -95,8 +104,16 @@ class AuthRepositoryImpl @Inject constructor(
95104 )
96105 ).fold(
97106 onSuccess = { tokenResponse ->
98- handleSignInSuccess(tokenResponse, UserType .WORKER .apiValue)
99- Result .success(Unit )
107+ coroutineScope {
108+ handleSignInSuccess(tokenResponse, UserType .WORKER .apiValue)
109+
110+ val profile = profileRepository.getMyWorkerProfile().getOrNull()
111+ if (profile != null ) {
112+ userInfoDataSource.setUserInfo(profile.toString())
113+ }
114+
115+ Result .success(Unit )
116+ }
100117 },
101118 onFailure = { Result .failure(it) }
102119 )
@@ -108,8 +125,16 @@ class AuthRepositoryImpl @Inject constructor(
108125 SignInWorkerRequest (phoneNumber = phoneNumber, authCode = authCode)
109126 ).fold(
110127 onSuccess = { tokenResponse ->
111- handleSignInSuccess(tokenResponse, UserType .WORKER .apiValue)
112- Result .success(Unit )
128+ coroutineScope {
129+ handleSignInSuccess(tokenResponse, UserType .WORKER .apiValue)
130+
131+ val updatedProfile = profileRepository.getMyWorkerProfile().getOrNull()
132+ if (updatedProfile != null ) {
133+ userInfoDataSource.setUserInfo(updatedProfile.toString())
134+ }
135+
136+ Result .success(Unit )
137+ }
113138 },
114139 onFailure = { Result .failure(it) }
115140 )
@@ -159,7 +184,7 @@ class AuthRepositoryImpl @Inject constructor(
159184 private suspend fun handleSignInSuccess (
160185 tokenResponse : TokenResponse ,
161186 userType : String ,
162- ) = withContext( Dispatchers . IO ) {
187+ ) = coroutineScope {
163188 launch { tokenDataSource.setRefreshToken(tokenResponse.refreshToken) }
164189 launch { userInfoDataSource.setUserType(userType) }
165190 launch { tokenDataSource.setAccessToken(tokenResponse.accessToken) }.join()
@@ -168,7 +193,7 @@ class AuthRepositoryImpl @Inject constructor(
168193 tokenRepository.postDeviceToken(deviceToken, userType = userType)
169194 }
170195
171- private suspend fun clearUserData () = withContext( Dispatchers . IO ) {
196+ private suspend fun clearUserData () = coroutineScope {
172197 launch { userInfoDataSource.clearUserType() }
173198 launch { userInfoDataSource.clearUserInfo() }
174199 tokenDataSource.clearToken()
0 commit comments