diff --git a/ui-ngx/src/app/core/auth/auth.service.ts b/ui-ngx/src/app/core/auth/auth.service.ts index 656711bdc0..fa4ab6a2cf 100644 --- a/ui-ngx/src/app/core/auth/auth.service.ts +++ b/ui-ngx/src/app/core/auth/auth.service.ts @@ -261,6 +261,8 @@ export class AuthService { const publicId = this.utils.getQueryParam('publicId'); const accessToken = this.utils.getQueryParam('accessToken'); const refreshToken = this.utils.getQueryParam('refreshToken'); + const username = this.utils.getQueryParam('username'); + const password = this.utils.getQueryParam('password'); if (publicId) { return this.publicLogin(publicId).pipe( mergeMap((response) => { @@ -290,6 +292,23 @@ export class AuthService { return throwError(e); } return this.procceedJwtTokenValidate(); + } else if (username && password) { + const loginRequest: LoginRequest = { + username: username, + password: password + }; + return this.http.post('/api/auth/login', loginRequest, defaultHttpOptions()).pipe( + tap((loginResponse: LoginResponse) => { + try { + this.updateAndValidateToken(loginResponse.token, 'jwt_token', false); + this.updateAndValidateToken(loginResponse.refreshToken, 'refresh_token', false); + } catch (e) { + } + } + ), mergeMap( () => { + return this.procceedJwtTokenValidate(); + } + )); } return this.procceedJwtTokenValidate(doTokenRefresh); } else { diff --git a/ui-ngx/src/app/modules/login/pages/login/login.component.ts b/ui-ngx/src/app/modules/login/pages/login/login.component.ts index a53d83f839..6fe81e44ef 100644 --- a/ui-ngx/src/app/modules/login/pages/login/login.component.ts +++ b/ui-ngx/src/app/modules/login/pages/login/login.component.ts @@ -22,7 +22,7 @@ import { PageComponent } from '@shared/components/page.component'; import { FormBuilder } from '@angular/forms'; import { HttpErrorResponse } from '@angular/common/http'; import { Constants } from '@shared/models/constants'; -import { ActivatedRoute, Router } from '@angular/router'; +import { Router } from '@angular/router'; @Component({ selector: 'tb-login', @@ -39,17 +39,11 @@ export class LoginComponent extends PageComponent implements OnInit { constructor(protected store: Store, private authService: AuthService, public fb: FormBuilder, - private router: Router, - private route: ActivatedRoute) { + private router: Router) { super(store); } ngOnInit() { - if (this.route.snapshot.queryParams.username && this.route.snapshot.queryParams.password) { - this.loginFormGroup.setValue({username: this.route.snapshot.queryParams.username, - password: this.route.snapshot.queryParams.password}); - this.login(); - } } login(): void {