Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit e64b6b0

Browse files
authored
Merge pull request #5448 from matrix-org/jryans/lifecycle-customisations
Add lifecycle customisation point after logout
2 parents edd5bf5 + 25cc4b8 commit e64b6b0

File tree

3 files changed

+39
-18
lines changed

3 files changed

+39
-18
lines changed

src/Lifecycle.ts

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {SSO_HOMESERVER_URL_KEY, SSO_ID_SERVER_URL_KEY} from "./BasePlatform";
4949
import ThreepidInviteStore from "./stores/ThreepidInviteStore";
5050
import CountlyAnalytics from "./CountlyAnalytics";
5151
import CallHandler from './CallHandler';
52+
import LifecycleCustomisations from "./customisations/Lifecycle";
5253

5354
const HOMESERVER_URL_KEY = "mx_hs_url";
5455
const ID_SERVER_URL_KEY = "mx_is_url";
@@ -716,6 +717,7 @@ export async function onLoggedOut(): Promise<void> {
716717
dis.dispatch({action: 'on_logged_out'}, true);
717718
stopMatrixClient();
718719
await clearStorage({deleteEverything: true});
720+
LifecycleCustomisations.onLoggedOutAndStorageCleared?.();
719721
}
720722

721723
/**

src/customisations/Lifecycle.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright 2020 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
function onLoggedOutAndStorageCleared(): void {
18+
// E.g. redirect user or call other APIs after logout
19+
}
20+
21+
// This interface summarises all available customisation points and also marks
22+
// them all as optional. This allows customisers to only define and export the
23+
// customisations they need while still maintaining type safety.
24+
export interface ILifecycleCustomisations {
25+
onLoggedOutAndStorageCleared?: typeof onLoggedOutAndStorageCleared;
26+
}
27+
28+
// A real customisation module will define and export one or more of the
29+
// customisation points that make up `ILifecycleCustomisations`.
30+
export default {} as ILifecycleCustomisations;

src/customisations/Security.ts

+7-18
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,13 @@ function setupEncryptionNeeded(kind: SetupEncryptionKind): boolean {
6767
// them all as optional. This allows customisers to only define and export the
6868
// customisations they need while still maintaining type safety.
6969
export interface ISecurityCustomisations {
70-
examineLoginResponse?: (
71-
response: any,
72-
credentials: IMatrixClientCreds,
73-
) => void;
74-
persistCredentials?: (
75-
credentials: IMatrixClientCreds,
76-
) => void;
77-
createSecretStorageKey?: () => Uint8Array,
78-
getSecretStorageKey?: () => Uint8Array,
79-
catchAccessSecretStorageError?: (
80-
e: Error,
81-
) => void,
82-
setupEncryptionNeeded?: (
83-
kind: SetupEncryptionKind,
84-
) => boolean,
85-
getDehydrationKey?: (
86-
keyInfo: ISecretStorageKeyInfo,
87-
) => Promise<Uint8Array>,
70+
examineLoginResponse?: typeof examineLoginResponse;
71+
persistCredentials?: typeof persistCredentials;
72+
createSecretStorageKey?: typeof createSecretStorageKey,
73+
getSecretStorageKey?: typeof getSecretStorageKey,
74+
catchAccessSecretStorageError?: typeof catchAccessSecretStorageError,
75+
setupEncryptionNeeded?: typeof setupEncryptionNeeded,
76+
getDehydrationKey?: typeof getDehydrationKey,
8877
}
8978

9079
// A real customisation module will define and export one or more of the

0 commit comments

Comments
 (0)