-
Notifications
You must be signed in to change notification settings - Fork 900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: app.auth is not a function #1696
Comments
I'm not able to reproduce the issue, though I didn't use @angluar/fire. |
Dear @Feiyang1 , I have updated the main issue with latest details. Along with that below is the code for my Auth Service by which I am importing firebase. This only got broke when the firebase got updated. My working code from master is available at - https://angular6-201.firebaseapp.com/dashboard `import { User } from './../models/user.model'; @Injectable({ constructor(public afAuth: AngularFireAuth) { } observable$ = Observable.create((observer) => { getAuthUser(): Observable { login(): User | void { logout(): void { getUserDetails(): User | void { async getUserToken(): Promise { isAuthenticated(): boolean { resetUserData(): User | void { |
I created a fresh angularfire project with auth using the steps here: https://github.com/angular/angularfire2/blob/master/docs/auth/getting-started.md It seemed to work, I wasn't able to reproduce the error. I went to the url you provided above, which seems to be your deployed project, and it seems to be working. Did you get this working since you last posted, or is that an older version that's deployed? If it's still not working, can you share the code for initializing your app, such as:
Thanks! |
Dear @hsubox76 ,
Thank You |
Unfortunately, I still can't seem to reproduce it. Can you create a bare-bones repo that reproduces this error? I've made a minimal AngularFire project repo here (that does not show the error): https://github.com/hsubox76/angularfire-test It is a fully functional repo except for your Firebase config (API key, etc.) needing to be pasted into Can you either clone that repo and cause it to fail, or strip down your own code (remove anything proprietary or private) to create a similar minimal repo that fails? This would be the best way for us to narrow down what's wrong. And if you're able to make that, then can you give us a link to the source code (Github repo)? The link above (https://angular6-201.firebaseapp.com/dashboard) seems to be to a deployment, not code. |
I've fixed with this comment |
import firebase from "firebase/app";
import "firebase/auth";
import "firebase/firestore";
import firebase from "@firebase/app";
import "@firebase/auth";
import "@firebase/firestore"; This actually didn't fix my issue. I'm still having the same issue as you where |
Dear @curtgrimes, Thank You for your effort to look into my issue. Unfortunately it is still unresolved. #1 for "import firebase from "firebase/app";" I am getting following error- #2 If I try "import firebase from "@firebase/auth";" I am getting the following error - "Module '"../../../../../../PROJECTS/Angular6_201/any-time-library/node_modules/@firebase/auth"' has no exported member 'firebase'.ts(2305)" Also whenever I am installing firebase or running "npm update" using "npm i firebase" (as per npmjs) after deleting folder in node_modules, it is loading tons of .c and .cc files and trying to build which it is eventually failing. I have node gyp, python 2.7 and MS VS Build Tool 2017 installed. Maybe total noob in this, but this is not something proper. never happened earlier in this way, i keep updating my app because that is one of the requirement from app owner. I seriously need help because my app is now messed up. Thank You Regards |
This actually didn't fix my issue. I'm still having the same issue as you where |
Dear @curtgrimes, I was using v5.11.1 and problem started from that time. Thank You |
Updated to Firebase SDK version: v6.0.2 but the issue is still there. |
It looks like this issue is caused by the |
Dear @curtgrimes , Tried by removing that also. Not working :( Thank You |
I'm afraid it's too difficult to pinpoint the exact problem without getting a look at the rest of your setup. Can you please provide a minimal repro as described in the above comment? Once you've created it, you can upload it to a public Github repo and I'll clone it and try to debug. It should look something like the example repo I linked above - complete but minimal, except that it results in the errors you're seeing. |
I'm having this problem too, in node. I've been using both the admin and client sdks together, for example to create a custom token and then login with it, especially for testing. |
@Feiyang1 thanks for your detailed response, and it is working for me with firebase 5.11.1 like you say.
|
@inorganik in your repo https://github.com/inorganik/angularfire-test, |
Installing firebase in my functions folder at v 5.11.1 fixed this issue for me. Thanks @Feiyang1 ! It seems clear now the issue is understanding which versions of firebase are compatible with each other. Having major versions synced up would be nice. At the very least can we have a REAME that shows compatible versions of everything? It would save us a lot of pain and suffering. |
Closing since it seems the issue has been resolved. |
@Feiyang1 I don't think it is resolved. The fact that you need to select particular version combinations of the two will cause headaches for new users, and closing this suggests Google is ok with it not being reliable to use the firebase package in node (which there are good reasons for doing). If I build my product based on this, will I be at risk in the future of not being able to upgrade, because there is no pair of versions that works? e.g. currently, I'm stuck on 5.x |
Dear @Feiyang1 , Closing without a proper/stable solution is unfair. Don't you think? Thank You |
@buzzware @ramen-mukherjee |
@Feiyang1 your above comment doesn't seem to work for me. |
I have the following package versions and the functions emulator work as expected:
If I update the |
@donaldaverill please take a look at the conversation in #2054 |
Thank you @Feiyang1. Yes, I've read through that thread a few times. I'm not importing or requiring anything directly from the
Does that seem okay? |
That looks fine. I don't see any change in |
@Feiyang1 As it turns out, I don't need the |
#1696 (comment) describes a different issue than yours. The issue is that Do you have separate
then you can remove |
And we are removing this error |
Thanks again @Feiyang1
Ok, makes sense.
I have one package.json. Additionally, one of my functions is an Angular Universal app that includes AngularFire. This function/universal app has broken as well due to the |
I see. I still don't understand why 6.3.5 works though. Anyway, a new version will come out later today that won't cause this issue anymore. |
@Feiyang1 |
Introduction
After the recent updates (I update regularly), I am getting following error while running the application. Project is created with Angular CLI. As of now, no build errors.
System
Steps to reproduce:
Screenshot
Code
`import { User } from './../models/user.model';
import { Observable, Observer } from 'rxjs';
import { Injectable } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/auth';
import { auth } from 'firebase/app';
@Injectable({
providedIn: 'root'
})
export class AuthService {
user: User = {
name: '',
email: '',
photo: '',
token: {
value: '',
uid: '',
createdOn: '',
expiredOn: '',
isAuthenticated: false,
isAdmin: false
}
};
constructor(public afAuth: AngularFireAuth) { }
observable$ = Observable.create((observer) => {
try {
this.getUserDetails();
observer.next(this.user);
} catch {
this.resetUserData();
observer.error();
} finally {
observer.complete();
}
});
getAuthUser(): Observable {
return this.observable$;
}
login(): User | void {
this.afAuth.auth.setPersistence(auth.Auth.Persistence.SESSION);
this.afAuth.auth.signInWithPopup(new auth.GoogleAuthProvider())
.then((user) => {
if (user) {
this.getUserDetails();
}
})
.catch((error) => {
this.resetUserData();
console.error(error);
});
return this.user;
}
logout(): void {
this.afAuth.auth.signOut()
.then(() => {
this.resetUserData();
})
.catch(
response => console.error('Error Occured While Logging Out' + response)
);
}
getUserDetails(): User | void {
this.afAuth.auth.onAuthStateChanged((currentUser) => {
if (currentUser) {
this.user.name = currentUser.displayName;
this.user.email = currentUser.email;
this.user.photo = currentUser.photoURL;
this.getUserToken();
} else {
this.resetUserData();
console.error('No user present. Please login');
}
});
return this.user;
}
async getUserToken(): Promise {
await this.afAuth.auth.currentUser.getIdTokenResult()
.then((token) => {
if (token) {
this.user.token.value = token.token ? token.token : '';
this.user.token.createdOn = token.issuedAtTime ? token.issuedAtTime : '';
this.user.token.expiredOn = token.expirationTime ? token.expirationTime : '';
this.user.token.uid = token.claims ? (token.claims.user_id ? token.claims.user_id : '') : '';
this.user.token.isAuthenticated = this.isAuthenticated();
}
})
.catch(() => {
this.resetUserData();
console.error('error while getting the token');
});
}
isAuthenticated(): boolean {
if (this.user.token.createdOn && this.user.token.expiredOn) {
const expiryTime = new Date(this.user.token.expiredOn).getTime();
const creationTime = new Date(this.user.token.createdOn).getTime();
const currentTime = new Date().getTime();
if (expiryTime > creationTime && expiryTime > currentTime) {
return true;
} else {
console.error('Evicting Unauthenticated user');
this.logout();
return false;
}
} else {
console.error('Evicting Unauthenticated user');
this.logout();
return false;
}
}
resetUserData(): User | void {
this.user = {
name: '',
email: '',
photo: '',
token: {
value: '',
uid: '',
createdOn: '',
expiredOn: '',
isAuthenticated: false,
isAdmin: false
}
};
return this.user;
}
}
`
Error 1:
AppComponent.html:1 ERROR TypeError: app.auth is not a function
at auth.js:24
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (polyfills.js:7929)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (polyfills.js:7688)
at NgZone.push../node_modules/@angular/core/fesm5/core.js.NgZone.runOutsideAngular (core.js:17258)
at new AngularFireAuth (auth.js:22)
at createClass (core.js:21273)
at createProviderInstance (core.js:21235)
at resolveNgModuleDep (core.js:21199)
at NgModuleRef.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef.get (core.js:21907)
at resolveDep (core.js:22278)
Error 2:
AppComponent.html:1 ERROR CONTEXT DebugContext_ {view: {…}, nodeIndex: 1, nodeDef: {…}, elDef: {…}, elView: {…}}
View_AppComponent_0 @ AppComponent.html:1
proxyClass @ compiler.js:18239
push../node_modules/@angular/core/fesm5/core.js.DebugContext_.logError @ core.js:24139
push../node_modules/@angular/core/fesm5/core.js.ErrorHandler.handleError @ core.js:15777
(anonymous) @ core.js:17870
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:391
push../node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:150
push../node_modules/@angular/core/fesm5/core.js.NgZone.runOutsideAngular @ core.js:17258
(anonymous) @ core.js:17870
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:391
onInvoke @ core.js:17299
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:390
push../node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:150
(anonymous) @ zone.js:889
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:423
onInvokeTask @ core.js:17290
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:422
push../node_modules/zone.js/dist/zone.js.Zone.runTask @ zone.js:195
drainMicroTaskQueue @ zone.js:601
Promise.then (async)
scheduleMicroTask @ zone.js:584
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:413
push../node_modules/zone.js/dist/zone.js.Zone.scheduleTask @ zone.js:238
push../node_modules/zone.js/dist/zone.js.Zone.scheduleMicroTask @ zone.js:258
scheduleResolveOrReject @ zone.js:879
ZoneAwarePromise.then @ zone.js:1012
push../node_modules/@angular/core/fesm5/core.js.PlatformRef.bootstrapModule @ core.js:17803
./src/main.ts @ main.ts:14
webpack_require @ runtime.js:84
0 @ polyfills.ts:81
webpack_require @ runtime.js:84
checkDeferredModules @ runtime.js:46
webpackJsonpCallback @ runtime.js:33
(anonymous) @ main.js:1
Dependency List
"dependencies": {
"@angular/animations": "^7.2.15",
"@angular/cdk": "^7.3.7",
"@angular/common": "^7.2.15",
"@angular/compiler": "^7.2.15",
"@angular/core": "^7.2.15",
"@angular/fire": "^5.1.3",
"@angular/flex-layout": "^7.0.0-beta.24",
"@angular/forms": "^7.2.15",
"@angular/http": "^7.2.15",
"@angular/material": "^7.3.7",
"@angular/platform-browser": "^7.2.15",
"@angular/platform-browser-dynamic": "^7.2.15",
"@angular/pwa": "^0.13.9",
"@angular/router": "^7.2.15",
"@angular/service-worker": "^7.2.15",
"@ngrx/core": "^1.2.0",
"@ngrx/effects": "^7.4.0",
"@ngrx/entity": "^7.4.0",
"@ngrx/router-store": "^7.4.0",
"@ngrx/schematics": "^7.4.0",
"@ngrx/store": "^7.4.0",
"@ngrx/store-devtools": "^7.4.0",
"@trademe/ng-defer-load": "^2.0.0",
"@types/angular": "^1.6.54",
"@types/angular-material": "^1.1.68",
"@types/firebase-client": "^0.1.32",
"@types/firebase-token-generator": "^2.0.28",
"classlist.js": "^1.1.20150312",
"core-js": "^2.6.5",
"firebase": "^6.0.2",
"firebase-admin": "^6.5.1",
"firebase-functions": "^2.3.1",
"firebase-tools": "^6.9.2",
"hammerjs": "^2.0.8",
"node-sass": "^4.12.0",
"rxjs": "^6.5.2",
"web-animations-js": "^2.3.1",
"zone.js": "^0.8.29"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.13.9",
"@angular/cli": "^7.3.9",
"@angular/compiler-cli": "^7.2.15",
"@angular/language-service": "^7.2.15",
"@types/jasmine": "^3.3.12",
"@types/jasminewd2": "^2.0.6",
"@types/node": "^10.14.6",
"codelyzer": "^4.5.0",
"jasmine-core": "~3.3.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^3.1.4",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^2.0.5",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"protractor": "^5.4.2",
"ts-node": "~7.0.1",
"tslint": "~5.11.0",
"tslint-angular": "^1.1.2",
"types-installer": "^1.6.3",
"typescript": "^3.2.4"
}
Thank You
Regards
The text was updated successfully, but these errors were encountered: