Skip to content

Commit 21d2c10

Browse files
committed
add authcxt params to RawRTDBCloudEvent and use a type for AuthType values
1 parent 2683b7a commit 21d2c10

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

spec/v2/providers/database.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ const RAW_RTDB_EVENT: database.RawRTDBCloudEvent = {
4242
specversion: "1.0",
4343
time: "time",
4444
type: "type",
45+
authid: "uid",
46+
authtype: "unauthenticated",
4547
};
4648

4749
describe("database", () => {
@@ -465,13 +467,11 @@ describe("database", () => {
465467
it("should pass auth context into the event", async () => {
466468
const raw = {
467469
...RAW_RTDB_EVENT,
468-
authId: "uid",
469-
authType: "unauthenticated",
470470
};
471471

472472
const func = database.onValueWritten("foo/bar", (event) => {
473-
expect(event.authId).to.equal("uid");
474-
expect(event.authType).to.equal("unauthenticated");
473+
expect(event.authid).to.equal("uid");
474+
expect(event.authtype).to.equal("unauthenticated");
475475
});
476476

477477
await func(raw);

src/v2/providers/database.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,19 @@ export interface RawRTDBCloudEvent extends CloudEvent<RawRTDBCloudEventData> {
6363
instance: string;
6464
ref: string;
6565
location: string;
66+
authtype: AuthType;
67+
authid?: string;
6668
}
6769

70+
/**
71+
* AuthType defines the possible values for the authType field in a Realtime Database event.
72+
* - app_user: an end user of an application..
73+
* - admin: an admin user of an application. In the context of impersonate endpoints used by the admin SDK, the impersonator.
74+
* - unauthenticated: no credentials were used to authenticate the change that triggered the occurrence.
75+
* - unknown: a general type to capture all other principals not captured in the other auth types.
76+
*/
77+
export type AuthType = "app_user" | "admin" | "unauthenticated" | "unknown";
78+
6879
/** A CloudEvent that contains a DataSnapshot or a Change<DataSnapshot> */
6980
export interface DatabaseEvent<T, Params = Record<string, string>> extends CloudEvent<T> {
7081
/** The domain of the database instance */
@@ -83,11 +94,11 @@ export interface DatabaseEvent<T, Params = Record<string, string>> extends Cloud
8394
/**
8495
* The type of principal that triggered the event.
8596
*/
86-
authType?: "app_user" | "admin" | "unauthenticated";
97+
authtype: AuthType
8798
/**
8899
* The unique identifier of the principal.
89100
*/
90-
authId?: string;
101+
authid?: string;
91102
}
92103

93104
/** ReferenceOptions extend EventHandlerOptions with provided ref and optional instance */
@@ -392,6 +403,8 @@ function makeDatabaseEvent<Params>(
392403
firebaseDatabaseHost: event.firebasedatabasehost,
393404
data: snapshot,
394405
params,
406+
authtype: event.authtype,
407+
authid: event.authid
395408
};
396409
delete (databaseEvent as any).firebasedatabasehost;
397410
return databaseEvent;

0 commit comments

Comments
 (0)