-
Notifications
You must be signed in to change notification settings - Fork 267
Implement conditional create in Shrine #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -302,6 +302,32 @@ class AuthenticationViewModel @Inject constructor( | |
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Conditionally creates a passkey after a successful password login. | ||
| * | ||
| * @param createPasskeyOnCredMan A suspend function that takes a [JSONObject] and returns a | ||
| * [GenericCredentialManagerResponse]. This function is responsible for creating | ||
| * the passkey. | ||
| */ | ||
| fun conditionalCreatePasskey( | ||
| createPasskeyOnCredMan: suspend (createPasskeyRequestObj: JSONObject) -> GenericCredentialManagerResponse, | ||
| ) { | ||
| coroutineScope.launch { | ||
| when (val result = repository.registerPasskeyCreationRequest()) { | ||
| is AuthResult.Success -> { | ||
| val createPasskeyResponse = createPasskeyOnCredMan(result.data) | ||
| if (createPasskeyResponse is GenericCredentialManagerResponse.CreatePasskeySuccess) { | ||
| repository.registerPasskeyCreationResponse(createPasskeyResponse.createPasskeyResponse) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The result of val responseResult = repository.registerPasskeyCreationResponse(createPasskeyResponse.createPasskeyResponse)
if (responseResult is AuthResult.Failure) {
Log.e(TAG, "Failed to register conditional passkey with server: ${responseResult.error}")
} |
||
| } | ||
| } | ||
|
|
||
| is AuthResult.Failure -> { | ||
| Log.e(TAG, "Error during conditional passkey creation.") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a user signs in with a password (
isPasswordCredentialis true), bothviewModel.conditionalCreatePasskey()andcreateRestoreKey()are called. These functions trigger asynchronous credential creation flows that can run in parallel. This could lead to a confusing user experience with multiple system prompts for creating credentials appearing simultaneously, and may also cause race conditions. It would be better to make these calls mutually exclusive. For instance, you could offer to create a standard passkey after a password login, and offer to create a restore key after a passkey login.