I am currently developing a login system using Angular and Firestore, and here is the code I have written:
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import * as firebase from 'firebase/app';
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFirestore, AngularFirestoreDocument } from 'angularfire2/firestore';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/switchMap';
interface User {
uid: string;
email: string;
photoURL?: string;
displayName?: string;
favouriteColor?: string;
}
@Injectable()
export class AuthService {
user: Observable<User>;
constructor(private afAuth: AngularFireAuth,
private afs: AngularFirestore,
private router: Router) {
this.user = this.afAuth.authState
.switchMap(user => {
if (user) {
return this.afs.doc<User>(`users/${user.uid}`).valueChanges();
} else {
return Observable.of(null);
}
});
}
}
googleLogin(){
const provider = new firebase.auth.GoogleAuthProvider();
return this.oAuthLogin(provider);
}
private oAuthLogin(provider){
return this.afAuth.auth.signInWithPopup(provider)
.then((credential) => {
this.updateUserData(credential.user);
});
}
private updateUserData(user){
const userRef: AngularFirestoreDocument<User> = this.afs.doc(`users/${user.id}`);
const data: User = {
uid: user.uid,
email: user.email,
displayName: user.displayName,
photoURL: user.photoURL
};
return userRef.set(data);
}
However, when checking my console log, it indicates that I am missing semicolons. I'm not exactly sure why:
ERROR in src/app/core/auth.service.ts(40,14): error TS1005: ';' expected.
src/app/core/auth.service.ts(46,1): error TS1128: Declaration or statement expected.
src/app/core/auth.service.ts(46,29): error TS1005: ';' expected.
src/app/core/auth.service.ts(53,1): error TS1128: Declaration or statement expected.
src/app/core/auth.service.ts(53,29): error TS1005: ';' expected.
Additionally, I encountered this error:
ERROR in ./src/app/core/auth.service.ts
Module parse failed: 'return' outside of function (48:4)
You may need an appropriate loader to handle this file type.
| {
| var provider = new firebase.auth.GoogleAuthProvider();
| return this.oAuthLogin(provider);
| }
| oAuthLogin(provider);
I am confused about what TypeScript is trying to communicate. For instance, TypeScript suggests adding a semicolon at line 40 where the googleLogin() function is defined, which seems odd to me.
If anyone can help identify the spelling mistake or error, I would greatly appreciate it. I've spent over an hour troubleshooting this issue and haven't been able to pinpoint the exact problem.
Thank you in advance.