feat: Implement forced logout on app restart and prioritize last logged public key in UnlockScreen
This commit is contained in:
@@ -19,6 +19,7 @@ class AccountManager(private val context: Context) {
|
||||
private val CURRENT_PUBLIC_KEY = stringPreferencesKey("current_public_key")
|
||||
private val ACCOUNTS_JSON = stringPreferencesKey("accounts_json")
|
||||
private val IS_LOGGED_IN = booleanPreferencesKey("is_logged_in")
|
||||
private val LAST_LOGGED_PUBLIC_KEY = stringPreferencesKey("last_logged_public_key")
|
||||
}
|
||||
|
||||
val currentPublicKey: Flow<String?> = context.accountDataStore.data.map { preferences ->
|
||||
@@ -33,6 +34,14 @@ class AccountManager(private val context: Context) {
|
||||
preferences[ACCOUNTS_JSON]
|
||||
}
|
||||
|
||||
val lastLoggedPublicKey: Flow<String?> = context.accountDataStore.data.map { preferences ->
|
||||
preferences[LAST_LOGGED_PUBLIC_KEY]
|
||||
}
|
||||
|
||||
suspend fun getLastLoggedPublicKey(): String? {
|
||||
return context.accountDataStore.data.first()[LAST_LOGGED_PUBLIC_KEY]
|
||||
}
|
||||
|
||||
suspend fun saveAccount(account: EncryptedAccount) {
|
||||
context.accountDataStore.edit { preferences ->
|
||||
val existingJson = preferences[ACCOUNTS_JSON]
|
||||
@@ -66,6 +75,7 @@ class AccountManager(private val context: Context) {
|
||||
context.accountDataStore.edit { preferences ->
|
||||
preferences[CURRENT_PUBLIC_KEY] = publicKey
|
||||
preferences[IS_LOGGED_IN] = true
|
||||
preferences[LAST_LOGGED_PUBLIC_KEY] = publicKey
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user