question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

amplify-angular: authState as BehaviorSubject in amplify.service.ts

See original GitHub issue

Hi,

It would be helpful if we change the _authState Subject to be a BehaviorSubject @ https://github.com/aws-amplify/amplify-js/blob/master/packages/aws-amplify-angular/src/providers/amplify.service.ts#L35

I am piping the authStateChange$ observable in my CanActivate guard and with the subject it will only work on page load since that is when the value is emitted. When I navigate to other routes and back to a route guarded by the CanActivate, the pipe will not work since the Subject didn’t emit a new value.

I am happy to make a PR for this?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
mattiLeBlanccommented, Jul 21, 2019

I resolved it by adding my own behaviorSubject in my service and linking it to the stateChange:

 
  private authState = new BehaviorSubject<AuthState>({ state: null, user: {} }); 
  private onDestroy = new Subject(); 
  public authState$: Observable<AuthState> = this.authState.asObservable(); 

...
...
...

    this.amplifyService.authStateChange$ 
      .pipe( 
        takeUntil(this.onDestroy) 
      ) 
      .subscribe( authState => { 
        this.authState.next(authState); 
      }); 
0reactions
github-actions[bot]commented, Jun 12, 2021

This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS Amplify Auth & Angular RxJS Simple State Management
We define our public interface of our state in AuthState and create an initial object initialAuthState . We decided to use the default ......
Read more >
PreAuth trigger lifecycle for denying token - Cognito/Amplify
I'm looking at amplify docs and I've set up my code to check for ... authState.state === "customConfirmSignIn"; in header.component.ts, ...
Read more >
Implement Authentication in Angular using AWS Amplify -
This article is about how to implement Authentication in an Angular using AWS amplify within a very short period of time.
Read more >
Customization | Amplify UI for Angular
Headers & Footers. The Authenticator has several "slots" that you can customize to add messaging & functionality to meet your app's needs.
Read more >
How to use AWS Amplify and Angular to Build Cloud Enabled ...
Import AmplifyService into your component and listen for auth state changes: import { AmplifyService } from 'aws-amplify-angular'; // ... constructor( public ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found