Refactor signing out devices to handle React 18 Strict Mode (#28414)
setSigningOutDeviceIds was adding the same device ID twice, and also possibly using an old reference to the value when updating it Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
f77d9b4bcb
commit
73db771ff3
1 changed files with 16 additions and 13 deletions
|
@ -9,6 +9,7 @@ Please see LICENSE files in the repository root for full details.
|
||||||
import React, { lazy, Suspense, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
import React, { lazy, Suspense, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { discoverAndValidateOIDCIssuerWellKnown, MatrixClient } from "matrix-js-sdk/src/matrix";
|
import { discoverAndValidateOIDCIssuerWellKnown, MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
|
import { defer } from "matrix-js-sdk/src/utils";
|
||||||
|
|
||||||
import { _t } from "../../../../../languageHandler";
|
import { _t } from "../../../../../languageHandler";
|
||||||
import Modal from "../../../../../Modal";
|
import Modal from "../../../../../Modal";
|
||||||
|
@ -108,31 +109,33 @@ const useSignOut = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let success = false;
|
||||||
try {
|
try {
|
||||||
setSigningOutDeviceIds([...signingOutDeviceIds, ...deviceIds]);
|
setSigningOutDeviceIds((signingOutDeviceIds) => [...signingOutDeviceIds, ...deviceIds]);
|
||||||
|
|
||||||
const onSignOutFinished = async (success: boolean): Promise<void> => {
|
|
||||||
if (success) {
|
|
||||||
await onSignoutResolvedCallback();
|
|
||||||
}
|
|
||||||
setSigningOutDeviceIds(signingOutDeviceIds.filter((deviceId) => !deviceIds.includes(deviceId)));
|
|
||||||
};
|
|
||||||
|
|
||||||
if (delegatedAuthAccountUrl) {
|
if (delegatedAuthAccountUrl) {
|
||||||
const [deviceId] = deviceIds;
|
const [deviceId] = deviceIds;
|
||||||
try {
|
try {
|
||||||
setSigningOutDeviceIds([...signingOutDeviceIds, deviceId]);
|
success = await confirmDelegatedAuthSignOut(delegatedAuthAccountUrl, deviceId);
|
||||||
const success = await confirmDelegatedAuthSignOut(delegatedAuthAccountUrl, deviceId);
|
|
||||||
await onSignOutFinished(success);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error deleting OIDC-aware sessions", error);
|
logger.error("Error deleting OIDC-aware sessions", error);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await deleteDevicesWithInteractiveAuth(matrixClient, deviceIds, onSignOutFinished);
|
const deferredSuccess = defer<boolean>();
|
||||||
|
await deleteDevicesWithInteractiveAuth(matrixClient, deviceIds, async (success) => {
|
||||||
|
deferredSuccess.resolve(success);
|
||||||
|
});
|
||||||
|
success = await deferredSuccess.promise;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error deleting sessions", error);
|
logger.error("Error deleting sessions", error);
|
||||||
setSigningOutDeviceIds(signingOutDeviceIds.filter((deviceId) => !deviceIds.includes(deviceId)));
|
} finally {
|
||||||
|
if (success) {
|
||||||
|
await onSignoutResolvedCallback();
|
||||||
|
}
|
||||||
|
setSigningOutDeviceIds((signingOutDeviceIds) =>
|
||||||
|
signingOutDeviceIds.filter((deviceId) => !deviceIds.includes(deviceId)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue