Skip to content

Commit

Permalink
Fix unhandler error when storing password credentials (#4983)
Browse files Browse the repository at this point in the history
* Init

* Fix unhandle no credential key error

* Add changeset

* Fix typing

* CR fixess
  • Loading branch information
poulch committed Jun 24, 2024
1 parent 7ac3a40 commit 2c855d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/tricky-lamps-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

An error is no longer raised and visible to the user when saving credential is not supported
23 changes: 10 additions & 13 deletions src/utils/credentialsManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,23 @@ export async function checkIfCredentialsExist() {
return true;
}

export function saveCredentials(
export async function saveCredentials(
user: UserFragment | UserDetailsFragment,
password: string,
): Promise<CredentialType> | null {
let result: Promise<CredentialType> | null;
): Promise<CredentialType | null> {
if (!isSupported) {
return null;
}

if (isSupported) {
try {
const cred = new PasswordCredential({
id: user.email,
name: user.firstName ? `${user.firstName} ${user.lastName}` : undefined,
password,
});
try {
result = navigator.credentials.store(cred);
} catch {
result = null;
}
} else {
result = null;
}

return result;
return await navigator.credentials.store(cred);
} catch {
return null;
}
}

0 comments on commit 2c855d1

Please sign in to comment.