Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/app/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {inject, Injectable} from '@angular/core';
import {Auth, getRedirectResult, GoogleAuthProvider, idToken, signInWithPopup, signInWithRedirect, signOut, user, User} from '@angular/fire/auth';
import {Auth, getRedirectResult, GoogleAuthProvider, idToken, signInWithRedirect, signOut, user, User} from '@angular/fire/auth';
import {BehaviorSubject, Subscription} from 'rxjs';

@Injectable({
Expand Down Expand Up @@ -28,12 +28,6 @@ export class AuthService {
getRedirectResult(this.auth); // ignore result
}

signInWithPopup() {
const provider = new GoogleAuthProvider();
provider.setCustomParameters({hd: 'docchula.com'});
return signInWithPopup(this.auth, provider);
}

signInWithRedirect() {
const provider = new GoogleAuthProvider();
provider.setCustomParameters({hd: 'docchula.com'});
Expand Down
18 changes: 7 additions & 11 deletions src/app/welcome/welcome.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,14 @@ export class WelcomePage implements OnInit, OnDestroy {
spinner: "crescent",
});
await loading.present();
await this.authService.signInWithRedirect().catch(async (error) => {
await this.alertError(
"Login Failed",
`Unable to sign in. Please try again. (${error.code}: ${error.message})`
);
})
.finally(() => loading.dismiss());

this.authService.signInWithPopup().catch(async (error) => {
if (error.code === "auth/popup-closed-by-user") {
// User closed the popup without completing the sign-in. May cause by popup blocker.
await this.authService.signInWithRedirect();
} else {
await this.alertError(
"Login Failed",
`Unable to sign in. Please try again. (${error.code}: ${error.message})`,
);
}
}).finally(() => loading.dismiss());
}

logout() {
Expand Down