1- import { Component } from ' @angular/core' ;
1+ import { Component } from " @angular/core" ;
22
3- import { FloatLabelModule } from ' primeng/floatlabel' ;
3+ import { FloatLabelModule } from " primeng/floatlabel" ;
44import {
55 FormBuilder ,
66 FormGroup ,
77 FormsModule ,
88 ReactiveFormsModule ,
99 Validators ,
10- } from '@angular/forms' ;
11- import { ActivatedRoute , Router } from '@angular/router' ;
12- import { InputTextModule } from 'primeng/inputtext' ;
13- import { ButtonModule } from 'primeng/button' ;
14- import { FocusTrapModule } from 'primeng/focustrap' ;
15- import { AuthService } from '../../services/auth.service' ;
16- import { MessageModule } from 'primeng/message' ;
17- import { HttpErrorResponse } from '@angular/common/http' ;
10+ } from "@angular/forms" ;
11+ import { ActivatedRoute , Router } from "@angular/router" ;
12+ import { InputTextModule } from "primeng/inputtext" ;
13+ import { ButtonModule } from "primeng/button" ;
14+ import { FocusTrapModule } from "primeng/focustrap" ;
15+ import { AuthParams , AuthService , Token } from "../../services/auth.service" ;
16+ import { MessageModule } from "primeng/message" ;
17+ import { HttpErrorResponse } from "@angular/common/http" ;
18+ import { SkeletonModule } from "primeng/skeleton" ;
1819
1920@Component ( {
20- selector : ' app-auth' ,
21+ selector : " app-auth" ,
2122 standalone : true ,
2223 imports : [
2324 FloatLabelModule ,
2425 ReactiveFormsModule ,
2526 ButtonModule ,
2627 FormsModule ,
2728 InputTextModule ,
29+ SkeletonModule ,
2830 FocusTrapModule ,
2931 MessageModule ,
3032 ] ,
31- templateUrl : ' ./auth.component.html' ,
32- styleUrl : ' ./auth.component.scss' ,
33+ templateUrl : " ./auth.component.html" ,
34+ styleUrl : " ./auth.component.scss" ,
3335} )
3436export class AuthComponent {
3537 private redirectURL : string ;
38+ authParams : AuthParams | undefined ;
3639 authForm : FormGroup ;
37- error : string = '' ;
40+ error : string = "" ;
3841 isRegistering : boolean = false ;
3942
4043 constructor (
@@ -43,12 +46,31 @@ export class AuthComponent {
4346 private route : ActivatedRoute ,
4447 private fb : FormBuilder ,
4548 ) {
49+ this . route . queryParams . subscribe ( ( params ) => {
50+ const code = params [ "code" ] ;
51+ if ( code ) {
52+ this . authService . oidcLogin ( code ) . subscribe ( {
53+ next : ( data ) => {
54+ if ( ! data . access_token ) {
55+ this . error = "Authentication failed" ;
56+ return ;
57+ }
58+ this . router . navigateByUrl ( this . redirectURL ) ;
59+ } ,
60+ } ) ;
61+ }
62+ } ) ;
63+
64+ this . authService . authParams ( ) . subscribe ( {
65+ next : ( params ) => ( this . authParams = params ) ,
66+ } ) ;
67+
4668 this . redirectURL =
47- this . route . snapshot . queryParams [ ' redirectURL' ] || ' /home' ;
69+ this . route . snapshot . queryParams [ " redirectURL" ] || " /home" ;
4870
4971 this . authForm = this . fb . group ( {
50- username : [ '' , { validators : Validators . required } ] ,
51- password : [ '' , { validators : Validators . required } ] ,
72+ username : [ "" , { validators : Validators . required } ] ,
73+ password : [ "" , { validators : Validators . required } ] ,
5274 } ) ;
5375 }
5476
@@ -58,7 +80,7 @@ export class AuthComponent {
5880 }
5981
6082 register ( ) : void {
61- this . error = '' ;
83+ this . error = "" ;
6284 if ( this . authForm . valid ) {
6385 this . authService . register ( this . authForm . value ) . subscribe ( {
6486 next : ( ) => {
@@ -73,17 +95,22 @@ export class AuthComponent {
7395 }
7496
7597 authenticate ( ) : void {
76- this . error = '' ;
77- if ( this . authForm . valid ) {
78- this . authService . login ( this . authForm . value ) . subscribe ( {
79- next : ( ) => {
80- this . router . navigateByUrl ( this . redirectURL ) ;
81- } ,
82- error : ( err : HttpErrorResponse ) => {
83- this . authForm . reset ( ) ;
84- this . error = err . error . detail ;
85- } ,
86- } ) ;
98+ this . error = "" ;
99+ if ( this . authParams ?. oidc ) {
100+ window . location . replace ( encodeURI ( this . authParams . oidc ) ) ;
87101 }
102+
103+ this . authService . login ( this . authForm . value ) . subscribe ( {
104+ next : ( data ) => {
105+ if ( ! data . access_token ) {
106+ this . error = "Authentication failed" ;
107+ return ;
108+ }
109+ this . router . navigateByUrl ( this . redirectURL ) ;
110+ } ,
111+ error : ( ) => {
112+ this . authForm . reset ( ) ;
113+ } ,
114+ } ) ;
88115 }
89116}
0 commit comments