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

v12.6.0 Cloud Function Authentication Triggers - no longer working #2782

Closed
simeon9696 opened this issue Nov 21, 2024 · 4 comments
Closed

v12.6.0 Cloud Function Authentication Triggers - no longer working #2782

simeon9696 opened this issue Nov 21, 2024 · 4 comments

Comments

@simeon9696
Copy link

simeon9696 commented Nov 21, 2024

[REQUIRED] Step 2: Describe your environment

  • Operating System version: OS Name Microsoft Windows 11 Home Version 10.0.22631 Build 22631
  • Firebase SDK version: _____
  • Firebase Product: cloud functions (auth, database, storage, etc)
  • Node.js version: 20
  • NPM version: 10.8.2

[REQUIRED] Step 3: Describe the problem

The documentation for the auth triggers is no longer valid
https://firebase.google.com/docs/auth/extend-with-functions

src/onUserCreated.ts:8:45 - error TS2339: Property 'user' does not exist on type '(app?: App | undefined) => Auth'.

8 export const onUserCreated = functions.auth.user().onCreate((user:any) => { 

Steps to reproduce:

Using v12.6 of the firebase-functions package the below trigger is invalid:

// The Cloud Functions for Firebase SDK to create Cloud Functions and set up triggers.
import * as functions from 'firebase-functions';
// Start writing functions
// https://firebase.google.com/docs/functions/typescript

export const onUserCreated = functions.auth.user().onCreate((user:any) => {
 //TODO: Create avatar on user create and send verification email
  console.info(new Date())
  console.info(user)
});

I am currently refactoring to use a blocking function - only because the project is new and I can afford to do this


// The Cloud Functions for Firebase SDK to create Cloud Functions and set up triggers.
import {
  beforeUserCreated,
} from "firebase-functions/v2/identity";
// Start writing functions
// https://firebase.google.com/docs/functions/typescript

export const onUserCreated = beforeUserCreated((event:any) => {
  //TODO: Create avatar on user create and send verification email
  console.info(new Date())
  console.info(event)
});

What happened? How can we make the problem occur?
Run firebase init and try to set up a cloud function with an auth trigger as described in the documentation.

Relevant Code:

package.json

{
  "name": "functions",
  "scripts": {
    "lint": "eslint --ext .js,.ts .",
    "build": "tsc",
    "build:watch": "tsc --watch",
    "serve": "npm run build && firebase emulators:start --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "20"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "^12.6.0",
    "firebase-functions": "^6.0.1"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^5.12.0",
    "@typescript-eslint/parser": "^5.12.0",
    "eslint": "^8.9.0",
    "eslint-config-google": "^0.14.0",
    "eslint-plugin-import": "^2.25.4",
    "firebase-functions-test": "^3.1.0",
    "typescript": "^4.9.0"
  },
  "private": true
}

@google-oss-bot
Copy link

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@simeon9696
Copy link
Author

simeon9696 commented Nov 21, 2024

Used //@ts-expect-error and it cleared away - not sure what's the issue there

// The Cloud Functions for Firebase SDK to create Cloud Functions and set up triggers.
import * as functions from 'firebase-functions';
// Start writing functions
// https://firebase.google.com/docs/functions/typescript

//@ts-expect-error
export const onUserCreated = functions.auth.user().onCreate((user:any) => {
 //TODO: Create avatar on user create and send verification email
  console.info(new Date())
  console.info(user)
});

@simeon9696
Copy link
Author

That has just led to this error:

TypeError: Cannot read properties of undefined (reading 'user')

@simeon9696
Copy link
Author

simeon9696 commented Nov 22, 2024

Found a fix here:
firebase/firebase-functions#1622 (comment)

const functions = require('firebase-functions/v1');

or

import functions from 'firebase-functions/v1'

Please update the documentation! That's a breaking change

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

2 participants