Skip to content

Writing directly after auth.logout() fails [gets queued as the wrong user] #737

@Nostrus

Description

@Nostrus

Environment

  • Operating System version: MacOS High Sierra, 10.13.4
  • Firebase SDK version: 4.13.1
  • Firebase Product: Firestore
  • Angularfire2 5.0.0-rc.6.0

Problem

I have a working app and started switching from realtime database to firestore.
I'm trying the simplest operations, but 90% of the time I don't see my changes in the database, in the rest of the cases the data is properly created, without me changing anything in the codebase. I tried stack tracing with breakpoints, but even when data is not created in the DB, I can see that the new document's path and id is correctly set in local variables.
I see no console errors, so not sure how to debug this further. Tried reverting Firebase to 4.12.1, but same issue happens.

Steps to reproduce:

Relevant Code:

const userData = this.signupForm.value;

this.authProvider.auth
    .createUserWithEmailAndPassword(userData.email, userData.password)
    .then(response => {

        delete userData.password;
        const uid = response.uid;

        this.authService.logout();

        const museumData = {
            name: userData.museumName,
            isActive: false,
            country: 'hu'
        };

        this.museumService.create(museumData)
            .then(docRef => {

                const museumKey = docRef.id;

                userData.museumKey = museumKey;
                userData.role = 'admin';

                const userKey = this.userService.create(uid, userData)
                    .then(() => {

                        this.isSignupSuccessful = true;
                    });

                this.museumService.addUser(museumKey, uid);

            });

    })

this.museumService.create(museumData) doesn't return its promise. You can see the related service method below.

    constructor (
        private db: AngularFirestore
    ) {
        db.firestore.settings({ timestampsInSnapshots: true });
        this.collection = db.collection<Museum>('museums');
    }

    create(data) {
        return this.collection.add(data);
    }

Any tips to debug or feedback is appreciated.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions