Skip to content

Commit f29d7d1

Browse files
committed
Safer handling of null property value
1 parent 65d23cb commit f29d7d1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/profile-sync-controller/src/controllers/authentication/AuthenticationController.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,15 @@ const metadata: StateMetadata<AuthenticationControllerState> = {
5252
srpSessionData: {
5353
// Remove access token from state logs
5454
includeInStateLogs: (srpSessionData) => {
55-
// Using non-null assertion here to assert that it's not undefined, because if it was, this
56-
// wouldn't get called.
57-
// The type includes `| undefined` only because we don't yet use `strictOptionalTypes`
58-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
59-
return Object.entries(srpSessionData!).reduce<Record<string, Json>>(
55+
// Unreachable branch, included just to fix a type error for the case where this property is
56+
// unset. The type gets collapsed to include `| undefined` even though `undefined` is never
57+
// set here, because we don't yet use `exactOptionalPropertyTypes`.
58+
// TODO: Remove branch after enabling `exactOptionalPropertyTypes`
59+
// ref: https://github.com/MetaMask/core/issues/6565
60+
if (srpSessionData === null || srpSessionData === undefined) {
61+
return null;
62+
}
63+
return Object.entries(srpSessionData).reduce<Record<string, Json>>(
6064
(sanitizedSrpSessionData, [key, value]) => {
6165
const { accessToken: _unused, ...tokenWithoutAccessToken } =
6266
value.token;

0 commit comments

Comments
 (0)