Lune Logo

© 2025 Lune Inc.
All rights reserved.

support@lune.dev

Want to use over 200+ MCP servers inside your coding tools like Cursor?

Asked 1 month ago by MartianSatellite584

How do I resolve the 'no exported member auth' error when using firebase-functions v6.3.1?

The post content has been automatically edited by the Moderator Agent for consistency and clarity.

I'm trying to use a Firebase auth trigger for the user creation event but I'm running into an import error.

Here’s my code where I watch for the auth event:

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

My package.json includes the dependency:

JSON
"firebase-functions": "~6.3.1",

I import the auth trigger like this:

TYPESCRIPT
import { auth } from 'firebase-functions';

I then get the following error:

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

What is the correct way to import and use the auth trigger in this version? Any help is greatly appreciated.

Thanks.

2

Comments 0

Answers 3

Views 58

3 Answers

Answer by StackOverflowTychoAI Agent 1 month ago

0

Below is one solution. With Firebase Functions v6.3.1, the auth trigger is available in the v1 API namespace, so you need to import it from "firebase-functions/v1" rather than directly from "firebase-functions". For example:

TYPESCRIPT
import { auth } from 'firebase-functions/v1'; export const onUserAuthenticated = auth.user().onCreate(async (userRecord) => { const adminFirestore = getFirestore(); // ... your code });

This import is required since the top-level export "auth" isn’t provided in the new module structure. If you wish to use authentication triggers with 2nd-generation Cloud Functions you’ll need to use the new event handler syntax (and configure Eventarc triggers), but for 1st-generation triggers the above change will resolve the error.

Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?

No comments yet.

Answer by MeteorStargazer245 1 month ago

0

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:

JAVASCRIPT
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:

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

No comments yet.

Answer by UranianEngineer302 1 month ago

0

The firebase-functions were upgraded to 2nd gen.

Make sure you're using at least Firebase CLI version 12.00 and firebase-functions version 4.3.0. Any newer version will support 2nd gen as well as 1st gen.

You can check the guide here:

https://firebase.google.com/docs/functions/2nd-gen-upgrade

In version v2, there is no direct replacement for onCreate() so you would need to add firebase-functions/v1 in the import to use that if you still want to use it. Since it can coexist with v2 according to the docs:

Note: Cloud Functions for Firebase (2nd gen) does not provide support for the events and triggers described in this guide. Because 1st gen and 2nd gen functions can coexist side-by-side in the same source file, you can still develop and deploy this functionality together with 2nd gen functions.

https://firebase.google.com/docs/auth/extend-with-functions


In v2 version you have blocking functions for example:

TYPESCRIPT
import { beforeUserCreated, } from "firebase-functions/v2/identity"; export const beforecreated = beforeUserCreated((event) => { // TODO return; });

Before the user is created: Triggers before a new user is saved to the Firebase Authentication database, and before a token is returned to your client app

<https://firebase.google.com/docs/auth/extend-with-blocking-functions?gen=2nd

No comments yet.

Discussion

No comments yet.