argos/dmp-frontend/src/app/ui/auth/login/login.component.ts

52 lines
1.6 KiB
TypeScript
Raw Normal View History

2024-04-01 17:36:03 +02:00
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';
2024-04-01 17:36:03 +02:00
import { KeycloakService } from 'keycloak-angular';
import { from } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
2019-01-18 18:03:45 +01:00
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
})
export class LoginComponent extends BaseComponent implements OnInit {
2019-01-18 18:03:45 +01:00
@Input() redirect: boolean = true;
@Input() mergeUsers: boolean;
2019-01-18 18:03:45 +01:00
public auth2: any;
private returnUrl: string;
2019-11-13 16:32:55 +01:00
//public cofigurableProviders: ConfigurableProvider[];
2019-01-18 18:03:45 +01:00
constructor(
2024-04-01 17:36:03 +02:00
private zone: NgZone,
private router: Router,
2019-11-13 16:32:55 +01:00
private authService: AuthService,
2024-04-01 17:36:03 +02:00
private route: ActivatedRoute,
private keycloakService: KeycloakService
2019-01-18 18:03:45 +01:00
) { super(); }
ngOnInit(): void {
2024-04-04 12:50:51 +02:00
this.returnUrl = this.route.snapshot.queryParamMap.get('returnUrl') || '/';
2024-04-08 15:22:56 +02:00
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('/'));
2024-04-01 17:36:03 +02:00
2024-04-08 15:22:56 +02:00
}
}
2019-01-18 18:03:45 +01:00
}