Skip to content

Commit

Permalink
fix: When trying to updateCurrentUserAndDrives(), if we receive a `…
Browse files Browse the repository at this point in the history
…401`, logout the user
  • Loading branch information
KevinBoulongne committed Feb 11, 2025
1 parent bf14be9 commit ab8d597
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ object ErrorCode {
const val PASSWORD_NOT_VALID = "password_not_valid"
const val PUBLIC_SHARE_LINK_IS_NOT_VALID = "link_is_not_valid"
const val QUOTA_EXCEEDED_ERROR = "quota_exceeded_error"
const val NOT_AUTHORIZED = "not_authorized"

val apiErrorCodes = listOf(
ApiErrorCode(CATEGORY_ALREADY_EXISTS, R.string.errorCategoryAlreadyExists),
Expand Down
24 changes: 16 additions & 8 deletions app/src/main/java/com/infomaniak/drive/utils/AccountUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,26 @@ object AccountUtils : CredentialManager() {
okHttpClient: OkHttpClient = HttpClient.okHttpClient,
) = withContext(Dispatchers.IO) {

val (userResult, user) = with(ApiRepository.getUserProfile(okHttpClient)) {
result to (data ?: return@withContext)
}
val apiResponse = ApiRepository.getUserProfile(okHttpClient)

if (userResult != ApiResponseStatus.ERROR) {
ApiRepository.getAllDrivesData(okHttpClient).apply {
if (result != ApiResponseStatus.ERROR) {
handleDrivesData(context, fromMaintenance, fromCloudStorage, user, data as DriveInfo)
} else if (error?.code == ErrorCode.NO_DRIVE) {
if (apiResponse.result == ApiResponseStatus.ERROR) {
when (apiResponse.error?.code) {
ErrorCode.NOT_AUTHORIZED -> {
val user = currentUser ?: requestCurrentUser() ?: return@withContext
if (UploadFile.getAppSyncSettings()?.userId == user.id) UploadFile.deleteAllSyncFile()
removeUserAndDeleteToken(context, user)
}
}
return@withContext
}

val user = apiResponse.data ?: return@withContext
ApiRepository.getAllDrivesData(okHttpClient).apply {
if (result != ApiResponseStatus.ERROR) {
handleDrivesData(context, fromMaintenance, fromCloudStorage, user, data as DriveInfo)
} else if (error?.code == ErrorCode.NO_DRIVE) {
removeUserAndDeleteToken(context, user)
}
}
}

Expand Down

0 comments on commit ab8d597

Please sign in to comment.