mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-08-02 01:28:25 +00:00
fix(auth): sanitize authentication errors
This commit is contained in:
parent
88d3cbdfac
commit
d55ed7ae2a
1 changed files with 15 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ import co.touchlab.kermit.Logger
|
|||
import com.nuvio.app.core.network.SupabaseProvider
|
||||
import com.nuvio.app.core.storage.LocalAccountDataCleaner
|
||||
import io.github.jan.supabase.auth.auth
|
||||
import io.github.jan.supabase.auth.exception.AuthRestException
|
||||
import io.github.jan.supabase.auth.providers.builtin.Email
|
||||
import io.github.jan.supabase.auth.status.SessionStatus
|
||||
import io.github.jan.supabase.exceptions.RestException
|
||||
|
|
@ -117,7 +118,8 @@ object AuthRepository {
|
|||
Unit
|
||||
}.onFailure { e ->
|
||||
log.e(e) { "Email sign-up failed" }
|
||||
_error.value = e.message ?: getString(Res.string.auth_sign_up_failed)
|
||||
_error.value = e.safeAuthErrorDescription()
|
||||
?: getString(Res.string.auth_sign_up_failed)
|
||||
}
|
||||
|
||||
suspend fun signInWithEmail(email: String, password: String): Result<Unit> = runCatching {
|
||||
|
|
@ -128,7 +130,8 @@ object AuthRepository {
|
|||
}
|
||||
}.onFailure { e ->
|
||||
log.e(e) { "Email sign-in failed" }
|
||||
_error.value = e.message ?: getString(Res.string.auth_sign_in_failed)
|
||||
_error.value = e.safeAuthErrorDescription()
|
||||
?: getString(Res.string.auth_sign_in_failed)
|
||||
}
|
||||
|
||||
suspend fun signOut(): Result<Unit> {
|
||||
|
|
@ -248,4 +251,14 @@ object AuthRepository {
|
|||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun Throwable.safeAuthErrorDescription(): String? =
|
||||
findCause<AuthRestException>()
|
||||
?.errorDescription
|
||||
?.trim()
|
||||
?.takeIf { it.isNotEmpty() }
|
||||
?: findCause<RestException>()
|
||||
?.description
|
||||
?.trim()
|
||||
?.takeIf { it.isNotEmpty() }
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue