Skip to content

Commit

Permalink
feat: implement recover account method
Browse files Browse the repository at this point in the history
  • Loading branch information
sherzod-bakhodirov committed Nov 6, 2024
1 parent 39ddb72 commit d48cfc0
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions packages/@magic-sdk/provider/src/modules/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
RecencyCheckEventEmit,
RecoveryFactorEventHandlers,
RecoveryFactorEventEmit,
RecoverAccountEventHandlers,
RecoverAccountEventEmit,
} from '@magic-sdk/types';
import { getItem, setItem, removeItem } from '../util/storage';
import { BaseModule } from './base-module';
Expand Down Expand Up @@ -143,11 +145,23 @@ export class UserModule extends BaseModule {
}

public recoverAccount(configuration: RecoverAccountConfiguration) {
const requestPayload = createJsonRpcRequestPayload(
this.sdk.testMode ? MagicPayloadMethod.RecoverAccountTestMode : MagicPayloadMethod.RecoverAccount,
[configuration],
);
return this.request<boolean | null>(requestPayload);
const { email, showUI } = configuration;
const requestPayload = createJsonRpcRequestPayload(MagicPayloadMethod.EnableMFA, [{ email, showUI }]);
const handle = this.request<string | boolean | null, RecoverAccountEventHandlers>(requestPayload);

if (!showUI && handle) {
handle.on(RecoverAccountEventEmit.Cancel, () => {
this.createIntermediaryEvent(RecoverAccountEventEmit.Cancel, requestPayload.id as string)();
});
handle.on(RecoverAccountEventEmit.ResendSms, () => {
this.createIntermediaryEvent(RecoverAccountEventEmit.ResendSms, requestPayload.id as string)();
});
handle.on(RecoverAccountEventEmit.VerifyOtp, (otp: string) => {
this.createIntermediaryEvent(RecoverAccountEventEmit.VerifyOtp, requestPayload.id as string)(otp);
});
}

return handle;
}

public revealPrivateKey() {
Expand Down

0 comments on commit d48cfc0

Please sign in to comment.