firebase / firebase-tools

The Firebase Command Line Tools
MIT License
4.02k stars 936 forks source link

Functions v2 authType is 'unknown' when using emulator #7450

Open Bindslev opened 3 months ago

Bindslev commented 3 months ago

Related issues

[REQUIRED] Version info

node:

v18.8.0

firebase-functions: firebase function: v2

firebase-tools:

firebase version: 13.12.0

firebase-admin:

[REQUIRED] Test case

  1. Sign up to firebase auth / firestore / functions
  2. Create a login page
  3. Create a function that is triggered on a firestore collection write/update/delete
  4. Use "onDocumentUpdatedWithAuthContext" or any of the other methods with the AuthContext
  5. Notice that event.authType is unknown when developing locally using the firebase emulator after the use is logged in and authenticated

[REQUIRED] Steps to reproduce

I haven't found any documentation about this not working in the emulator, so I suppose it happens for everybody?

[REQUIRED] Expected behavior

I was expecting for the authType to not be unknown, and be able to retrieve the authenticated users ID using event.authId

[REQUIRED] Actual behavior

I get this:

authType: 'unknown', authId: 'fake-auth-id@gmail.com'

Were you able to successfully deploy your functions?

Yes

Bindslev commented 3 months ago

To anyone stumbling upon this issue, authType and authId actually works using emulators. Remember to use emulators for all firebase services for them to connect. I did it like this:

await FirebaseAuth.instance.useAuthEmulator('192.168.0.153', 9099);
FirebaseFirestore.instance.useFirestoreEmulator('192.168.0.153', 8080);
await FirebaseStorage.instance.useStorageEmulator('192.168.0.153', 9199);
FirebaseFunctions.instance.useFunctionsEmulator('192.168.0.153', 5001);
Bindslev commented 3 months ago

Seems like it wasn't working anyway. I thought I authorized using the emulator but even after adding these lines of code it still somehow authorized without emulator and now after getting the emulator to work with all of these firebase products, the auth doesn't produce the userId I was expecting

aendel commented 3 months ago

+1

JU-2094 commented 2 months ago

This is WAI (the change was adding the types & payload template but not the dependency getting the values ). I'd change the type to FR.

Notes for impl: As an initial option , the emulator context has the jwt token - we can check if it has the information.

google-oss-bot commented 2 months ago

Hey @Bindslev. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

blikblum commented 2 months ago

@JU-2094 @harshyyy21 what kind of feedback do you need?

Just tested with latest firebase-tools v13.15.3 and is always returning :"authType": "unknown" | "authId": "fake-auth-id@gmail.com"

This is limiting us to use functionality since we can not test locally

IIlllII commented 2 months ago

We have the same issue. Makes it very hard to test some features locally.

meteorainer commented 1 month ago

Same issue here. I can log in and sign up from within my app locally, but can't test responsive code with auth context because const { authType, authId } = event; always returns authType: unknown, authId: fake-auth-id@gmail.com

peterlauri commented 1 month ago

Same issue here. I can log in and sign up from within my app locally, but can't test responsive code with auth context because const { authType, authId } = event; always returns authType: unknown, authId: fake-auth-id@gmail.com

Thumbs up on the issue to get traction. Same for @IIlllII and @aendel

google-oss-bot commented 1 month ago

Hey @Bindslev. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

IIlllII commented 1 month ago

Hey @Bindslev. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

oss-bot aka spam-bot ☝️☝️☝️☝️

meteorainer commented 1 month ago

Posting for recent activity. +1 for attention

robbymarston commented 1 month ago

+1 also experiencing.

meteorainer commented 4 days ago

Updating to respond to the type being changed. This is not a feature request. The expectation of getting actual FirestoreAuthEvent info from the emulator seems reasonable.