firebase / firebase-admin-go

Firebase Admin Go SDK
Apache License 2.0
1.14k stars 247 forks source link

BUG: Can't connect to Auth Emulator with Go despite setting env variable #532

Closed kyleshepherd closed 1 year ago

kyleshepherd commented 1 year ago

I am trying to use the Firebase emulators in an API I'm building with Go. I've got the Firestore emulator working fine, but the Auth one is being ignored and instead my actual Firebase project's Authentication is being used.

// .envrc

export GOOGLE_APPLICATION_CREDENTIALS=./record-dev-sa.json
export FIRESTORE_EMULATOR_HOST=localhost:8080
export FIREBASE_AUTH_EMULATOR_HOST=localhost:9099
export GCLOUD_PROJECT=record-dev-8198f

// serve.go
app, err := firebase.NewApp(ctx, nil)
if err != nil {
  return err
}

client, err := app.Auth(ctx)
if err != nil {
  return nil, err
}

I've tried setting the GCLOUD_PROJECT env variable as well but it isn't changing the results. I expected this to behave the same as the Firestore Emulator, where it automatically picks up the env variable without any other changes required

mpwalkerdine commented 5 months ago

I've just had the exact same problem... Imagine my delight at finding this issue, and my disappointment that it was closed with no comment. It's OK though, I figured it out.

Still here? Oh, right, sure: There's some out of date gcloud documentation floating about which instructs you to: go get firebase.google.com/go

But what you really want (at time of writing) is: go get firebase.google.com/go/v4

You're welcome.