Handle waiting for google library
This commit is contained in:
@@ -20,7 +20,6 @@ export class AuthGuard {
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
console.log('Not auth try to wait');
|
||||
return this.tryWaitForAuthData();
|
||||
}
|
||||
}
|
||||
@@ -30,7 +29,6 @@ export class AuthGuard {
|
||||
if (this.auth$.isAuthenticated()) {
|
||||
resolve(true);
|
||||
} else {
|
||||
console.log('GoToLogin');
|
||||
this.loginUrl = window.location.pathname;
|
||||
this.router$.navigate(['']);
|
||||
resolve(false);
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
|
||||
import moment, { Moment } from 'moment';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { User } from '../models/user.model';
|
||||
import { from, Observable } from 'rxjs';
|
||||
import { BehaviorSubject, from, Observable } from 'rxjs';
|
||||
import jwt_decode from "jwt-decode";
|
||||
|
||||
@Injectable({
|
||||
@@ -16,6 +16,8 @@ export class AuthService {
|
||||
user!: User;
|
||||
apiTokenExpirationTime!: Moment;
|
||||
|
||||
public isGoogleLibLoaded: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
|
||||
|
||||
bc!: BroadcastChannel;
|
||||
|
||||
constructor(
|
||||
@@ -23,6 +25,11 @@ export class AuthService {
|
||||
) {
|
||||
this.createBroadcastChannel();
|
||||
this.askForAuthData();
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
window.onGoogleLibraryLoad = () => {
|
||||
this.isGoogleLibLoaded.next(true);
|
||||
};
|
||||
}
|
||||
|
||||
ping() {
|
||||
@@ -77,14 +84,10 @@ export class AuthService {
|
||||
}
|
||||
// broadcastChannel
|
||||
createBroadcastChannel() {
|
||||
try {
|
||||
this.bc = new BroadcastChannel('auth');
|
||||
this.bc.onmessage = (event: MessageEvent<AuthMessage>) => {
|
||||
this.broadcastListener(event);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('eee', e);
|
||||
}
|
||||
}
|
||||
broadcastListener(event: MessageEvent<AuthMessage>) {
|
||||
switch (event.data.type) {
|
||||
|
||||
@@ -48,7 +48,6 @@ export class LayerEditComponent implements OnInit {
|
||||
|
||||
async ngOnInit() {
|
||||
this.document = await this.load();
|
||||
console.log(this.document);
|
||||
}
|
||||
|
||||
private async load(): Promise<Layer> {
|
||||
|
||||
@@ -69,7 +69,6 @@ export class LayersListComponent implements OnInit {
|
||||
}
|
||||
|
||||
openInNewTab(element: Layer) {
|
||||
console.log(element);
|
||||
const url = this._router.serializeUrl(
|
||||
this._router.createUrlTree([`/app/layers/Detail/${element.id}`])
|
||||
);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<script src="https://accounts.google.com/gsi/client" async="" defer=""></script>
|
||||
<div class="loading-container" *ngIf="loading">
|
||||
<img class="loading-img" src="../../assets/loader.gif" />
|
||||
</div>
|
||||
|
||||
@@ -26,13 +26,16 @@ export class LoginViewComponent implements OnInit {
|
||||
loading = false;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.auth$.isGoogleLibLoaded.subscribe((isLoaded) => {
|
||||
if (isLoaded) {
|
||||
this.initGoogleLogin();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
initGoogleLogin() {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
window.onGoogleLibraryLoad = () => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
|
||||
google.accounts.id.initialize({
|
||||
client_id: environment.google.clientId,
|
||||
callback: this.handleCredentialResponse.bind(this),
|
||||
@@ -51,7 +54,6 @@ export class LoginViewComponent implements OnInit {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
google.accounts.id.prompt();
|
||||
};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
|
||||
Reference in New Issue
Block a user