Skip to content

Conversation

@kushalpalesha
Copy link

@kushalpalesha kushalpalesha commented Nov 13, 2025

Description

Add authctxt fields so users can access them in their v2 functions.

Code sample

// The Cloud Functions for Firebase SDK to setup triggers and logging.
const {onValueWritten} = require("firebase-functions/v2/database");
const {logger} = require("firebase-functions");

exports.dbtrigger = onValueWritten("/messages/{pushId}/original", (event) => {
  // Log the AuthContext
  logger.log(`Auth type: ${event.authtype}`);
  logger.log(`Auth ID: ${event.authid}`);
``
  // Grab the current value of what was written to the Realtime Database.
  const original = event.data.after.val();
  logger.log("Uppercasing", event.params.pushId, original);
  const uppercase = original.toUpperCase();

  // You must return a Promise when performing asynchronous tasks inside a function.
  return event.data.after.ref.parent.child("uppercase").set(uppercase);
});

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 DatabaseEvent object within Firebase Functions v2 for Realtime Database triggers. By adding authType and authId fields, it empowers developers to build more sophisticated and secure functions that can react differently based on the authentication context of the user or service that initiated a database change. This change improves the expressiveness and control available to function authors without altering existing functionality.

Highlights

  • Enhanced DatabaseEvent Interface: The DatabaseEvent interface has been updated to include optional authType and authId properties, providing authentication context for Realtime Database events.
  • User Access to Auth Context: Developers can now access the type of principal (authType) and its unique identifier (authId) directly within their Firebase Realtime Database functions (e.g., onValueWritten).
  • New Test Coverage: A new test case has been added to database.spec.ts to ensure that the authId and authType are correctly passed into the DatabaseEvent object for onValueWritten triggers.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 465 to 478
it("should pass auth context into the event", async () => {
const raw = {
...RAW_RTDB_EVENT,
authId: "uid",
authType: "unauthenticated",
};

const func = database.onValueWritten("foo/bar", (event) => {
expect(event.authId).to.equal("uid");
expect(event.authType).to.equal("unauthenticated");
});

await func(raw as any);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The new test correctly verifies that the auth context is passed to the onValueWritten handler. However, this change also affects onValueCreated, onValueUpdated, and onValueDeleted as they all use the DatabaseEvent type. It would be beneficial to add similar tests for these other functions to ensure the auth context is passed through correctly for all database trigger types. This would increase confidence in the change across the entire API surface.

@kushalpalesha kushalpalesha requested a review from taeold November 13, 2025 20:37
@kushalpalesha kushalpalesha marked this pull request as draft November 19, 2025 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant