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 247 forks source link

[Authenticator] Make current `AuthState` accessible #3245

Open torbenkeller opened 1 year ago

torbenkeller commented 1 year ago

I want to hide just a section of the page when the user is not logged in and display a button to open the authentication flow. Unfortunately it is not possible to access the current AuthState outside of the authenticator forms, so in the section I can not wrap the layouts depending on the current AuthState. Possible solutions would be:

export InheritedAuthBloc This would be my preferred solution because it provides a stream of AuthState that could also be used to automatically redirect using GoRouter.refreshListenable.

create InheritedAuthState This would make the current AuthState accessible inside custom components but keep the use cases pretty limited to that.

Jordan-Nelson commented 1 year ago

Hi @torbenkeller - This sounds like a reasonable request. The react Authenticator does expose some ability to access the state. The flutter authenticator does not have this ability.

In addition to the suggestions above, another option would be to expose AuthenticatorState outside of the authenticatorBuilder method. This is intended to be the publicly exposed representation of the internal state. Since it is intended only to be used in an unauthenticated state, it does not currently expose all of the info you might want to access for your use case. An inherited widget for this exists, but it is not exposed.

I will mark this as a feature request so that we can track interest in this.

torbenkeller commented 1 year ago

Hi @Jordan-Nelson - unfortunately AuthenticatorState is not exposing the AuthState

Jordan-Nelson commented 1 year ago

@torbenkeller - Correct. If AuthenticatorState were exposed for broader use than the original intended purpose, we would need to reconsider what is included in the AuthenticatorState API.