Skip to content

this.auth.getUser() always return null #1

@vaimdev

Description

@vaimdev

I am trying to use the code as a base for a similar app, however, I encounter an issue that when I use the AuthService from another Service class,

this.auth.getUser always return null

ClassRoomService class

  async create(title, text) {
    console.log(title, text);
    const user = await this.auth.getUser();

    if (user) {
      console.log(user);
      console.log(user.id);
    }
    else {
      console.log("user is null")
    }
}

I wonder what is wrong with the code, would you be kind to give me some advice ?

Forgot to mention, I add a new function for anonymousLogin in AuthService

  anonymousLogin() {

    return this.afAuth.auth.signInAnonymously()
          .then(() => console.log("successful login"))
          .catch(error => console.log(error));
  }

In component script

		this.authService.anonymousLogin().then(() => {
			 console.log("in anonymousLogin");
			this.classRoomService.create(this.act_title, this.act_text);  --> the "async create function"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions