angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Not getting Authentication Data after upgrading from RC5 to Final.

Open thehashrocket opened this issue 10 years ago • 6 comments

So, I, too, upgraded to Angular2 Final. I did the migration project steps to move everything over. I'm getting zero errors, it authenticates. However, the problem happens after authentication. When it redirects back to the page, it's not getting that delicious authentication data. It acts like I'm not logged in. This is happening locally, and on firebase hosting. I double checked that I'm not blocking cookies. I stripped down the authentication options to just facebook. It just doesn't work. It was ok prior to going to final. The last version I was on was RC5.

I'm using Typescript 2.0.2.

My app.module looks like this:

import {BrowserModule} from '@angular/platform-browser';
import {NgModule, ApplicationRef} from '@angular/core';
import {CommonModule} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {AppComponent} from './app.component';
import {CollapseDirective, DropdownDirective, DropdownToggleDirective, DropdownMenuDirective} from 'ng2-bootstrap';
import {
    FIREBASE_PROVIDERS,
    defaultFirebase,
    AngularFire,
    AuthMethods,
    AuthProviders,
    firebaseAuthConfig, AngularFireModule
} from 'angularfire2';
import {RoomlyNavbarComponent} from './shared/roomly-navbar/roomly-navbar.component';
import {RoomlyRoomsComponent} from './roomly-rooms/roomly-rooms.component';
import {RoomlyHomeComponent} from './roomly-home/roomly-home.component';
import {
    routing,
    appRoutingProviders
} from './app.routes';
import {RoomlyRoomComponent} from './roomly-room/roomly-room.component';
import {RoomlyPhotoUploaderComponent} from './roomly-photo-uploader/roomly-photo-uploader.component';
import {RoomlyItemComponent} from './roomly-item/roomly-item.component';
import {RoomlyBuildingComponent} from './roomly-building/roomly-building.component';
import {RoomlyBuildingsComponent} from './roomly-buildings/roomly-buildings.component';
import {BuildingFormComponent} from './building-form/building-form.component';

const myFirebaseConfig = {
    apiKey: "REMOVED",
    authDomain: "REMOVED",
    databaseURL: "REMOVED",
    storageBucket: "REMOVED",
};

const myFirebaseAuthConfig = {
    provider: AuthProviders.Facebook,
    method: AuthMethods.Redirect
};

@NgModule({
    declarations: [
        AppComponent,
        CollapseDirective,
        DropdownDirective,
        DropdownToggleDirective,
        DropdownMenuDirective,
        RoomlyNavbarComponent,
        RoomlyRoomsComponent,
        RoomlyRoomComponent,
        RoomlyHomeComponent,
        RoomlyPhotoUploaderComponent,
        RoomlyItemComponent,
        RoomlyBuildingComponent,
        RoomlyBuildingsComponent,
        BuildingFormComponent,
    ],
    imports: [
        BrowserModule,
        CommonModule,
        FormsModule,
        routing,
        AngularFireModule.initializeApp(myFirebaseConfig, myFirebaseAuthConfig)
    ],
    providers: [appRoutingProviders],
    entryComponents: [AppComponent],
    bootstrap: [
        AppComponent,
        RoomlyNavbarComponent
        ]
})
export class AppModule {

}

My app.component looks like this. I'm using routes, so it's pretty bare. It just loads a page that contains the router-outlet and the navbar:

import { Component } from '@angular/core';
import * as firebase from 'firebase';
import { AngularFire, FirebaseListObservable } from 'angularfire2';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.css']
})
export class AppComponent {
  constructor(public af: AngularFire) {
  }
}

Finally, the home page where the actual logging in takes places looks like this:

import {Component, OnInit} from '@angular/core';
import {AngularFire, AuthProviders, AuthMethods} from 'angularfire2';
import {AuthUser} from '../shared/AuthUser';

@Component({
    selector: 'app-roomly-home',
    templateUrl: 'roomly-home.component.html',
    styleUrls: ['roomly-home.component.css']
})
export class RoomlyHomeComponent implements OnInit {

    ngOnInit() {
    }

    user = {};
    authUser: AuthUser = new AuthUser('', '');
    loggedin: boolean;

    constructor(public af: AngularFire) {
        this.af.auth.subscribe(auth => console.log('hello ', auth));
        this.af.auth.subscribe(user => {
            if (user) {
                // user logged in
                this.user = user;
                this.loggedin = true;
            }
            else {
                // user not logged in
                this.user = {};
                this.loggedin = false;
            }
        });
    }

    login() {
        this.af.auth.login();
    }

    loginFacebook() {
        this.af.auth.login({
            provider: AuthProviders.Facebook,
            method: AuthMethods.Popup
        });
    }

    loginGoogle() {
        this.af.auth.login({
            provider: AuthProviders.Google,
            method: AuthMethods.Popup
        });
    }

    loginTwitter() {
        this.af.auth.login({
            provider: AuthProviders.Twitter,
            method: AuthMethods.Popup
        });
    }

    logout() {
        this.af.auth.logout();
    }


}

I'm not sure what changed between RC5 and Final to cause it to fail. If it helps, here's my package.json file:

{
  "name": "Roomly Home Inventory",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "2.0.0",
    "@angular/compiler": "2.0.0",
    "@angular/core": "2.0.0",
    "@angular/forms": "2.0.0",
    "@angular/http": "2.0.0",
    "@angular/platform-browser": "2.0.0",
    "@angular/platform-browser-dynamic": "2.0.0",
    "@angular/router": "3.0.0",
    "angularfire2": "^2.0.0-beta.4",
    "core-js": "^2.4.1",
    "firebase": "^3.4.0",
    "ng2-bootstrap": "^1.1.4",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "@types/jasmine": "^2.2.30",
    "angular-cli": "1.0.0-beta.14",
    "codelyzer": "~0.0.26",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "4.0.5",
    "ts-node": "1.2.1",
    "tslint": "3.13.0",
    "typescript": "2.0.2"
  }
}

Has anyone else run across this?

thehashrocket avatar Sep 16 '16 13:09 thehashrocket

Have you tried with angularfire2 beta.5-preview? I was getting similar yesterday with beta.4, seems OK with beta 5 to me...

mikeybyker avatar Sep 16 '16 13:09 mikeybyker

@mikeybyker ho'd you get it go to that version? I tried npm install --save @angularfire2@latest and it only did beta.4

thehashrocket avatar Sep 16 '16 13:09 thehashrocket

ok, so I manually typed beta.5 manually, like an animal, but still no go. :(

thehashrocket avatar Sep 16 '16 13:09 thehashrocket

With: npm install [email protected]

mikeybyker avatar Sep 16 '16 13:09 mikeybyker

Crossed post :-) So it didn't work? Hmm, all is OK with auth here - I'm using google as the provider and rather than Redirects I'm on AuthMethods.Popup - perhaps the difference?

mikeybyker avatar Sep 16 '16 14:09 mikeybyker

GOT IT!

I followed up by heeding the advice of the warning and installed @types/[email protected] and it works. WOOT! Thank you! :)

thehashrocket avatar Sep 16 '16 14:09 thehashrocket