Skip to content

Commit ecdc6e1

Browse files
committed
addressing PR feedbacks
1 parent ea509af commit ecdc6e1

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

spec/common/providers/identity.spec.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -772,34 +772,48 @@ describe("identity", () => {
772772
});
773773

774774
describe("generateRequestPayload", () => {
775-
const DISPLAY_NAME_FILED = "displayName";
775+
const DISPLAY_NAME_FIELD = "displayName";
776776
const TEST_RESPONSE = {
777777
displayName: TEST_NAME,
778778
recaptchaPassed: false,
779779
} as identity.BeforeCreateResponse;
780780

781781
const EXPECT_PAYLOAD = {
782-
userRecord: { displayName: TEST_NAME, updateMask: DISPLAY_NAME_FILED },
782+
userRecord: { displayName: TEST_NAME, updateMask: DISPLAY_NAME_FIELD },
783783
recaptchaPassed: false,
784784
};
785785

786+
const TEST_RESPONSE_RECAPTCHA_TRUE = {
787+
recaptchaPassed: true,
788+
} as identity.BeforeCreateResponse;
789+
790+
const EXPECT_PAYLOAD_RECAPTCHA_TRUE = {
791+
recaptchaPassed: true,
792+
};
793+
786794
const TEST_RESPONSE_RECAPTCHA_UNDEFINED = {
787795
displayName: TEST_NAME,
788796
} as identity.BeforeSignInResponse;
789797

790798
const EXPECT_PAYLOAD_UNDEFINED = {
791-
userRecord: { displayName: TEST_NAME, updateMask: DISPLAY_NAME_FILED },
799+
userRecord: { displayName: TEST_NAME, updateMask: DISPLAY_NAME_FIELD },
792800
};
793-
it("should return empty string on undefined response", () => {
794-
expect(identity.generateRequestPayload()).to.eq("");
801+
it("should return empty object on undefined response", () => {
802+
expect(identity.generateResponsePayload()).to.eql({});
795803
});
796804

797805
it("should exclude recaptchaPass field from updateMask", () => {
798-
expect(identity.generateRequestPayload(TEST_RESPONSE)).to.deep.equal(EXPECT_PAYLOAD);
806+
expect(identity.generateResponsePayload(TEST_RESPONSE)).to.deep.equal(EXPECT_PAYLOAD);
807+
});
808+
809+
it("should return recaptchaPass when it is true on response", () => {
810+
expect(identity.generateResponsePayload(TEST_RESPONSE_RECAPTCHA_TRUE)).to.deep.equal(
811+
EXPECT_PAYLOAD_RECAPTCHA_TRUE
812+
);
799813
});
800814

801815
it("should not return recaptchaPass if undefined", () => {
802-
const payload = identity.generateRequestPayload(TEST_RESPONSE_RECAPTCHA_UNDEFINED);
816+
const payload = identity.generateResponsePayload(TEST_RESPONSE_RECAPTCHA_UNDEFINED);
803817
expect(payload.hasOwnProperty("recaptchaPassed")).to.be.false;
804818
expect(payload).to.deep.equal(EXPECT_PAYLOAD_UNDEFINED);
805819
});

src/common/providers/identity.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,17 @@ export interface DecodedPayload {
433433
[key: string]: any;
434434
}
435435

436+
/** @internal */
437+
export interface ResponsePayload {
438+
userRecord?: UserRecordResponsePayload;
439+
recaptchaPassed?: boolean;
440+
}
441+
442+
/** @internal */
443+
export interface UserRecordResponsePayload extends Omit<BeforeSignInResponse, "recaptchaPassed"> {
444+
updateMask?: string;
445+
}
446+
436447
type HandlerV1 = (
437448
user: AuthUserRecord,
438449
context: AuthEventContext
@@ -651,18 +662,19 @@ function parseAdditionalUserInfo(decodedJWT: DecodedPayload): AdditionalUserInfo
651662
};
652663
}
653664

654-
/** Helper to generate payload to GCIP from client request.
665+
/**
666+
* Helper to generate a response from the blocking function to the Firebase Auth backend.
655667
* @internal
656668
*/
657-
export function generateRequestPayload(
669+
export function generateResponsePayload(
658670
authResponse?: BeforeCreateResponse | BeforeSignInResponse
659-
): any {
671+
): ResponsePayload {
660672
if (!authResponse) {
661-
return "";
673+
return {};
662674
}
663675

664676
const { recaptchaPassed, ...formattedAuthResponse } = authResponse;
665-
const result = {} as any;
677+
const result = {} as ResponsePayload;
666678
const updateMask = getUpdateMask(formattedAuthResponse);
667679

668680
if (updateMask.length !== 0) {
@@ -853,7 +865,7 @@ export function wrapHandler(eventType: AuthBlockingEventType, handler: HandlerV1
853865
}
854866

855867
validateAuthResponse(eventType, authResponse);
856-
const result = generateRequestPayload(authResponse);
868+
const result = generateResponsePayload(authResponse);
857869

858870
res.status(200);
859871
res.setHeader("Content-Type", "application/json");

0 commit comments

Comments
 (0)