Skip to content

Commit

Permalink
Fix/infinite login loop issue 1737 (#1775)
Browse files Browse the repository at this point in the history
* Fix : Infinite login page redirect loop

Bug: On webapp load, if config is missing, app can go into an infinite login page redirect loop #1737

* Delete error.component.spec.ts

No need for static error page
  • Loading branch information
JaysinhGo authored Nov 6, 2023
1 parent 0718a01 commit c81f051
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 11 deletions.
3 changes: 2 additions & 1 deletion webapp/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ import { LandingPageModule } from './landing-page/landing-page.module';
import { FetchResourcesService } from './pacman-features/services/fetch-resources.service';
import { PostLoginAppModule } from './post-login-app/post-login-app.module';
import { TokenResolverService } from './resolver/token-resolver.service';
import { ErrorComponent } from './error/error.component';

@NgModule({
declarations: [AppComponent],
declarations: [AppComponent, ErrorComponent],
imports: [
BrowserModule,
BrowserAnimationsModule,
Expand Down
20 changes: 20 additions & 0 deletions webapp/src/app/error/error.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.error-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh; /* 100% of the viewport height */
text-align: center;
}

h1 {
font-size: 36px;
color: #FF0000;
margin-bottom: 20px;
}

p {
font-size: 18px;
color: #333;
}

4 changes: 4 additions & 0 deletions webapp/src/app/error/error.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="error-container">
<h1>Something went wrong</h1>
<p>Please try again after some time.</p>
</div>
15 changes: 15 additions & 0 deletions webapp/src/app/error/error.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'app-error',
templateUrl: './error.component.html',
styleUrls: ['./error.component.css']
})
export class ErrorComponent implements OnInit {

constructor() { }

ngOnInit(): void {
}

}
5 changes: 5 additions & 0 deletions webapp/src/app/landing-page/landing-page.routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { TokenResolverService } from '../resolver/token-resolver.service';

import { HomePageComponent } from './home-page/home-page.component';
import { LoginComponent } from './login/login.component';
import { ErrorComponent } from '../error/error.component';

const routes: Routes = [
{
Expand All @@ -46,6 +47,10 @@ const routes: Routes = [
redirectTo: '/home/login',
pathMatch: 'full'
},
{
path: 'error',
component: ErrorComponent,
},
];

@NgModule({
Expand Down
37 changes: 27 additions & 10 deletions webapp/src/app/landing-page/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,33 @@ export class LoginComponent implements OnInit {
private cognitoService: AwsCognitoService,
private httpService: HttpService,
private dataCacheService:DataCacheService,
) {
) {}

console.log('Auth type:', CONFIGURATIONS.optional.auth.AUTH_TYPE)
@Input() menuState: string;
@Output() onClose = new EventEmitter();

ngOnInit() {
// Check if the configuration is valid; if not, navigate to the error page

if(this._verifyConfiguration()) this._init();
else this.router.navigate(['/error']);
}

private _verifyConfiguration(){
if(!CONFIGURATIONS.optional.auth.AUTH_TYPE){
console.error('AUTH_TYPE is missing in configuration');
return false
}
if(!CONFIGURATIONS.optional.auth.cognitoConfig.loginURL){
console.error('Login URL is missing in configuration');
return false
}
return true;
}
private _init(){
// Private method to initialize the application based on the configuration

console.log('Auth type:', CONFIGURATIONS.optional.auth.AUTH_TYPE);
if (CONFIGURATIONS.optional.auth.AUTH_TYPE === 'azuresso') {
this.adalService.login();
} else if (CONFIGURATIONS.optional.auth.AUTH_TYPE === 'cognito') {
Expand All @@ -69,14 +93,7 @@ export class LoginComponent implements OnInit {
} else {
this.showOnPremLogin = true;
}

this.content = CONTENT;
}

@Input() menuState: string;
@Output() onClose = new EventEmitter();

ngOnInit() {
this.content = CONTENT;
}

login() {
Expand Down

0 comments on commit c81f051

Please sign in to comment.