Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Support loading Firebase Functions packaged as an ES module. (#3485)
- Fixes Cloud Storage emulator missing classes (#3541)
- Fixes Cloud Storage emulator missing classes. (#3541)
- Add missing properties to Authentication functions `context` in the Functions emulator. (#3536)
16 changes: 15 additions & 1 deletion src/emulator/auth/cloudFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import * as uuid from "uuid";

import { EventContext } from "firebase-functions";
import { Client } from "../../apiv2";

import { EmulatorInfo, Emulators } from "../types";
Expand All @@ -7,6 +10,10 @@ import { UserInfo } from "./state";

type AuthCloudFunctionAction = "create" | "delete";

type CreateEvent = EventContext & {
data: UserInfoPayload;
};

export class AuthCloudFunction {
private logger = EmulatorLogger.forEmulator(Emulators.AUTH);
private functionsEmulatorInfo?: EmulatorInfo;
Expand Down Expand Up @@ -54,9 +61,16 @@ export class AuthCloudFunction {
private createEventRequestBody(
action: AuthCloudFunctionAction,
userInfoPayload: UserInfoPayload
): { eventType: string; data: UserInfoPayload } {
): CreateEvent {
return {
eventId: uuid.v4(),
eventType: `providers/firebase.auth/eventTypes/user.${action}`,
resource: {
name: `projects/${this.projectId}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall this include the user id? I'm not sure what the production behavior actually is though

Copy link
Contributor Author

@samtstern samtstern Jul 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just following the docs here, but I will deploy a function quickly to confirm:
https://firebase.google.com/docs/reference/functions/cloud_functions_.eventcontext#resource

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the description with a production payload.

service: "firebaseauth.googleapis.com",
},
params: {},
timestamp: new Date().toISOString(),
data: userInfoPayload,
};
}
Expand Down
9 changes: 8 additions & 1 deletion src/test/emulators/cloudFunctions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ describe("cloudFunctions", () => {
it("should make a request to the functions emulator", async () => {
nock("http://1.1.1.1:4")
.post("/functions/projects/project-foo/trigger_multicast", {
eventType: `providers/firebase.auth/eventTypes/user.create`,
eventId: /.*/,
eventType: "providers/firebase.auth/eventTypes/user.create",
resource: {
name: "projects/project-foo",
service: "firebaseauth.googleapis.com",
},
params: {},
timestamp: /.*/,
data: { uid: "foobar", metadata: {}, customClaims: {} },
})
.reply(200, {});
Expand Down