Added new background & login

This commit is contained in:
2020-06-11 01:01:12 -04:00
parent 4dad4556e9
commit 1539f2eb50
13 changed files with 167 additions and 3335 deletions

View File

@ -0,0 +1,47 @@
import {Injectable} from "@angular/core";
import {BehaviorSubject, from} from "rxjs";
import {AngularFirestore} from "@angular/fire/firestore";
import {AngularFireAuth} from "@angular/fire/auth";
import {auth} from 'firebase';
import {Router} from "@angular/router";
import {flatMap, map, skip} from 'rxjs/operators';
import {User} from '../models/user';
@Injectable({
providedIn: 'root'
})
export class AuthService {
readonly collection = 'Users';
authenticated = false;
user = new BehaviorSubject<User>(null);
constructor(private afAuth: AngularFireAuth, private router: Router, private db: AngularFirestore) {
this.user.subscribe(user => {
console.log(user, user instanceof Object);
this.authenticated = user instanceof Object
});
this.afAuth.user.pipe(
flatMap((user: any) => {
if(!user) return from([false]);
let ref = this.db.collection(this.collection).doc(user.uid);
return ref.valueChanges().pipe(map(dbUser => Object.assign({ref: ref}, user, dbUser)))
})
).subscribe(user => this.user.next(<User>user));
}
async loginWithGoogle() {
this.afAuth.auth.signInWithPopup(new auth.GoogleAuthProvider());
return this.user.pipe(skip(1));
}
async loginWithFacebook() {
this.afAuth.auth.signInWithPopup(new auth.FacebookAuthProvider());
return this.user.pipe(skip(1));
}
async logout() {
await this.afAuth.auth.signOut();
return this.router.navigate(['/']);
}
}