diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js --- a/lib/actions/user-actions.js +++ b/lib/actions/user-actions.js @@ -84,7 +84,8 @@ success: 'LOG_OUT_SUCCESS', failed: 'LOG_OUT_FAILED', }); -const logOut = + +const keyserverLogOut = ( callKeyserverEndpoint: CallKeyserverEndpoint, allKeyserverIDs: $ReadOnlyArray, @@ -103,7 +104,7 @@ callKeyserverEndpoint('log_out', requests), (async () => { await sleep(500); - throw new Error('log_out took more than 500ms'); + throw new Error('keyserver log_out took more than 500ms'); })(), ]); } catch {} @@ -114,8 +115,11 @@ function useLogOut(): ( keyserverIDs?: $ReadOnlyArray, ) => Promise { + const client = React.useContext(IdentityClientContext); + const identityClient = client?.identityClient; + const preRequestUserState = useSelector(preRequestUserStateSelector); - const callKeyserverLogOut = useKeyserverCall(logOut); + const callKeyserverLogOut = useKeyserverCall(keyserverLogOut); const commServicesAccessToken = useSelector( state => state.commServicesAccessToken, @@ -123,10 +127,29 @@ return React.useCallback( async (keyserverIDs?: $ReadOnlyArray) => { - const { keyserverIDs: _, ...result } = await callKeyserverLogOut({ - preRequestUserState, - keyserverIDs, - }); + const identityPromise = (async () => { + if (!usingCommServicesAccessToken) { + return; + } + invariant(identityClient, 'Identity client should be set'); + try { + await Promise.race([ + identityClient.logOut(), + (async () => { + await sleep(500); + throw new Error('identity log_out took more than 500ms'); + })(), + ]); + } catch {} + })(); + + const [{ keyserverIDs: _, ...result }] = await Promise.all([ + callKeyserverLogOut({ + preRequestUserState, + keyserverIDs, + }), + identityPromise, + ]); return { ...result, preRequestUserState: { @@ -135,7 +158,12 @@ }, }; }, - [callKeyserverLogOut, commServicesAccessToken, preRequestUserState], + [ + callKeyserverLogOut, + commServicesAccessToken, + identityClient, + preRequestUserState, + ], ); } diff --git a/lib/types/identity-service-types.js b/lib/types/identity-service-types.js --- a/lib/types/identity-service-types.js +++ b/lib/types/identity-service-types.js @@ -98,6 +98,7 @@ export interface IdentityServiceClient { +deleteUser: () => Promise; + +logOut: () => Promise; +getKeyserverKeys: string => Promise; +registerPasswordUser?: ( username: string, diff --git a/native/identity-service/identity-service-context-provider.react.js b/native/identity-service/identity-service-context-provider.react.js --- a/native/identity-service/identity-service-context-provider.react.js +++ b/native/identity-service/identity-service-context-provider.react.js @@ -84,6 +84,14 @@ } = await getAuthMetadata(); return commRustModule.deleteUser(userID, deviceID, token); }, + logOut: async () => { + const { + deviceID, + userID, + accessToken: token, + } = await getAuthMetadata(); + return commRustModule.logOut(userID, deviceID, token); + }, getKeyserverKeys: async ( keyserverID: string, ): Promise => { diff --git a/web/grpc/identity-service-client-proxy.js b/web/grpc/identity-service-client-proxy.js --- a/web/grpc/identity-service-client-proxy.js +++ b/web/grpc/identity-service-client-proxy.js @@ -73,6 +73,8 @@ deleteUser: () => Promise = this.proxyToWorker('deleteUser'); + logOut: () => Promise = this.proxyToWorker('logOut'); + getKeyserverKeys: (keyserverID: string) => Promise = this.proxyToWorker('getKeyserverKeys'); diff --git a/web/grpc/identity-service-client-wrapper.js b/web/grpc/identity-service-client-wrapper.js --- a/web/grpc/identity-service-client-wrapper.js +++ b/web/grpc/identity-service-client-wrapper.js @@ -130,6 +130,13 @@ await this.authClient.deleteUser(new Empty()); }; + logOut: () => Promise = async () => { + if (!this.authClient) { + throw new Error('Identity service client is not initialized'); + } + await this.authClient.logOutUser(new Empty()); + }; + getKeyserverKeys: (keyserverID: string) => Promise = async (keyserverID: string) => { const client = this.authClient;