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 @@ -474,11 +474,27 @@ calendarQuery: CalendarQuery, }; -const tempIdentityLoginActionTypes = Object.freeze({ - started: 'TEMP_IDENTITY_LOG_IN_STARTED', - success: 'TEMP_IDENTITY_LOG_IN_SUCCESS', - failed: 'TEMP_IDENTITY_LOG_IN_FAILED', +const identityLogInActionTypes = Object.freeze({ + started: 'IDENTITY_LOG_IN_STARTED', + success: 'IDENTITY_LOG_IN_SUCCESS', + failed: 'IDENTITY_LOG_IN_FAILED', }); +function useIdentityPasswordLogIn(): ( + username: string, + password: string, +) => Promise { + const client = React.useContext(IdentityClientContext); + const identityClient = client?.identityClient; + return React.useCallback( + (username, password) => { + if (!identityClient) { + throw new Error('Identity service client is not initialized'); + } + return identityClient.logInPasswordUser(username, password); + }, + [identityClient], + ); +} const logInActionTypes = Object.freeze({ started: 'LOG_IN_STARTED', @@ -771,7 +787,8 @@ getOlmSessionInitializationData, mergeUserInfos, logIn as logInRawAction, - tempIdentityLoginActionTypes, + identityLogInActionTypes, + useIdentityPasswordLogIn, useLogIn, logInActionTypes, useLogOut, diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js --- a/lib/types/redux-types.js +++ b/lib/types/redux-types.js @@ -344,19 +344,19 @@ +loadingInfo: LoadingInfo, } | { - +type: 'TEMP_IDENTITY_LOG_IN_STARTED', + +type: 'IDENTITY_LOG_IN_STARTED', +loadingInfo: LoadingInfo, +payload?: void, } | { - +type: 'TEMP_IDENTITY_LOG_IN_FAILED', + +type: 'IDENTITY_LOG_IN_FAILED', +error: true, +payload: Error, +loadingInfo: LoadingInfo, } | { - +type: 'TEMP_IDENTITY_LOG_IN_SUCCESS', - +payload?: void, + +type: 'IDENTITY_LOG_IN_SUCCESS', + +payload: IdentityAuthResult, +loadingInfo: LoadingInfo, } | {