Code Monkey home page Code Monkey logo

ionic3-angularfire-login's Introduction

Integrating Firebase 3 with AngularFire2 into Ionic3

Install

npm install

Use your own Firebase Account

You will need to change the following code in src/app/app.module.ts

export const firebaseConfig = {
  apiKey: "<your-key>",
  authDomain: "<your-project-authdomain>",
  databaseURL: "<your-database-URL>",
  storageBucket: "<your-storage-bucket>"
};

Use your own Facebook Account

Firebase Functions repository

This project make some requests when the user is created to a firebase functions server. You can take a look at the repository here: https://github.com/rodrigoreal/ionic3-angularfire-login-functions

This Application was tested with the following configuration

cli packages:

    @ionic/cli-plugin-ionic-angular : 1.4.0 
    @ionic/cli-utils                : 1.6.0 
    ionic (Ionic CLI)               : 3.6.0 

local packages:

    @ionic/app-scripts : 2.1.3
    Ionic Framework    : ionic-angular 3.6.0

System:

    Node       : v6.9.5
    OS         : macOS Sierra
    Xcode      : Xcode 8.3.3 Build version 8E3004b
    ios-deploy : 1.9.1
    ios-sim    : 5.0.8
    npm        : 3.10.10

ionic3-angularfire-login's People

Contributors

bryant1410 avatar ciekawy avatar rodrigoreal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ionic3-angularfire-login's Issues

cannot install

npm install @types/[email protected] --save-dev --save-exact
Password:
npm ERR! registry error parsing json
npm ERR! registry error parsing json
npm ERR! registry error parsing json
npm ERR! Darwin 16.3.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "@types/[email protected]" "--save-dev" "--save-exact"
npm ERR! node v6.9.2
npm ERR! npm v3.10.9

npm ERR! Unexpected token < in JSON at position 1
npm ERR!
npm ERR!
npm ERR!
npm ERR!
npm ERR!
npm ERR! <title>503 No healthy backends</title>
npm ERR!
npm ERR!
npm ERR!

Error 503 No healthy backends


npm ERR!

No healthy backends


npm ERR!

Guru Mediation:


npm ERR!

Details: cache-lhr6322-LHR 1484232824 3922796935


npm ERR!

npm ERR!

Varnish cache server


npm ERR!
npm ERR!
npm ERR!
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! https://github.com/npm/npm/issues


Your system information:

Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.5
Ionic CLI Version: 2.1.18
Ionic App Lib Version: 2.1.9
Ionic App Scripts Version: 1.0.0
ios-deploy version: 1.9.0
ios-sim version: 5.0.13
OS: macOS Sierra
Node Version: v6.9.2
Xcode version: Xcode 8.2 Build version 8C38

Fetch user profile from facebook

Now that the facebook native code is in place can you add code to fetch user profile, say name, birthday, about, profile pic and display once the user is logged in.

Facebook configuration

Hi, I did facebook steps but I get the following error:

"Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains.."

What I need to put for work in my browser or/and my emulator/device?

License

Could you add a license, please?

\"location.protocol\"

I am getting this error when I deploy my app to the devices. Do you have any clue about it?

All i'am doing is getting the simple simple list fro firebase.

This operation is not supported in the environment this application is running on. "location.protocol" must be http or https and web storage...

Facebook authentication for web browser.

The native code will not execute on desktop browser.
@rodrigoreal please add the below code in auth.js for the same:

import {Platform} from 'ionic-angular';

