Ignore auto sign in if user has PIN (#392)

If the current user has a PIN, the sign in automatically setting is
ignored if the app is put in the background or restarted.

Follow up to #356 &
https://github.com/damontecres/Wholphin/issues/321#issuecomment-3621312496

I think the PIN protection needs some more thought overall.
This commit is contained in:
damontecres 2025-12-07 17:48:46 -05:00 committed by GitHub
parent e0d50baf15
commit fa141adc60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 7 additions and 3 deletions

View file

@ -179,7 +179,7 @@ class MainActivity : AppCompatActivity() {
} else {
DisposableEffect(Unit) {
onDispose {
if (!appPreferences.signInAutomatically) {
if (!appPreferences.signInAutomatically || current?.user?.hasPin == true) {
serverRepository.closeSession()
}
}
@ -252,7 +252,7 @@ class MainActivity : AppCompatActivity() {
val signInAutomatically =
runBlocking { userPreferencesDataStore.data.firstOrNull()?.signInAutomatically } ?: true
Timber.i("onRestart: signInAutomatically=$signInAutomatically")
if (!signInAutomatically) {
if (!signInAutomatically || serverRepository.currentUser.value?.hasPin == true) {
serverRepository.closeSession()
}
}

View file

@ -109,6 +109,8 @@ class ServerRepository
/**
* Restores a session for the given server & user such as when the app reopens
*
* If user has a PIN, this returns false
*/
suspend fun restoreSession(
serverId: UUID?,
@ -124,7 +126,7 @@ class ServerRepository
}
if (serverAndUsers != null) {
val user = serverAndUsers.users.firstOrNull { it.id == userId }
if (user != null) {
if (user != null && !user.hasPin) {
changeUser(serverAndUsers.server, user)
return true
}

View file

@ -52,6 +52,8 @@ data class JellyfinUser(
val accessToken: String?,
val pin: String? = null,
) {
val hasPin: Boolean get() = pin.isNotNullOrBlank()
override fun toString(): String =
"JellyfinUser(rowId=$rowId, id=$id, name=$name, serverId=$serverId, accessToken?=${accessToken.isNotNullOrBlank()}, pin?=${pin.isNotNullOrBlank()})"
}