diff --git a/lib/hooks/login-hooks.js b/lib/hooks/login-hooks.js --- a/lib/hooks/login-hooks.js +++ b/lib/hooks/login-hooks.js @@ -13,6 +13,7 @@ } from '../actions/user-actions.js'; import { useKeyserverAuthWithRetry } from '../keyserver-conn/keyserver-auth.js'; import { logInActionSources } from '../types/account-types.js'; +import type { IdentityAuthResult } from '../types/identity-service-types.js'; import { authoritativeKeyserverID } from '../utils/authoritative-keyserver.js'; import { useDispatchActionPromise } from '../utils/redux-promise-utils.js'; import { useSelector, useDispatch } from '../utils/redux-utils.js'; @@ -27,8 +28,9 @@ | { +step: 'inactive' } | { +step: 'identity_login_dispatched', - +resolve: () => void, + +resolve: (authResult: IdentityAuthResult) => void, +reject: Error => void, + +authResult: IdentityAuthResult, }; const inactiveStep = { step: 'inactive' }; @@ -37,24 +39,27 @@ function useLogIn( loginFlow: LoginFlow, -): (identityAuthPromise: Promise<mixed>) => Promise<void> { +): ( + identityAuthPromise: Promise<IdentityAuthResult>, +) => Promise<IdentityAuthResult> { const [currentStep, setCurrentStep] = React.useState<CurrentStep>(inactiveStep); const returnedFunc = React.useCallback( - (promise: Promise<mixed>) => - new Promise<void>( + (promise: Promise<IdentityAuthResult>) => + new Promise<IdentityAuthResult>( // eslint-disable-next-line no-async-promise-executor async (resolve, reject) => { if (currentStep.step !== 'inactive') { return; } try { - await promise; + const authResult = await promise; setCurrentStep({ step: 'identity_login_dispatched', resolve, reject, + authResult, }); } catch (e) { reject(e); @@ -97,7 +102,7 @@ return; } registeringOnAuthoritativeKeyserverRef.current = true; - const { resolve, reject } = currentStep; + const { resolve, reject, authResult } = currentStep; void (async () => { try { await keyserverAuth({ @@ -114,7 +119,7 @@ dataLoaded: true, }, }); - resolve(); + resolve(authResult); } catch (e) { void dispatchActionPromise(logOutActionTypes, identityLogOut()); await waitUntilDatabaseDeleted(); @@ -139,7 +144,7 @@ function usePasswordLogIn(): ( username: string, password: string, -) => Promise<void> { +) => Promise<IdentityAuthResult> { const identityPasswordLogIn = useIdentityPasswordLogIn(); const dispatchActionPromise = useDispatchActionPromise(); const identityPasswordAuth = React.useCallback( @@ -163,7 +168,7 @@ walletAddress: string, siweMessage: string, siweSignature: string, -) => Promise<void> { +) => Promise<IdentityAuthResult> { const identityWalletLogIn = useIdentityWalletLogIn(); const dispatchActionPromise = useDispatchActionPromise(); const identityWalletAuth = React.useCallback( @@ -187,11 +192,13 @@ ); } -function useSecondaryDeviceLogIn(): (userID: string) => Promise<void> { +function useSecondaryDeviceLogIn(): ( + userID: string, +) => Promise<IdentityAuthResult> { const identitySecondaryDeviceLogIn = useIdentitySecondaryDeviceLogIn(); const dispatchActionPromise = useDispatchActionPromise(); const identitySecondaryDeviceAuth = React.useCallback( - (userID: string) => { + (userID: string): Promise<IdentityAuthResult> => { const promise = identitySecondaryDeviceLogIn(userID); void dispatchActionPromise(identityLogInActionTypes, promise); return promise; diff --git a/native/account/log-in-panel.react.js b/native/account/log-in-panel.react.js --- a/native/account/log-in-panel.react.js +++ b/native/account/log-in-panel.react.js @@ -26,6 +26,7 @@ type LegacyLogInStartingPayload, logInActionSources, } from 'lib/types/account-types.js'; +import type { IdentityAuthResult } from 'lib/types/identity-service-types.js'; import type { LoadingStatus } from 'lib/types/loading-types.js'; import { getMessageForException } from 'lib/utils/errors.js'; import { @@ -70,7 +71,10 @@ +legacyLogInExtraInfo: () => Promise<LegacyLogInExtraInfo>, +dispatchActionPromise: DispatchActionPromise, +legacyLogIn: (logInInfo: LegacyLogInInfo) => Promise<LegacyLogInResult>, - +identityPasswordLogIn: (username: string, password: string) => Promise<void>, + +identityPasswordLogIn: ( + username: string, + password: string, + ) => Promise<IdentityAuthResult>, +getInitialNotificationsEncryptedMessage: () => Promise<string>, }; type State = { diff --git a/native/account/restore.js b/native/account/restore.js --- a/native/account/restore.js +++ b/native/account/restore.js @@ -14,8 +14,11 @@ useWalletLogIn, } from 'lib/hooks/login-hooks.js'; import { IdentityClientContext } from 'lib/shared/identity-client-context.js'; -import type { SignedDeviceList } from 'lib/types/identity-service-types.js'; -import { platformToIdentityDeviceType } from 'lib/types/identity-service-types.js'; +import { + type IdentityAuthResult, + type SignedDeviceList, + platformToIdentityDeviceType, +} from 'lib/types/identity-service-types.js'; import type { SignedMessage } from 'lib/types/siwe-types.js'; import { getConfig } from 'lib/utils/config.js'; import { getContentSigningKey } from 'lib/utils/crypto-utils.js'; @@ -55,7 +58,7 @@ userIdentifier: string, secret: string, siweSocialProof?: SignedMessage, - ) => { + ): Promise<RestoreUserResult> => { //1. Runs Key Generation const { olmAPI } = getConfig(); await olmAPI.initializeCryptoAccount(); @@ -149,18 +152,25 @@ userIdentifier: string, secret: string, siweSocialProof?: SignedMessage, -) => Promise<void> { +) => Promise<IdentityAuthResult> { const restoreProtocol = useRestoreProtocol(); const dispatchActionPromise = useDispatchActionPromise(); const restoreAuth = React.useCallback( - ( + async ( userIdentifier: string, secret: string, siweSocialProof?: SignedMessage, - ) => { + ): Promise<IdentityAuthResult> => { const promise = restoreProtocol(userIdentifier, secret, siweSocialProof); void dispatchActionPromise(restoreUserActionTypes, promise); - return promise; + const { userID, accessToken, username, preRequestUserState } = + await promise; + return { + userID, + accessToken, + username, + preRequestUserState, + }; }, [dispatchActionPromise, restoreProtocol], );