52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import { Component, Input, NgZone, OnInit } from '@angular/core';
|
|
import { ActivatedRoute, Params, Router } from '@angular/router';
|
|
import { AuthService } from '@app/core/services/auth/auth.service';
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
import { KeycloakService } from 'keycloak-angular';
|
|
import { from } from 'rxjs';
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
@Component({
|
|
selector: 'app-login',
|
|
templateUrl: './login.component.html',
|
|
styleUrls: ['./login.component.scss']
|
|
})
|
|
export class LoginComponent extends BaseComponent implements OnInit {
|
|
|
|
@Input() redirect: boolean = true;
|
|
@Input() mergeUsers: boolean;
|
|
|
|
public auth2: any;
|
|
private returnUrl: string;
|
|
//public cofigurableProviders: ConfigurableProvider[];
|
|
|
|
constructor(
|
|
private zone: NgZone,
|
|
private router: Router,
|
|
private authService: AuthService,
|
|
private route: ActivatedRoute,
|
|
private keycloakService: KeycloakService
|
|
) { super(); }
|
|
|
|
ngOnInit(): void {
|
|
this.returnUrl = this.route.snapshot.queryParamMap.get('returnUrl') || '/';
|
|
if (!this.keycloakService.isLoggedIn()) {
|
|
this.authService.authenticate('/');
|
|
} else {
|
|
this.authService.prepareAuthRequest(from(this.keycloakService.getToken())).pipe(takeUntil(this._destroyed)).subscribe(
|
|
() => {
|
|
let returnUrL = this.returnUrl;
|
|
let queryParams: Params = {};
|
|
if (!this.authService.selectedTenant()) {
|
|
this.authService.selectedTenant('default');
|
|
// returnUrL = '/login/post';
|
|
// queryParams.returnUrl = this.returnUrl;
|
|
}
|
|
this.zone.run(() => this.router.navigate([returnUrL], { queryParams }));
|
|
},
|
|
(error) => this.authService.authenticate('/'));
|
|
|
|
}
|
|
}
|
|
}
|