Skip to content

Commit

Permalink
Update auth.service.ts
Browse files Browse the repository at this point in the history
Ensure that we return an error message when rejecting the sign in
  • Loading branch information
AXeL-dev committed Nov 5, 2020
1 parent ac4ad8e commit 5e823e9
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/app/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AngularFireAuth } from '@angular/fire/auth';
import { Authentication, AuthenticationType } from '../models/auth.model';
import * as firebase from 'firebase/app';
import 'firebase/auth'; // required when importing firebase from 'firebase/app'
import { DebugService } from './debug.service';

@Injectable({
providedIn: 'root'
Expand All @@ -12,9 +13,12 @@ export class AuthService {
currentUser: firebase.default.User = null;
lastError: firebase.default.FirebaseError = null;

constructor(private auth: AngularFireAuth) {
constructor(
private auth: AngularFireAuth,
private debugService: DebugService
) {
this.auth.onAuthStateChanged((user) => {
// console.log(user);
// this.debugService.log(user);
this.currentUser = user;
});
}
Expand All @@ -24,10 +28,10 @@ export class AuthService {
}

signIn(authentication: Authentication): Promise<void> {
// console.log('sign in', authentication);
this.debugService.log('sign in', authentication);
return new Promise((resolve, reject) => {
if (this.isSignedIn()) {
console.log('already signed in!');
this.debugService.log('already signed in!');
resolve();
} else {
// Set authentication function
Expand Down Expand Up @@ -61,14 +65,16 @@ export class AuthService {
reject(error);
});
} else {
reject();
reject({
message: 'Unknown authentication type'
});
}
}
});
}

signOut(force: boolean = false): void {
// console.log('sign out', this.isSignedIn());
this.debugService.log('sign out', this.isSignedIn());
if (force || this.isSignedIn()) {
this.auth.signOut().catch((error: firebase.default.FirebaseError) => {
this.setLastError(error);
Expand Down

0 comments on commit 5e823e9

Please sign in to comment.