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

beforeSignin functions doesn't trigger in emulator for demo projects? #6494

Closed
renaudcerrato opened this issue Nov 4, 2023 · 4 comments · Fixed by #6504
Closed

beforeSignin functions doesn't trigger in emulator for demo projects? #6494

renaudcerrato opened this issue Nov 4, 2023 · 4 comments · Fixed by #6504

Comments

@renaudcerrato
Copy link

renaudcerrato commented Nov 4, 2023

I'm trying to get the beforeSignin trigger function to work using the emulator on demo projects (--project demo-xxxx / 12.7.0 / macOS) but that's not triggering while perfectly working in production. I'm able to login and write to the database in the emulator, but no beforeSignin trigger. I've spent the whole day trying, but nothing in the logs.

I double checked that both auth and functions are started and running in the emulator, and correctly set the projectId to demo-test in my client as suggested:

initializeApp({
  projectId: "demo-test",
  apiKey: "useless",
  databaseURL: "https://demo-test.firebaseio.com",
})

const auth = getAuth()
connectAuthEmulator(auth, "http://127.0.0.1:9099")
auth.settings.appVerificationDisabledForTesting = true

I also tried to to set the projectId in the function, which should be useless, but with no luck:

import {beforeUserSignedIn} from "firebase-functions/v2/identity"
import {initializeApp} from "firebase-admin/app"

initializeApp({
 projectId: "demo-test",
})

export const beforesignin = beforeUserSignedIn(async (event) => {
  console.log(`beforesignin: ${JSON.stringify(event.data)}`)
})

Is there anything else I'm not aware of to get it working on demo-projects emulation ?

➜ firebase emulators:start --project demo-test
i  emulators: Starting emulators: auth, functions, database
i  emulators: Detected demo project ID "demo-test", emulated services will use a demo configuration and attempts to access non-emulated services for this project will fail.
i  database: Database Emulator logging to database-debug.log
i  ui: Emulator UI logging to ui-debug.log

✔  functions: Loaded functions definitions from source: beforesignin.
✔  functions[us-central1-beforesignin]: providers/cloud.auth/eventTypes/user.beforeSignIn function initialized (http://127.0.0.1:5001/demo-test/us-central1/beforesignin).

┌─────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! It is now safe to connect your app. │
│ i  View Emulator UI at http://127.0.0.1:4000/               │
└─────────────────────────────────────────────────────────────┘

┌────────────────┬────────────────┬─────────────────────────────────┐
│ Emulator       │ Host:Port      │ View in Emulator UI             │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Authentication │ 127.0.0.1:9099 │ http://127.0.0.1:4000/auth      │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Functions      │ 127.0.0.1:5001 │ http://127.0.0.1:4000/functions │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Database       │ 127.0.0.1:9000 │ http://127.0.0.1:4000/database  │
└────────────────┴────────────────┴─────────────────────────────────┘
  Emulator Hub running at 127.0.0.1:4400
  Other reserved ports: 4500

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.
@aalej
Copy link
Contributor

aalej commented Nov 6, 2023

Hi @renaudcerrato, thanks for the detailed report. I’m currently unable to reproduce the behavior you mentioned. Using the code snippets you provided, I created this repo to try and replicate the issue. Let me know in case I’m missing anything.

I added an authDomain in the initializeApp:

initializeApp({
   projectId: "demo-test",
   apiKey: "useless",
   authDomain: "demo-test.firebaseapp.com",
   databaseURL: "https://demo-test.firebaseio.com",
})

And removed a section in the functions code related to the Admin SDK:

import {beforeUserSignedIn} from "firebase-functions/v2/identity"

export const beforesignin = beforeUserSignedIn(async (event) => {
 console.log(" ------------- beforeUserSignedIn --------------- ");
 console.log(`beforesignin: ${JSON.stringify(event.data)}`)
})

By any chance, if you’re unable to reproduce the issue using the repo, could you provide a Minimal, Complete, and Verifiable Example (MCVE)? This is so that we can replicate the issue on our end.

@aalej aalej added the Needs: Author Feedback Issues awaiting author feedback label Nov 6, 2023
@renaudcerrato
Copy link
Author

Thanks for the repo, it seems the authDomain did the trick!

@renaudcerrato
Copy link
Author

Hey @aalej : just been able to reproduce the issue in your repo by adding a pubsub function to the project. Please look at aalej/issues-6494#1

@renaudcerrato renaudcerrato reopened this Nov 8, 2023
@google-oss-bot google-oss-bot added Needs: Attention and removed Needs: Author Feedback Issues awaiting author feedback labels Nov 8, 2023
@aalej
Copy link
Contributor

aalej commented Nov 9, 2023

Thanks @renaudcerrato for additional information. I was able to reproduce the issue you mentioned after adding the code you provided. I’ll notify our engineering team about this so that they can take a look, and I’ll be marking this as reproducible.

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

Successfully merging a pull request may close this issue.

4 participants