Skip to content

Commit 9e4b062

Browse files
committed
Made minor changes
1 parent 691285e commit 9e4b062

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

Shrine/app/src/main/java/com/authentication/shrine/repository/AuthRepository.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class AuthRepository @Inject constructor(
6060
) {
6161

6262
// Companion object for constants and helper methods
63-
private companion object {
63+
companion object {
6464
const val TAG = "AuthRepository"
6565

6666
// Keys for SharedPreferences
@@ -71,6 +71,7 @@ class AuthRepository @Inject constructor(
7171

7272
// Value for restore credential AuthApiService parameter
7373
const val RESTORE_KEY_TYPE_PARAMETER = "rc"
74+
const val RESTORE_CREDENTIAL_AAGUID = "restore-credential"
7475

7576
suspend fun <T> DataStore<Preferences>.read(key: Preferences.Key<T>): T? {
7677
return data.map { it[key] }.first()
@@ -263,12 +264,7 @@ class AuthRepository @Inject constructor(
263264
if (apiResult.isSuccessful) {
264265
dataStore.edit { prefs ->
265266
if (credentialResponse is CreateRestoreCredentialResponse) {
266-
val responseData = credentialResponse.data.getString(
267-
"androidx.credentials.BUNDLE_KEY_CREATE_RESTORE_CREDENTIAL_RESPONSE"
268-
)
269-
val responseJSON = JSONObject(responseData!!)
270-
val credentialId = responseJSON.getString("rawId")
271-
prefs[RESTORE_KEY_CREDENTIAL_ID] = credentialId
267+
prefs[RESTORE_KEY_CREDENTIAL_ID] = rawId
272268
}
273269
apiResult.getSessionId()?.also {
274270
prefs[SESSION_ID] = it
@@ -496,6 +492,8 @@ class AuthRepository @Inject constructor(
496492
)
497493
if (response.isSuccessful) {
498494
return true
495+
} else if (response.code() == 401) {
496+
signOut()
499497
}
500498
}
501499
}catch (e: Exception) {

Shrine/app/src/main/java/com/authentication/shrine/ui/viewmodel/PasskeyManagementViewModel.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.authentication.shrine.GenericCredentialManagerResponse
2424
import com.authentication.shrine.R
2525
import com.authentication.shrine.model.PasskeyCredential
2626
import com.authentication.shrine.repository.AuthRepository
27+
import com.authentication.shrine.repository.AuthRepository.Companion.RESTORE_CREDENTIAL_AAGUID
2728
import com.google.gson.Gson
2829
import com.google.gson.reflect.TypeToken
2930
import dagger.hilt.android.lifecycle.HiltViewModel
@@ -252,10 +253,6 @@ class PasskeyManagementViewModel @Inject constructor(
252253
}
253254
}
254255
}
255-
256-
companion object {
257-
const val RESTORE_CREDENTIAL_AAGUID = "restore-credential"
258-
}
259256
}
260257

261258
/**

Shrine/app/src/main/java/com/authentication/shrine/ui/viewmodel/SettingsViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import androidx.lifecycle.viewModelScope
2121
import com.authentication.shrine.R
2222
import com.authentication.shrine.model.PasskeyCredential
2323
import com.authentication.shrine.repository.AuthRepository
24-
import com.authentication.shrine.ui.viewmodel.PasskeyManagementViewModel.Companion.RESTORE_CREDENTIAL_AAGUID
24+
import com.authentication.shrine.repository.AuthRepository.Companion.RESTORE_CREDENTIAL_AAGUID
2525
import dagger.hilt.android.lifecycle.HiltViewModel
2626
import kotlinx.coroutines.flow.MutableStateFlow
2727
import kotlinx.coroutines.flow.asStateFlow

0 commit comments

Comments
 (0)