aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.32k stars 246 forks source link

Provide Stream for Current Authenticated User's State #2654

Open georgiossalon opened 1 year ago

georgiossalon commented 1 year ago

Description

Are you going to provide a Stream to get the current state of the authenticated user?

I only did find on the following page https://docs.amplify.aws/lib/auth/auth-events/q/platform/flutter/ the auth-events. This is though a StreamSubscription.

If not then could you elaborate why?

Firebase has the following function .authStateChanges() offering this feature.

Categories

Steps to Reproduce

No response

Screenshots

No response

Platforms

Flutter Version

3.3.10

Amplify Flutter Version

0.6.10

Deployment Method

Amplify CLI

Schema

No response

dnys1 commented 1 year ago

Hi @georgiossalon - we do not have any plans to add this currently, but I will discuss it with the team and get back to you.

sagnik-sanyal commented 1 year ago

Hello there, i was also wondering about this same issue, is anything available to acheive this at the moment

AYJF commented 1 year ago

same issue here. I totally agree with @georgiossalon

dnys1 commented 1 year ago

While we investigate supporting this, the current workaround is to use the availableStreams getter on Amplify.Hub like this:

final Stream<AuthUser?> userStream = Amplify.Hub.availableStreams[HubChannel.Auth]!
        .cast<AuthHubEvent>()
        .map((event) => event.payload);