Merge branch 'renovate/playwright' into 'main'
[ProtonMail-WebClient.git] / packages / account / sso / passwordActions.ts
blob48e71a3bab1e62f283f57e696dcc1b4d0892645a
1 import type { UnknownAction } from '@reduxjs/toolkit';
2 import type { ThunkAction } from 'redux-thunk';
4 import type { ProtonThunkArguments } from '@proton/redux-shared-store-types';
5 import { getSilentApi } from '@proton/shared/lib/api/helpers/customConfig';
6 import innerMutatePassword from '@proton/shared/lib/authentication/mutate';
7 import { getDeviceSecretDataByUser } from '@proton/shared/lib/keys/device';
8 import { changeSSOUserKeysPasswordHelper } from '@proton/shared/lib/keys/password';
10 import { userThunk } from '../user';
11 import type { UserKeysState } from '../userKeys';
12 import { userKeysThunk } from '../userKeys';
14 export const changeSSOUserBackupPassword = ({
15     newBackupPassword,
16 }: {
17     newBackupPassword: string;
18 }): ThunkAction<Promise<void>, UserKeysState, ProtonThunkArguments, UnknownAction> => {
19     return async (dispatch, getState, extra) => {
20         const [user, userKeys] = await Promise.all([dispatch(userThunk()), dispatch(userKeysThunk())]);
21         const deviceSecretData = await getDeviceSecretDataByUser({ user });
23         const api = extra.api;
24         const authentication = extra.authentication;
26         const { keyPassword } = await changeSSOUserKeysPasswordHelper({
27             newBackupPassword,
28             api: getSilentApi(api),
29             user,
30             userKeys,
31             deviceSecretData,
32         });
34         await innerMutatePassword({
35             api,
36             authentication,
37             keyPassword,
38             clearKeyPassword: newBackupPassword,
39             User: user,
40         });
41     };