Limpieza auth
This commit is contained in:
@@ -19,9 +19,8 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
async ngOnInit(): Promise<void> {
|
||||
console.log('AppComponent.ngInit()');
|
||||
|
||||
// const chatLoginToken = await this.waitChatToken();
|
||||
// const authState = await this.authService.configureAndTryLogin(chatLoginToken);
|
||||
const authState = await this.authService.configureAndTryLogin(null);
|
||||
const chatLoginToken = await this.waitChatToken();
|
||||
const authState = await this.authService.configureAndTryLogin(chatLoginToken);
|
||||
|
||||
if (authState !== AuthState.ChatLoggingInProcess) {
|
||||
this.showOverlay = false;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { OidcSecurityService } from 'angular-auth-oidc-client';
|
||||
import { BehaviorSubject, Subject } from 'rxjs';
|
||||
import { first } from 'rxjs/operators';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { User } from '../entities/user';
|
||||
import { ApiService } from './api.service';
|
||||
import { ChatService } from './chat.service';
|
||||
@@ -16,8 +15,6 @@ export enum AuthState {
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthService {
|
||||
private checkAuthSubject: Subject<boolean>;
|
||||
|
||||
private loggedSubject = new BehaviorSubject<boolean>(false);
|
||||
public logged$ = this.loggedSubject.asObservable();
|
||||
|
||||
@@ -32,14 +29,6 @@ export class AuthService {
|
||||
|
||||
login(): void {
|
||||
this.oidcSecurityService.authorize();
|
||||
|
||||
this.checkAuthSubject?.pipe(first()).subscribe((auth) => {
|
||||
console.log('Login result=', auth);
|
||||
if (auth) {
|
||||
// Endpoint /user/ creates User in DB if it does not exist
|
||||
this.apiService.getUser().subscribe();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
logout(): void {
|
||||
@@ -51,24 +40,21 @@ export class AuthService {
|
||||
}
|
||||
|
||||
async configureAndTryLogin(chatLoginToken: string): Promise<AuthState> {
|
||||
this.checkAuthSubject = new Subject<boolean>();
|
||||
this.oidcSecurityService.checkAuth().subscribe(this.checkAuthSubject);
|
||||
|
||||
this.oidcSecurityService.userData$.subscribe((claims) => {
|
||||
console.log(claims);
|
||||
console.log('name=' + User.fromClaims(claims)?.name);
|
||||
this.userSubject.next(User.fromClaims(claims));
|
||||
if (claims == null) {
|
||||
this.loggedSubject.next(false);
|
||||
}
|
||||
});
|
||||
this.oidcSecurityService.isAuthenticated$.subscribe((auth) => {
|
||||
console.log('isAuthenticated', auth);
|
||||
this.loggedSubject.next(auth);
|
||||
});
|
||||
|
||||
return this.checkAuthSubject.toPromise().then((auth) => {
|
||||
console.log('is authenticated', auth);
|
||||
this.oidcSecurityService.userData$.subscribe((claims) => {
|
||||
if (claims != null) {
|
||||
console.log(claims);
|
||||
console.log('name=' + User.fromClaims(claims)?.name);
|
||||
}
|
||||
this.userSubject.next(User.fromClaims(claims));
|
||||
});
|
||||
|
||||
return this.oidcSecurityService.checkAuth().toPromise().then((auth) => {
|
||||
console.log('AUTH INITIALIZED result=', auth);
|
||||
|
||||
if (auth) {
|
||||
if (sessionStorage.getItem('chatLoginInProcess') === 'true') {
|
||||
@@ -82,7 +68,9 @@ export class AuthService {
|
||||
console.error('CHAT LOGIN TOKEN NOT RECEIVED');
|
||||
}
|
||||
|
||||
this.loggedSubject.next(true);
|
||||
// Endpoint /user/ creates User in DB if it does not exist
|
||||
this.apiService.getUser().subscribe(res => console.log(res));
|
||||
|
||||
return AuthState.Logged;
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user