Amplify Flutter: how to implement Auto Login and obtain authToken

1.8k views Asked by At

I'm using Amplify Flutter to implement user authentication in my Flutter app and can't figure out the following two things:

  1. Auto-login: How do I implement auto-login so that users remain logged in when closing and reopening the app over time (i.e. the app remains in logged-in state indefinitely unless users specifically log out of the app)?

  2. authToken: When the user is logged in, how do I get the authToken needed to add to my outgoing api requests (from the app to my aws backend)?

Been scouring the internet (and reading through the official docs) for solutions but can't seem to find much info on this or figure it out.

1

There are 1 answers

0
Garrett On

I was experiencing this issue as well and came across Amplify's Authenticator widget.

It's pretty easy to setup and works very well with little to no effort from the developer. It infers configuration from your Amplify config dart file, even allows for extensive customization over the UI's behavior.

@override
Widget build(BuildContext context) {
    return Authenticator(
        child: MaterialApp(
            builder: Authenticator.builder(),
            home: const AppContainer(),
        ),
    );
}

Full docs can be found here