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

ionic-universal-firebase-login

v0.3.2

Published

Easy to use universal (browser, Android, iOS) authentication via Firebase for Ionic

Downloads

82

Readme

Universal Firebase login for Ionic

Scrutinizer Code Quality Build Status code style: prettier

Do you want to implement native authentication as well as in browser authetication for your Ionic application? This package is for you!

The easiest to use flexible hybrid module for Ionic (Angular) with complete documentation and step-by-step guide. We use Firestore for authentication service and its Firestore for storing information about users.

No more pain with login implementation troubles!

Platforms:

  • Browser
  • Android
  • iOS

See documentation and guides on: https://github.com/cothema/ionic-universal-firebase-login

Video tutorial

Youtube video Ionic Firebase Login Tutorial

Play tutorial on YouTube

Supported providers

Supported login types:

  • Pop up / Native
  • Redirect (not implemented at this time)

What's included?

You can customize almost everything to your own needs (e.g. by extending, overloading or composition).

Configuration

Override or change options property of BaseAuthService

| Option name | Default value | Description | --- | --- | --- | afterSignInPage | "/" | Path where user will be redirected after successful sign in. If false, no redirect will be done. | providers | {} | List of provider configurations. See example configuration. | redirectBack | true | When true, user will be redirected back to requested router path after sign in | signInPage | "/sign-in" | Path where user will be redirected when sign in is required (and after logout). If false, no redirect will be done. | storage | false | You can store user profile data in Firestore ('firestore') or nowhere (false). | storageUserTable | "users" | If you specify storage, than this table name / key will be used. | mapUserToStorageFunc | | You can use custom strategy to map user model to storage. See example configuration. | storageUserFactoryFunc | | You can use custom model object for user in storage. See example configuration. | userFactoryFunc | | You can use custom model object for user. See example configuration.

Example configuration

import { NgModule } from "@angular/core";
import { AngularFireModule } from "@angular/fire";
import { AngularFirestoreModule } from "@angular/fire/firestore";
import { FacebookAuthModule, GoogleAuthModule, UniFirebaseLoginModule } from "ionic-universal-firebase-login";
import { environment } from "../environments/environment";
import { Player } from "./model/player.model";
import * as firebase from "firebase";

export function mapFirebaseUserToStorageFunc(user: firebase.User) {
    return {
        uid: user.uid,
        email: user.email,
        displayName: user.displayName,
        photoURL: user.photoURL,
    };
}

export function userFactoryFunc(): Player {
    return new Player();
}

@NgModule({
    imports: [
        ...
        AngularFireModule.initializeApp(environment.firebase),
        AngularFirestoreModule,
        UniFirebaseLoginModule.forRoot({
            storage: "firestore",
            storageUserTable: "players",
            signInPage: "login",
            userFactoryFunc,
            mapFirebaseUserToStorageFunc
        }),
        GoogleAuthModule,
        FacebookAuthModule,
    ],
    ...
})
export class AppModule {
}

Usage in template:

import { Component, OnInit } from "@angular/core";
import { BaseAuthService } from "ionic-universal-firebase-login";

@Component({
  selector: "app-sample",
  template: `
    Username: {{ auth.user?.displayName }}
    Email: {{ auth.user?.email }}
  `,
})
export class SamplePage {
  constructor(
    public auth: BaseAuthService,
  ) {}
}

Installation

  • Before you start, be sure that you have signed your application. It is required for native authentication on Android and iOS.

Install with npm:

npm install firebase @angular/fire ionic-universal-firebase-login
  • Go to https://firebase.google.com/ → create a new Firebase project (if you don't have it already).
    • Project overview → Create Web app
    • Firebase settings → General tab → Web app project (at the bottom) → Config → copy Firebase SDK snippet (Configuration is the same for all platforms, so you have to do this step only once.)
  • Edit src/environments/environment.ts and paste the config from previous step as in example below:
export const environment = {
    ...
    firebase: {
        apiKey: "XXX",
        authDomain: "XXX.firebaseapp.com",
        databaseURL: "https://XXX.firebaseio.com",
        projectId: "XXX",
        storageBucket: "XXX.appspot.com",
        messagingSenderId: "XXX",
        appId: "XXX",
        measurementId: "G-XXX",
    },
}
  • Edit src/app/app.module.ts and add:
import { NgModule } from '@angular/core'; 
import {AngularFireModule} from '@angular/fire';
import {environment} from '../environments/environment';
import {UniFirebaseLoginModule, GoogleAuthModule, FacebookAuthModule} from 'ionic-universal-firebase-login';

@NgModule({
    ...
    imports: [
        ...
        AngularFireModule.initializeApp(environment.firebase),
        UniFirebaseLoginModule.forRoot(),
        GoogleAuthModule, // if you want to use Google as a provider
        FacebookAuthModule, // if you want to use Facebook as a provider
    ]
})

App for Android platform:

  • Create Android app in Firebase similarly as Web app
  • Android package name have to be same as you have in config.xml (<widget id="..."). If you have some default package id in config.xml, edit it.
  • If you don't have SHA-1 key, see guide for Android:
    • Create your keystore with a key: https://coderwall.com/p/r09hoq/android-generate-release-debug-keystores
    • Get SHA-1 from your keystore: https://developers.google.com/android/guides/client-auth
  • Enter SHA1 key in the first step of Android app creation.
  • Click to Download google-services.json and copy it to your project root
  • Skip last (4th) step, because its for Android Studio project only.

See our guide for each provider:

import { NgModule } from "@angular/core";
import { PreloadAllModules, RouterModule, Routes } from "@angular/router";
import { AuthGuard } from "ionic-universal-firebase-login";

const routes: Routes = [
  {
    path: "",
    loadChildren: () =>
      import("./home.module").then(m => m.HomePageModule),
    canActivate: [AuthGuard],
    canActivateChild: [AuthGuard],
  },
  {
    path: "sign-in",
    loadChildren: () => import("./sign-in/sign-in.module").then(m => m.SignInPageModule),
  },
];

@NgModule({
  imports: [
    RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules }),
  ],
  exports: [RouterModule],
})
export class AppRoutingModule {
}

Example implementations

See example project

Real use cases:

  • https://gitlab.com/cothema/cook-pocket

Changelog

See CHANGELOG.md

Contribution

Feel free to send pull requests or create new issues.

License

MIT license