javascriptfirebasefirebase-authenticationgoogle-cloud-functions

firebase-functions has no exported member 'auth'


This piece of code is watching for the user auth event:

export const onUserAuthenticated = auth.user().onCreate(async (userRecord) => {
  const adminFirestore = getFirestore();
  ...

package.json

"firebase-functions": "~6.3.1",

I'm importing the 'auth' like so:

import { auth } from 'firebase-functions';

...and getting the following error:

Module '"firebase-functions"' has no exported member 'auth'.

Any help greatly appreciated.
Thanks.


Solution

  • Looks like there is some change in firebase-functions where there is v1 and v2 folders in their source code, seems by default it refers to the v2 api, unless specified otherwise.

    I found this article on v1 vs v2 which might be helpful:

    1st and 2nd gen version comparison


    For now I found this workaround to use the old method:

    import functions from 'firebase-functions/v1';
    
    functions.auth.user().onCreate(async (userRecord) => {
      console.log('asdf');
    });
    

    for V2, this seems to be something similar to onCreate:

    import functions from 'firebase-functions/v2';
    
    functions.identity.beforeUserCreated(async (userRecord) => {
      console.log('asdf');
    });