npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

firehouse

v0.0.20

Published

## Documents

Downloads

3

Readme

Firehouse

Documents

Requirements

  • firebase and @angular/fire must be installed on the project.
  • chance is optional for testing.
  • AngularFire must be initialized on app module like below
@NgModule({
  imports: [
    ...
    AngularFireModule.initializeApp( /* ... firebase config ... */ ),
    AngularFirestoreModule,
    AngularFireAuthModule
    ...
  ],
  ...
})
export class AppModule {}

Sample code

How to get user data

  • You need to get data when the user auth changed.
this.firehouse.auth.onAuthStateChanged(async () => {
  if (this.firehouse.isLoggedIn) {
    const re = await this.firehouse.userGet(this.firehouse.currentUser.uid).then(user => {
      this.form = user;
      this.a.render();
    }).catch(e => e);
    if (this.firehouse.isError(re)) {
      this.a.error(re);
    }
  }
});

User registration

  • When you put user registration form and profile update form in one componet(tempalte),
    • use the following code.
load = false;
subscriber;
form = {};
constructor(
  public a: AppService,
  public firehouse: FirehouseService
) {
  this.subscriber = this.firehouse.auth.onAuthStateChanged(async user => {
    if (this.load) {
      return;
    }
    this.load = true;
    if (user) {
      const re = await this.firehouse.userGet(this.firehouse.currentUser.uid).catch(e => e);
      if (this.firehouse.isError(re)) {
        this.a.error(re);
        return;
      }
      this.form = re;
      this.a.render();
    }
  });
}

ngOnDestroy() {
  if (this.subscriber) {
    this.subscriber(); // unsubscribe
    this.subscriber = null;
  }
}
 async onSubmit() {
    if (this.firehouse.isLoggedIn) {
      const re = await this.firehouse.userUpdate(this.form).catch(e => e);
      if (this.firehouse.isError(re)) {
        this.a.error(re);
      } else {
        // profile upload success
      }

    } else {
      const re = await this.firehouse.userRegister(this.form).catch(e => e);
      if (re.code === void 0) {
        // do something after registration
      } else {
        this.a.error(re);
      }
    }
    return false;
  }

Common pitfalls

  • The following shows a common pitfall you may be trapped.
    • It first creates account with email/password
    • And inside the firehouse.userRegister, it will create user profile documentation under /users collection.
    • Before it creates a doc undre /users, it will try to read it because it listens the user staet change.
    • So, it reads the user data before it exists.
    • That's why you get premission-denied error.
this.f.fireAuth.auth.onAuthStateChanged( async () => {
  console.log(`auth.onAuthStateChanged() happens right after email/password registration before updated /users collection`);
  if ( this.f.isLoggedIn ) {
    console.log(`Since the user has logged in already
                  and it is trying to get user data from /users collection which is not exists yet.`);
    const re = await this.f.userGet( this.f.currentUser.uid ).then( user => {
      this.form = user;
      this.a.render();
      }).catch( e => e);
      if ( this.f.isError(re) ) {
        console.log(`That's why you get permission-denied error here!`);
        this.a.error(re);
      }
  }

/**
 * going to register
 */
  const re = await this.f.userRegister( this.form ).catch(e => e);
if ( re.code === void 0 ) {
  // this.a.alert('Register success');
  // this.a.openHome();
} else {
  this.a.error( re );
}
});