@@ -168,7 +168,7 @@ export async function loadSession(opts: ILoadSessionOpts = {}): Promise<boolean>
168
168
* Gets the user ID of the persisted session, if one exists. This does not validate
169
169
* that the user's credentials still work, just that they exist and that a user ID
170
170
* is associated with them. The session is not loaded.
171
- * @returns {[String, bool ] } The persisted session's owner and whether the stored
171
+ * @returns {[string, boolean ] } The persisted session's owner and whether the stored
172
172
* session is for a guest user, if an owner exists. If there is no stored session,
173
173
* return [null, null].
174
174
*/
@@ -494,7 +494,7 @@ async function handleLoadSessionFailure(e: Error): Promise<boolean> {
494
494
* Also stops the old MatrixClient and clears old credentials/etc out of
495
495
* storage before starting the new client.
496
496
*
497
- * @param {MatrixClientCreds } credentials The credentials to use
497
+ * @param {IMatrixClientCreds } credentials The credentials to use
498
498
*
499
499
* @returns {Promise } promise which resolves to the new MatrixClient once it has been started
500
500
*/
@@ -525,7 +525,7 @@ export async function setLoggedIn(credentials: IMatrixClientCreds): Promise<Matr
525
525
* If the credentials belong to a different user from the session already stored,
526
526
* the old session will be cleared automatically.
527
527
*
528
- * @param {MatrixClientCreds } credentials The credentials to use
528
+ * @param {IMatrixClientCreds } credentials The credentials to use
529
529
*
530
530
* @returns {Promise } promise which resolves to the new MatrixClient once it has been started
531
531
*/
@@ -731,27 +731,25 @@ export function logout(): void {
731
731
if ( MatrixClientPeg . get ( ) . isGuest ( ) ) {
732
732
// logout doesn't work for guest sessions
733
733
// Also we sometimes want to re-log in a guest session if we abort the login.
734
- // defer until next tick because it calls a synchronous dispatch and we are likely here from a dispatch.
734
+ // defer until next tick because it calls a synchronous dispatch, and we are likely here from a dispatch.
735
735
setImmediate ( ( ) => onLoggedOut ( ) ) ;
736
736
return ;
737
737
}
738
738
739
739
_isLoggingOut = true ;
740
740
const client = MatrixClientPeg . get ( ) ;
741
741
PlatformPeg . get ( ) . destroyPickleKey ( client . getUserId ( ) , client . getDeviceId ( ) ) ;
742
- client . logout ( ) . then ( onLoggedOut ,
743
- ( err ) => {
744
- // Just throwing an error here is going to be very unhelpful
745
- // if you're trying to log out because your server's down and
746
- // you want to log into a different server, so just forget the
747
- // access token. It's annoying that this will leave the access
748
- // token still valid, but we should fix this by having access
749
- // tokens expire (and if you really think you've been compromised,
750
- // change your password).
751
- logger . log ( "Failed to call logout API: token will not be invalidated" ) ;
752
- onLoggedOut ( ) ;
753
- } ,
754
- ) ;
742
+ client . logout ( undefined , true ) . then ( onLoggedOut , ( err ) => {
743
+ // Just throwing an error here is going to be very unhelpful
744
+ // if you're trying to log out because your server's down and
745
+ // you want to log into a different server, so just forget the
746
+ // access token. It's annoying that this will leave the access
747
+ // token still valid, but we should fix this by having access
748
+ // tokens expire (and if you really think you've been compromised,
749
+ // change your password).
750
+ logger . warn ( "Failed to call logout API: token will not be invalidated" , err ) ;
751
+ onLoggedOut ( ) ;
752
+ } ) ;
755
753
}
756
754
757
755
export function softLogout ( ) : void {
@@ -856,9 +854,8 @@ async function startMatrixClient(startSyncing = true): Promise<void> {
856
854
* storage. Used after a session has been logged out.
857
855
*/
858
856
export async function onLoggedOut ( ) : Promise < void > {
859
- _isLoggingOut = false ;
860
857
// Ensure that we dispatch a view change **before** stopping the client,
861
- // so that React components unmount first. This avoids React soft crashes
858
+ // that React components unmount first. This avoids React soft crashes
862
859
// that can occur when components try to use a null client.
863
860
dis . fire ( Action . OnLoggedOut , true ) ;
864
861
stopMatrixClient ( ) ;
@@ -869,8 +866,13 @@ export async function onLoggedOut(): Promise<void> {
869
866
// customisations got the memo.
870
867
if ( SdkConfig . get ( ) . logout_redirect_url ) {
871
868
logger . log ( "Redirecting to external provider to finish logout" ) ;
872
- window . location . href = SdkConfig . get ( ) . logout_redirect_url ;
869
+ // XXX: Defer this so that it doesn't race with MatrixChat unmounting the world by going to /#/login
870
+ setTimeout ( ( ) => {
871
+ window . location . href = SdkConfig . get ( ) . logout_redirect_url ;
872
+ } , 100 ) ;
873
873
}
874
+ // Do this last to prevent racing `stopMatrixClient` and `on_logged_out` with MatrixChat handling Session.logged_out
875
+ _isLoggingOut = false ;
874
876
}
875
877
876
878
/**
@@ -908,9 +910,7 @@ async function clearStorage(opts?: { deleteEverything?: boolean }): Promise<void
908
910
}
909
911
}
910
912
911
- if ( window . sessionStorage ) {
912
- window . sessionStorage . clear ( ) ;
913
- }
913
+ window . sessionStorage ?. clear ( ) ;
914
914
915
915
// create a temporary client to clear out the persistent stores.
916
916
const cli = createMatrixClient ( {
@@ -937,7 +937,7 @@ export function stopMatrixClient(unsetClient = true): void {
937
937
IntegrationManagers . sharedInstance ( ) . stopWatching ( ) ;
938
938
Mjolnir . sharedInstance ( ) . stop ( ) ;
939
939
DeviceListener . sharedInstance ( ) . stop ( ) ;
940
- if ( DMRoomMap . shared ( ) ) DMRoomMap . shared ( ) . stop ( ) ;
940
+ DMRoomMap . shared ( ) ? .stop ( ) ;
941
941
EventIndexPeg . stop ( ) ;
942
942
const cli = MatrixClientPeg . get ( ) ;
943
943
if ( cli ) {
0 commit comments