Fix crash chrome on logout (#4027)
This commit is contained in:
parent
80ef369f8a
commit
922c9fb4ce
4 changed files with 40 additions and 1 deletions
5
.changeset/stale-kings-compare.md
Normal file
5
.changeset/stale-kings-compare.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"saleor-dashboard": patch
|
||||
---
|
||||
|
||||
Fix Chrome browser crash when user click logout button
|
|
@ -8,6 +8,8 @@ import { useIntl } from "react-intl";
|
|||
|
||||
import { useAuthProvider } from "./hooks/useAuthProvider";
|
||||
|
||||
const originalWindowNavigator = window.navigator;
|
||||
|
||||
const adminCredentials = {
|
||||
email: "admin@example.com",
|
||||
password: "admin",
|
||||
|
@ -22,6 +24,24 @@ const nonStaffUserCredentials = {
|
|||
beforeEach(() => {
|
||||
localStorage.clear();
|
||||
sessionStorage.clear();
|
||||
|
||||
Object.defineProperty(window, "navigator", {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
value: {
|
||||
credentials: {
|
||||
get: jest.fn(),
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
Object.defineProperty(window, "navigator", {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
value: originalWindowNavigator,
|
||||
});
|
||||
});
|
||||
|
||||
jest.mock("react-intl", () => ({
|
||||
|
|
|
@ -7,6 +7,7 @@ import useLocalStorage from "@dashboard/hooks/useLocalStorage";
|
|||
import useNavigator from "@dashboard/hooks/useNavigator";
|
||||
import { commonMessages } from "@dashboard/intl";
|
||||
import {
|
||||
checkIfCredentialsExist,
|
||||
isSupported as isCredentialsManagementAPISupported,
|
||||
login as loginWithCredentialsManagementAPI,
|
||||
saveCredentials,
|
||||
|
@ -109,7 +110,10 @@ export function useAuthProvider({
|
|||
} as RequestExternalLogoutInput),
|
||||
});
|
||||
|
||||
if (isCredentialsManagementAPISupported) {
|
||||
// Clear credentials from browser's credential manager only when exist.
|
||||
// Chrome 115 crash when calling preventSilentAccess() when no credentials exist.
|
||||
const hasCredentials = await checkIfCredentialsExist();
|
||||
if (isCredentialsManagementAPISupported && !!hasCredentials) {
|
||||
navigator.credentials.preventSilentAccess();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,16 @@ export async function login<T>(
|
|||
return result!;
|
||||
}
|
||||
|
||||
export async function checkIfCredentialsExist() {
|
||||
const credential = await navigator.credentials.get({ password: true });
|
||||
|
||||
if (credential === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function saveCredentials(
|
||||
user: UserFragment | UserDetailsFragment,
|
||||
password: string,
|
||||
|
|
Loading…
Reference in a new issue