@Injectable()
export class AuthProvider {
  constructor(private af: AngularFire, platform: Platform) {
    this.platform = platform;
  }
.
.
.
.
.
loginWithFacebook() {
    return Observable.create(observer => {
      if (!this.platform.is('mobileweb')) {
        let fbLoginSuccess = function(userData) {
          console.log("UserInfo: ", userData);
          facebookConnectPlugin.getAccessToken(function(token) {
            let provider = firebase.auth.FacebookAuthProvider.credential(token);
            firebase.auth().signInWithCredential(provider).then((success) => {
              observer.next(success);
            });
          });
        };
        facebookConnectPlugin.login(["public_profile"], fbLoginSuccess,
          function(error) {
            console.error(error);
          }
        );
      } else {
        this.af.auth.login({
          provider: AuthProviders.Facebook,
          method: AuthMethods.Popup
        }).then((authData) => {
          console.info("authData", authData);
          observer.next(authData);
        }).catch((error) => {
          console.info("error", error);
          observer.error(error);
        });
      }
    });
  }

Cancel subscriptions on logout

When I use the logout() function you created in the auth-provider, I get a permission_denied exception, because there is still an open subscription to firebase.

I read the issue #6 but the solution provided there (for an older Version), does not solve the actual problem.

I'm completely new to ionic and angular, so I don't really know how to unsubscribe.

Could you update the logout function so all open subscriptions are unsubscribed?

Thanks!

White Blank screen

I cloned the folder, but it doesn't work (blank screen).
By adding the this line /// <reference path="../node_modules/angularfire2/firebase3.d.ts"/>, i got rid of all 'Cannot find module 'firebase' errors, but then these errors come up in auth.ts: 26th line:
TypeScript error: /home/red/Documents/ionic2/workingSample/app/providers/auth/auth.ts(26,49): Error TS2345: Argument of type '(authData: FirebaseAuthData) => void' is not assignable to parameter of type '(a: FirebaseAuthState) => any'.
Types of parameters 'authData' and 'a' are incompatible.
Type 'FirebaseAuthState' is not assignable to type 'FirebaseAuthData'.
Types of property 'provider' are incompatible.
Type 'AuthProviders' is not assignable to type 'string'.

TypeScript error: /home/red/Documents/ionic2/workingSample/node_modules/angularfire2/providers/auth.d.ts(12,20): Error TS1112: A class member cannot be declared optional.

TypeScript error: /home/red/Documents/ionic2/workingSample/node_modules/angularfire2/utils/firebase_object_observable.d.ts(6,17): Error TS1112: A class member cannot be declared optional.

TypeScript error: node_modules/angularfire2/firebase3.d.ts(414,3): Error TS2300: Duplicate identifier 'export='.

TypeScript error: typings/main/ambient/firebase/index.d.ts(328,2): Error TS2300: Duplicate identifier 'export='.

Any ideas?

Logout Function

Hi Rodrigo,

You created the logout function in auth.ts but you didnt use in app longer.
Could you please add a logout button on home page with its functionality??

Getting compilation errors.

on executing ionic serve -l
I am getting below errors:

TypeScript error: /home/adarshdeep/Downloads/ionic2-angularfire-login-master/app/providers/auth/auth.ts(53,9): Error TS2304: Cannot find name 'facebookConnectPlugin'.
TypeScript error: /home/adarshdeep/Downloads/ionic2-angularfire-login-master/app/providers/auth/auth.ts(54,61): Error TS2339: Property 'credential' does not exist on type 'typeof FacebookAuthProvider'.
TypeScript error: /home/adarshdeep/Downloads/ionic2-angularfire-login-master/app/providers/auth/auth.ts(61,7): Error TS2304: Cannot find name 'facebookConnectPlugin'.
TypeScript error: /home/adarshdeep/Downloads/ionic2-angularfire-login-master/app/providers/auth/auth.ts(85,14): Error TS2339: Property 'plugins' does not exist on type 'Window'.
TypeScript error: /home/adarshdeep/Downloads/ionic2-angularfire-login-master/app/providers/auth/auth.ts(93,61): Error TS2339: Property 'credential' does not exist on type 'typeof GoogleAuthProvider'.
TypeScript error: /home/adarshdeep/Downloads/ionic2-angularfire-login-master/app/providers/auth/auth.ts(113,59): Error TS2339: Property 'credential' does not exist on type 'typeof GoogleAuthProvider'.

Where is the FirebaseAuthData class?

I tried parts of the code but typescript is failing at the class FirebaseAuthData. Where is it imported from?

I have already imported FIREBASE_PROVIDERS in app.ts.

fyi, my ionic info is:

Cordova CLI: 6.0.0
Gulp version:  CLI version 3.8.1
Gulp local:   Local version 3.9.1
Ionic Framework Version: 2.0.0-beta.10
Ionic CLI Version: 2.0.0-beta.32
Ionic App Lib Version: 2.0.0-beta.18
ios-deploy version: Not installed
ios-sim version: 3.0.0
OS: Mac OS X El Capitan
Node Version: v5.6.0
Xcode version: Xcode 7.3.1 Build version 7D1014

Also further down in the code you have:

}).catch((error) => {
        if (error) {
          switch (error.code) {
            case "INVALID_EMAIL":

What is the type of this error? How did it get a 'code' field? Typescript fails to compile this also.

add steps on how you got it working

Could you please add in the README the steps to get it working? i.e. which files you had to edit, which all you had to npm install, what you had to check for after, etc.?

p.s. in any case this is a useful project and I've reposted it.

Livereload Error ?

Getting a live reload error. after signing up or signing in. Please find the image

livereload

Catching exception after logout

I don't know if others are seeing this error. When you do a 'logout/signout', are you seeing an exception? After that the ionic app just hangs for me. I had to add a function to catch the error from the inner subscribe to handle it.

  getUserData() {
    return Observable.create(observer => {
      this.af.auth.subscribe(
        (authData) => {
          if (authData) {
            this.af.database.object("/users/" + authData.uid).subscribe(
              (userData) => {
                console.log(userData);
                observer.next(userData);
              },
              (ex) => { // added to capture exception after login
                console.log('getUserData(): Found exception: ', ex);
                observer.error(ex);
              }
            );
          } else { 
            console.log('getUserData(): authData was nil: '); // this never seems to be called.
            observer.error();
          }
        },

        (err) => {
          console.log('getUserData(): Error: ', err);
        }
      );
    });
  }

Also, why should this be called each time? It's because of the this.auth.getUserData() in app.ts:initializeApp(). We would ideally need it only the first time right? How do we cancel that subscription after the first time? I tried take(1) but that doesn't seem to work.

      this.auth.getUserData().take(1).subscribe(data => { // the take(1) doesn't work
        console.log('Firebase responded with success.');
        this.rootPage = TabsPage;
      }, err => {
        console.log('Firebase responded with error.', err);
        this.rootPage = LoginEmailPage;
      });

Logout issue

Im trying to set logout without any success.
Any help appreciated.

  logoutUser(){
  this.authData.logoutUser()
  .then(authData => {
              this.navCtrl.setRoot( auth-signin);
          });
}

Runtime Error
Cannot read property of logoutUser undefined.

Cannot run on android

Hello,

i'm new to android. When trying your project with ionic run android i get the following gradle error:

ionic2-angularfire-login/platforms/android/src/nl/xservices/plugins/GooglePlus.java:11: error: package com.google.android.gms.auth does not exist

Since i'm new to ionic i'm not sure if i'm suppoused to add the dependency within the build.gradle file or something went wrong during my installation of your project.

Thanks :)

"nonce" variable always "00000"

Sorry in advance if I missed something, but this line always generates "00000".

According to the docs it should be "A cryptographically strong random string that you use to prevent intercepted responses from being reused. The Google Authorization Server round-trips this parameter; you must verify your application receives the same value it sent."

Ionic DeepLinkConfig question

Hey @rodrigoreal,

I'm quite stuck with the deepLinkConfig scenario.
If we use this application as a PWA, it will be great to not redirect the user with this.nav.setRoot on the app.component.

Some auth pages need to have access to the user auth, but they are loaded before firebase get the auth state of the user. I've try the ionViewCanEnter method without success.

Do you have face to the DeepLinkConfig with auth scenario ?

Thank you

npm install failes

$ npm install
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of [email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN @angular/[email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN [email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN [email protected] requires a peer of @angular/[email protected] but none was installed.
npm WARN [email protected] requires a peer of [email protected] but none was installed.
npm WARN [email protected] requires a peer of zone.js@~0.6.26 but none was installed.

Also
$ ionic serve
...
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "watch"
npm ERR! node v7.5.0
npm ERR! npm v4.1.2
npm ERR! code ELIFECYCLE
npm ERR! ionic-hello-world@ watch: ionic-app-scripts watch
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ionic-hello-world@ watch script 'ionic-app-scripts watch'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ionic-hello-world package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ionic-app-scripts watch
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs ionic-hello-world
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls ionic-hello-world
npm ERR! There is likely additional logging output above.

latest node and npm installed on the machine

Sorry buy I'm new to all thins and thank you in advance for your help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.