So right now im writing a login system with angular and firestore, here's my code:
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, my console log is telling me, that i miss semicolons, not quite 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.
and also:
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 have obviously no idea what typescript wants to tell me. For example, in the first error, typescript says i need to add an semicolon at line 40, but line 40 is the function googleLogin(){} itself, so not quite sure whats going on here.
If anyone is able to find the misspell / error i would appreciate it. Been sitting on this for now over an hour and simply can't find whats exactly wrong.
Thanks in advance.