Skip to content

Commit c45845c

Browse files
committed
save the response
1 parent 1249235 commit c45845c

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

auth/src/main/java/com/firebase/ui/auth/viewmodel/credentialmanager/CredentialManagerHandler.kt

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.firebase.ui.auth.viewmodel.credentialmanager
22

33
import android.app.Application
4-
import androidx.lifecycle.ViewModel
4+
import android.content.Context
55
import androidx.lifecycle.viewModelScope
66
import androidx.credentials.CreatePasswordRequest
77
import androidx.credentials.CredentialManager
8+
import androidx.credentials.CreateCredentialResponse
89
import androidx.credentials.exceptions.CreateCredentialException
910
import com.firebase.ui.auth.ErrorCodes
1011
import com.firebase.ui.auth.FirebaseUiException
@@ -29,7 +30,7 @@ class CredentialManagerHandler(application: Application) :
2930
* Uses a password-based credential for demonstration; adapt to passkeys or other flows as needed.
3031
*/
3132
fun saveCredentials(
32-
activity: androidx.activity.ComponentActivity,
33+
context: Context,
3334
firebaseUser: FirebaseUser?,
3435
password: String?
3536
) {
@@ -59,8 +60,23 @@ class CredentialManagerHandler(application: Application) :
5960

6061
viewModelScope.launch {
6162
try {
62-
credentialManager.createCredential(activity, request)
63-
setResult(Resource.forSuccess(response!!))
63+
// Use the createCredential function and store the response
64+
val createResponse: CreateCredentialResponse =
65+
credentialManager.createCredential(context, request)
66+
67+
// If the response is successful, set the success result
68+
if (createResponse != null) {
69+
setResult(Resource.forSuccess(response!!))
70+
} else {
71+
setResult(
72+
Resource.forFailure(
73+
FirebaseUiException(
74+
ErrorCodes.UNKNOWN_ERROR,
75+
"Received null response from Credential Manager."
76+
)
77+
)
78+
)
79+
}
6480
} catch (e: CreateCredentialException) {
6581
setResult(
6682
Resource.forFailure(

0 commit comments

Comments
 (0)