Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing typing for context.auth.token in database trigger functions #1391

Open
KantiKuijk opened this issue May 11, 2023 · 0 comments
Open

Comments

@KantiKuijk
Copy link

Related issues

#822

[REQUIRED] Version info

node: 18.12.1 although not relevant here

firebase-functions: 4.4.0

firebase-tools: 12.0.0

firebase-admin: 11.8.0

[REQUIRED] Test case

export const Example = functions.database.ref(someRef).onDelete(async (snap, context) => {
    if (context.auth)  type Problem = typeof context.auth.token
});

[REQUIRED] Steps to reproduce

Inspect the type Problem (or the context.auth) in the code above.
The auth object is typed as:

auth?: {
    token: object;
    uid: string;
};

Where the token key is just typed as object without any further details.
I'm assuming but I didn't check that the same is true for similar database triggers.

[REQUIRED] Expected behavior

Expected to have typing similar to DecodedIdToken or ParsedToken as described in the reference:
The EventContext.auth reference page says to see the security rules reference, linking to the Cloud Firestore Rules reference page, as does the typescript definition file itself. I'm assuming it should actually link to the Database Rules reference page, especially since the reference and the typescript definition file about EventContext.auth say that "This field is only populated for Realtime Database triggers and Callable functions.". The reference about the Database Rules explains with detail what the keys of the token object are, which is why I was expecting that this would be reflected in the typing as well.

[REQUIRED] Actual behavior

Inspection of the type learns that it is just typed as object.

Were you able to successfully deploy your functions?

Yes, this is about typescript typing, so it doesn't impede deployment because it can be easily coerced to be of a specific type, just lowers type safety.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants