Skip to content

Commit

Permalink
Merge pull request #826 from magiclabs/PDEEXP-1951-Lost-Device-Event-…
Browse files Browse the repository at this point in the history
…Does-Not-Emit-Whitelabel-MFA-provider

Pdeexp 1951 lost device event does not emit whitelabel mfa provider
  • Loading branch information
Ethella authored Oct 25, 2024
2 parents a03dc68 + b5839f6 commit adf0d5d
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 51 deletions.
9 changes: 9 additions & 0 deletions packages/@magic-sdk/provider/src/modules/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ export class AuthModule extends BaseModule {
handle.on(LoginWithEmailOTPEventEmit.VerifyMFACode, (mfa: string) => {
this.createIntermediaryEvent(LoginWithEmailOTPEventEmit.VerifyMFACode, requestPayload.id as string)(mfa);
});
handle.on(LoginWithEmailOTPEventEmit.LostDevice, () => {
this.createIntermediaryEvent(LoginWithEmailOTPEventEmit.LostDevice, requestPayload.id as string)();
});
handle.on(LoginWithEmailOTPEventEmit.VerifyRecoveryCode, (recoveryCode: string) => {
this.createIntermediaryEvent(
LoginWithEmailOTPEventEmit.VerifyRecoveryCode,
requestPayload.id as string,
)(recoveryCode);
});
handle.on(LoginWithEmailOTPEventEmit.Cancel, () => {
this.createIntermediaryEvent(LoginWithEmailOTPEventEmit.Cancel, requestPayload.id as any)();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,41 @@ test('Generates JSON RPC pending for verify-mfa-code', () => {
const intermediaryEventSecondMethod = magic.auth.createIntermediaryEvent.mock.calls[1][0];
expect(intermediaryEventSecondMethod).toBe('cancel');
});

test('Generates JSON RPC pending for lost-device', () => {
const magic = createMagicSDK();
magic.auth.overlay.post = jest.fn().mockImplementation(() => new Promise(() => {}));
const createIntermediaryEventFn = jest.fn();
magic.auth.createIntermediaryEvent = jest.fn().mockImplementation(() => createIntermediaryEventFn);

const handle = magic.auth.loginWithEmailOTP({ email: expectedEmail, showUI: false });

handle.emit('lost-device');
handle.emit('cancel');

const verifyEvent = magic.auth.createIntermediaryEvent.mock.calls[0];
expect(verifyEvent[0]).toBe('lost-device');

const intermediaryEventSecondMethod = magic.auth.createIntermediaryEvent.mock.calls[1][0];
expect(intermediaryEventSecondMethod).toBe('cancel');
});

test('Generates JSON RPC pending for verify-recovery-code', () => {
const magic = createMagicSDK();
magic.auth.overlay.post = jest.fn().mockImplementation(() => new Promise(() => {}));
const createIntermediaryEventFn = jest.fn();
magic.auth.createIntermediaryEvent = jest.fn().mockImplementation(() => createIntermediaryEventFn);

const handle = magic.auth.loginWithEmailOTP({ email: expectedEmail, showUI: false });

const recovery_code = '10epf6fk';
handle.emit('verify-recovery-code', recovery_code);
handle.emit('cancel');

const verifyEvent = magic.auth.createIntermediaryEvent.mock.calls[0];
expect(verifyEvent[0]).toBe('verify-recovery-code');
expect(createIntermediaryEventFn.mock.calls[0][0]).toBe(recovery_code);

const intermediaryEventSecondMethod = magic.auth.createIntermediaryEvent.mock.calls[1][0];
expect(intermediaryEventSecondMethod).toBe('cancel');
});
10 changes: 10 additions & 0 deletions packages/@magic-sdk/types/src/modules/auth-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ export enum LoginWithMagicLinkEventOnReceived {
export enum LoginWithEmailOTPEventEmit {
VerifyEmailOtp = 'verify-email-otp',
VerifyMFACode = 'verify-mfa-code',
LostDevice = 'lost-device',
VerifyRecoveryCode = 'verify-recovery-code',
Cancel = 'cancel',
}

Expand All @@ -171,6 +173,9 @@ export enum LoginWithEmailOTPEventOnReceived {
InvalidMfaOtp = 'invalid-mfa-otp',
ExpiredEmailOtp = 'expired-email-otp',
MfaSentHandle = 'mfa-sent-handle',
RecoveryCodeSentHandle = 'recovery-code-sent-handle',
InvalidRecoveryCode = 'invalid-recovery-code',
RecoveryCodeSuccess = 'recovery-code-success',
}

export enum DeviceVerificationEventEmit {
Expand Down Expand Up @@ -278,12 +283,17 @@ export type LoginWithEmailOTPEventHandlers = {
[LoginWithEmailOTPEventOnReceived.InvalidMfaOtp]: () => void;
[LoginWithEmailOTPEventOnReceived.ExpiredEmailOtp]: () => void;
[LoginWithEmailOTPEventOnReceived.MfaSentHandle]: () => void;
[LoginWithEmailOTPEventOnReceived.RecoveryCodeSentHandle]: () => void;
[LoginWithEmailOTPEventOnReceived.InvalidRecoveryCode]: () => void;
[LoginWithEmailOTPEventOnReceived.RecoveryCodeSuccess]: () => void;
[AuthEventOnReceived.IDTokenCreated]: (idToken: string) => void;
[WalletEventOnReceived.WalletInfoFetched]: () => void;

// Event sent
[LoginWithEmailOTPEventEmit.VerifyEmailOtp]: (otp: string) => void;
[LoginWithEmailOTPEventEmit.VerifyMFACode]: (mfa: string) => void;
[LoginWithEmailOTPEventEmit.LostDevice]: () => void;
[LoginWithEmailOTPEventEmit.VerifyRecoveryCode]: (recoveryCode: string) => void;
[LoginWithEmailOTPEventEmit.Cancel]: () => void;
} & DeviceVerificationEventHandlers;

Expand Down
Loading

0 comments on commit adf0d5d

Please sign in to comment.