Skip to content
This repository has been archived by the owner on Nov 23, 2022. It is now read-only.

Commit

Permalink
Fixed login redirect issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjun SK committed Apr 21, 2020
1 parent 46f84c8 commit 592c890
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions src/app/pages/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnInit, NgZone } from '@angular/core';
import { Auth } from 'aws-amplify';
import { Auth, Hub } from 'aws-amplify';
import { Router } from '@angular/router';
import { AmplifyService } from 'aws-amplify-angular'
import { NgxSpinnerService } from 'ngx-spinner';
Expand All @@ -18,39 +18,36 @@ export class LoginComponent implements OnInit {
private spinner: NgxSpinnerService) {


// Invoked when congnito call's callback. ie returns to angular page.
this.amplifyService.authStateChange$
.subscribe(authState => {
this.spinner.show();

if (authState.state === "cognitoHostedUI" || authState.state === "signedIn") {
this.zone.run(() => this.router.navigate(['/dashboard']));
}else{
this.spinner.hide();
}

});
// Used for listening to login events
Hub.listen("auth", ({ payload: { event, data } }) => {
if (event === "cognitoHostedUI" || event === "signedIn") {
console.log(event);
this.zone.run(() => this.router.navigate(['/dashboard']));
} else {
this.spinner.hide();
}
});

//currentAuthenticatedUser: when user comes to login page again
Auth.currentAuthenticatedUser()
.then( ()=>{
this.router.navigate(['/dashboard'],{ replaceUrl: true });
}).catch( (err) =>{
//currentAuthenticatedUser: when user comes to login page again
Auth.currentAuthenticatedUser()
.then(() => {
this.router.navigate(['/dashboard'], { replaceUrl: true });
}).catch((err) => {
this.spinner.hide();
console.log(err);
})

}
}

ngOnInit() {}
ngOnInit() { }

onLoginClick() {
this.spinner.show();
Auth.federatedSignIn();
}

onLoginClickOkta(){

onLoginClickOkta() {
this.spinner.show();

Auth.federatedSignIn({
Expand Down

0 comments on commit 592c890

Please sign in to comment.