add authcontxt params to the DatabaseEvent object#1770
add authcontxt params to the DatabaseEvent object#1770kushalpalesha merged 13 commits intomasterfrom
Conversation
Summary of ChangesHello @kushalpalesha, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces significant enhancements to the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds authId and authType to the DatabaseEvent interface, allowing developers to access user authentication information in Realtime Database triggers. The changes are correct and include an initial test for onValueWritten. My feedback focuses on improving test coverage and robustness to ensure high quality for this new feature.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds authentication context fields (authType and authId) to the DatabaseEvent object for v2 database functions, allowing developers to access this information in their function triggers. The changes are well-implemented, including updates to the necessary interfaces, the addition of a new AuthType type, and corresponding tests to validate the new functionality. My feedback focuses on improving the readability and type-safety of the event transformation logic by refactoring to use modern JavaScript/TypeScript features like object destructuring, which avoids type casting and property deletion.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds authentication context (authId and authType) to Realtime Database events in v2 functions. The changes are functionally correct and include corresponding tests. My feedback focuses on improving the implementation's clarity and maintainability by refactoring the event creation logic to be more idiomatic and type-safe. I've also pointed out some test code duplication that could be refactored for better maintainability.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds authId and authType to the DatabaseEvent for v2 database triggers, along with corresponding tests. The changes are logical and the test refactoring to reduce duplication is a good improvement. I've provided a few suggestions to enhance code clarity and type safety, including one for better typing in the new tests and a recommendation to refactor an object creation pattern to be more robust.
| ...RAW_RTDB_EVENT, | ||
| }; | ||
|
|
||
| const func = (handler as any)("foo/bar", (event: any) => { |
There was a problem hiding this comment.
src/v2/providers/database.ts
Outdated
| authType: event.authtype, | ||
| authId: event.authid, | ||
| } as any; | ||
| delete (databaseEvent as any).firebasedatabasehost; | ||
| delete (databaseEvent as any).authtype; | ||
| delete (databaseEvent as any).authid; |
There was a problem hiding this comment.
This pattern of spreading the raw event, casting to any, and then deleting properties can be brittle and reduces type safety. It would be cleaner and more type-safe to use object destructuring to construct the event object. This would involve picking only the necessary properties from the raw event and renaming them as needed, avoiding the need for as any and delete.
For example:
const {
firebasedatabasehost,
authtype,
authid,
data, // to be replaced
...rest
} = event;
return {
...rest,
firebaseDatabaseHost: firebasedatabasehost,
authType: authtype,
authId: authid,
data: snapshot,
params,
};While this might be a larger refactoring that cannot be applied as a simple suggestion due to file boundaries, it's worth considering for improving code quality and maintainability.
src/v2/providers/database.ts
Outdated
| authType: event.authtype, | ||
| authId: event.authid, | ||
| } as any; | ||
| delete (databaseEvent as any).firebasedatabasehost; | ||
| delete (databaseEvent as any).authtype; | ||
| delete (databaseEvent as any).authid; |
There was a problem hiding this comment.
Similar to the other function, this pattern of using ...event, as any, and delete could be improved. Using object destructuring would lead to cleaner, more type-safe code.
For example:
const {
firebasedatabasehost,
authtype,
authid,
data, // to be replaced
...rest
} = event;
return {
...rest,
firebaseDatabaseHost: firebasedatabasehost,
authType: authtype,
authId: authid,
data: { before, after },
params,
};
shettyvarun268
left a comment
There was a problem hiding this comment.
Put in a couple of comments at like 406 and 436 which I think might break stuff(unless I am missing something).
src/v2/providers/database.ts
Outdated
| data: snapshot, | ||
| params, | ||
| }; | ||
| authType: event.authtype, |
There was a problem hiding this comment.
Since authtype might be undefined on legacy events (or older versions), but DatabaseEvent.authType is typed as a required field, should we provide a default fallback here to ensure runtime safety? Something like authType: event.authtype ?? "unknown" .
src/v2/providers/database.ts
Outdated
| }, | ||
| params, | ||
| }; | ||
| authType: event.authtype, |
There was a problem hiding this comment.
Same here. Please correct me if I'm missing something.
Description
Add authctxt fields so users can access them in their v2 functions.
Code sample