Skip to content

Commit 5e823e9

Browse files
committed
Update auth.service.ts
Ensure that we return an error message when rejecting the sign in
1 parent ac4ad8e commit 5e823e9

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/app/services/auth.service.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { AngularFireAuth } from '@angular/fire/auth';
33
import { Authentication, AuthenticationType } from '../models/auth.model';
44
import * as firebase from 'firebase/app';
55
import 'firebase/auth'; // required when importing firebase from 'firebase/app'
6+
import { DebugService } from './debug.service';
67

78
@Injectable({
89
providedIn: 'root'
@@ -12,9 +13,12 @@ export class AuthService {
1213
currentUser: firebase.default.User = null;
1314
lastError: firebase.default.FirebaseError = null;
1415

15-
constructor(private auth: AngularFireAuth) {
16+
constructor(
17+
private auth: AngularFireAuth,
18+
private debugService: DebugService
19+
) {
1620
this.auth.onAuthStateChanged((user) => {
17-
// console.log(user);
21+
// this.debugService.log(user);
1822
this.currentUser = user;
1923
});
2024
}
@@ -24,10 +28,10 @@ export class AuthService {
2428
}
2529

2630
signIn(authentication: Authentication): Promise<void> {
27-
// console.log('sign in', authentication);
31+
this.debugService.log('sign in', authentication);
2832
return new Promise((resolve, reject) => {
2933
if (this.isSignedIn()) {
30-
console.log('already signed in!');
34+
this.debugService.log('already signed in!');
3135
resolve();
3236
} else {
3337
// Set authentication function
@@ -61,14 +65,16 @@ export class AuthService {
6165
reject(error);
6266
});
6367
} else {
64-
reject();
68+
reject({
69+
message: 'Unknown authentication type'
70+
});
6571
}
6672
}
6773
});
6874
}
6975

7076
signOut(force: boolean = false): void {
71-
// console.log('sign out', this.isSignedIn());
77+
this.debugService.log('sign out', this.isSignedIn());
7278
if (force || this.isSignedIn()) {
7379
this.auth.signOut().catch((error: firebase.default.FirebaseError) => {
7480
this.setLastError(error);

0 commit comments

Comments
 (0)