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 = ({
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({
28 api: getSilentApi(api),
34 await innerMutatePassword({
38 clearKeyPassword: newBackupPassword,