Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOSIP-27524 added with credentials #678

Closed
wants to merge 14 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 38 additions & 16 deletions src/app/landing-page/landing-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { HttpClient } from '@angular/common/http';
import { AppConfigService } from '../app-config.service';
import { Subscription } from 'rxjs';

@Component({
selector: 'app-landing-page',
Expand All @@ -10,30 +11,51 @@ import { AppConfigService } from '../app-config.service';
})
export class LandingPageComponent implements OnInit {
showLandingPage = false;
subscriptions: Subscription[] = [];

constructor(private router: Router, private http: HttpClient, private appConfigService: AppConfigService,) { }

async ngOnInit() {
this.showLandingPage = false;
await this.http
.get(
`${this.appConfigService.getConfig().SERVICES_BASE_URL
}authorize/admin/validateToken`
).subscribe(async (res: any) => {
console.log(res);
if (res && res.errors.length == 0) {
await this.router.navigateByUrl(`toolkit`);
} else {
this.showLandingPage = true;
}
},
(errors) => {
this.showLandingPage = true;
}
);
console.log(`LandingPageComponent: ngOnInit: this.showLandingPage : ${this.showLandingPage}`);
let flag = await this.isUserAuthenticated();
if (flag) {
await this.router.navigateByUrl(`toolkit`);
}
console.log(`LandingPageComponent: ngOnInit: complete`);
}

async isUserAuthenticated() {
return new Promise((resolve, reject) => {
this.subscriptions.push(
this.http.get(`${this.appConfigService.getConfig().SERVICES_BASE_URL
}authorize/admin/validateToken`).subscribe(
(res: any) => {
console.log(res);
if (res && res.errors && res.errors.length == 0) {
console.log(`LandingPageComponent: redirecting to toolkit`);
resolve(true);
} else {
console.log(`LandingPageComponent: redirecting to landing`);
this.showLandingPage = true;
resolve(false);
}
},
(errors) => {
this.showLandingPage = true;
console.log(`LandingPageComponent: errors: this.showLandingPage : ${this.showLandingPage}`);
resolve(false);
}
)
);
});
}

async doLogin() {
await this.router.navigate([`toolkit`]);
}

ngOnDestroy(): void {
this.subscriptions.forEach((subscription) => subscription.unsubscribe());
}
}
Loading