firebase / firebase-admin-node

Firebase Admin Node.js SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
1.64k stars 372 forks source link

Auth trigger build error after upgrade to 12.2.0 #2637

Closed ottob closed 3 months ago

ottob commented 4 months ago

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

when I bumped firebase-admin from 12.1.0 to 12.2.0 it stopped compiling my auth function trigger. Instead I receive a type error:

error TS2322: Type 'import("/Users/myuser/myproject/packages/common/node_modules/firebase-functions/lib/v1/cloud-functions").CloudFunction<import("/Users/myuser/myproject/packages/common/node_modules/firebase-admin/lib/auth/user-record").UserRecord>' is not assignable to type 'import("/Users/myuser/myproject/packages/common/node_modules/firebase-functions/lib/v1/cloud-functions").CloudFunction<import("/Users/myuser/myproject/node_modules/firebase-admin/lib/auth/user-record").UserRecord>'.
  Type 'import("/Users/myuser/myproject/node_modules/firebase-admin/lib/auth/user-record").UserRecord' is not assignable to type 'import("/Users/myuser/myproject/packages/common/node_modules/firebase-admin/lib/auth/user-record").UserRecord'.
    Types of property 'multiFactor' are incompatible.
      Type 'import("/Users/myuser/myproject/node_modules/firebase-admin/lib/auth/user-record").MultiFactorSettings | undefined' is not assignable to type 'import("/Users/myuser/myproject/packages/common/node_modules/firebase-admin/lib/auth/user-record").MultiFactorSettings | undefined'.
        Type 'import("/Users/myuser/myproject/node_modules/firebase-admin/lib/auth/user-record").MultiFactorSettings' is not assignable to type 'import("/Users/myuser/myproject/packages/common/node_modules/firebase-admin/lib/auth/user-record").MultiFactorSettings'.
          Types of property 'enrolledFactors' are incompatible.
            Type 'import("/Users/myuser/myproject/node_modules/firebase-admin/lib/auth/user-record").MultiFactorInfo[]' is not assignable to type 'import("/Users/myuser/myproject/packages/common/node_modules/firebase-admin/lib/auth/user-record").MultiFactorInfo[]'.
              Type 'import("/Users/myuser/myproject/node_modules/firebase-admin/lib/auth/user-record").MultiFactorInfo' is not assignable to type 'import("/Users/myuser/myproject/packages/common/node_modules/firebase-admin/lib/auth/user-record").MultiFactorInfo'.
                Types have separate declarations of a private property 'initFromServerResponse'.

Steps to reproduce:

Create a v1 auth trigger as described here: https://firebase.google.com/docs/functions/auth-events#trigger_a_function_on_user_creation Build it.

ottob commented 4 months ago

My code:

import { getAuth, UserRecord } from 'firebase-admin/auth'
import { FunctionBuilder, CloudFunction } from 'firebase-functions'

export default (
  functions: FunctionBuilder,
  config: { allowedDomains?: string[] } = {}
): CloudFunction<UserRecord> =>
  functions.auth.user().onCreate(async (user, { eventId }) => {

maybe the UserRecord should be imported from somewhere else now?

lahirumaramba commented 3 months ago

Could you test using the latest Firebase Admin SDK v12.3.0 and see if that resolves your issue?

ottob commented 3 months ago

Sorry, same issue with 12.3.0

ottob commented 3 months ago

Digging into this a bit more I can see that it's 12.1.1 that broke it, not 12.2.0.

I cannot do a proper bisect, but maybe this was caused by https://github.com/firebase/firebase-admin-node/pull/2556

ottob commented 3 months ago

We have a mono repo and I hade bumped the version in once place, but forgotten in another. So then it added the new version to yarn.lock in addition to the old one, so it linked multiple versions.