Firestore Cloud emulator not running properly

Asked

Viewed 46 times

0

I am testing a post request for login in the firebase database using the cloud firestore emulator with the command firebase serves in the terminal and the expected response in the 'Postman' would be a 'token' for user authentication in some requests that require validation, the bug that occurred to me today is that the emulator simply does not access the database anymore even though everything seems to be the same.

When I use the command

**firebase serve**

My application opens the local API path http://localhost:5000/application name/us-east1/api/login

When I enter the following request:

{
   "login": "[email protected]", 
   "password": "123456"
}

The return on the postmam is code 500 Error: Your API key is invalid, Please check you have copied it correctly.

My terminal returns me the following message: The Cloud Firestore Mulator is not running, so calls to Firestore will affect Production.

In the code below is my request with its respective logic.

const login = (_req: any, _res: any) => {
    const user: LoginUser = {
        email: _req.body.email,
        password: _req.body.password
    }

    const isValid: IsValid = validateLoginData(user)

    if(!isValid.valid) return _res.status(400).json(isValid.errors)

    firebase
        .auth()
        .signInWithEmailAndPassword(user.email, user.password)
        .then((data: any) => {
            return data.user.getIdToken()
        })
        .then((token) => {
            return _res.json({ token })
        })
        .catch((err) => {
        console.error(err)            
            return _res
                .status(403)
                .json({ general: 'Wrong credentials, please try again' })
        })
}

This request uses firebase.auth.signInWithEmailAndPassword that returns a file from firebase.user.getIdToken that will return me a JSON with Token that allows me to make requests that need to be authenticated.

When investigating the problem in documentation I arrived at the following solution in Stack Overflow in English:

https://stackoverflow.com/questions/57125151/firestore-local-http-with-real-db-the-cloud-firestore-emulator-is-not-running-s

And I implemented it using the command in windows: set GOOGLE_APPLICATION_CREDENTIALS="C: Project project project-name functions serviceaccountkey.json"

after that I changed the firebase startup code to:

admin.initializeApp({
   credential: admin.credential.applicationDefault()
 });

After that even starting the firebase with firebase serves or firebase emulators:start my server still not sending reply to my request.

This request previously worked and now no longer works and even using firebase deploy the api also does not respond to requests made directly to the server.

I’m trying to find the bug that might be causing this mistake but I don’t know where else to look. If anyone has ever been through this same mistake I would like to receive feedback.

1 answer

0

You installed the angular/fire?

https://github.com/angular/angularfire

The library itself is in charge of adding the token, it follows the code I use:

export class AuthenticationService {

  constructor(
    private angularFireAuth: AngularFireAuth,
  ) { }

  public login(eMail: string, password: string): Promise<firebase.auth.UserCredential> {
    return this.angularFireAuth
    .auth
    .signInWithEmailAndPassword(eMail, password);
  }

  public logout(): void {
    this.angularFireAuth
      .auth
      .signOut();   
    this.router.navigate(['/']);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.