Skip to content

Commit

Permalink
chore(authenticator): Docs clean up (#1183)
Browse files Browse the repository at this point in the history
* Update Authenticator docs

* Update example app

* Update README

* Update imports

* Fix broken link

* Clean up exports

* Add library doc comment

* Fix template definitions

* Fix templates

* Reference amplifyconfiguration.dart
  • Loading branch information
dnys1 authored Dec 6, 2021
1 parent 4cb61f7 commit fdd4788
Show file tree
Hide file tree
Showing 26 changed files with 281 additions and 130 deletions.
93 changes: 80 additions & 13 deletions packages/amplify_authenticator/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,88 @@
# amplify_authenticator

The Amplify Flutter Authenticator is meant to bring customers and end-users
a seamless experience while using authentication in Flutter applications.
The Amplify Flutter Authenticator simplifies the process of authenticating users by providing a fully-customizable flow which just works. Simply wrap your app's authenticated route in an Authenticator component and the process of authenticating users and managing login sessions is handled for you.

The authenticator uses a native solution for state management to avoid conflicts
between existing dependencies.
## Example

The overall architecture of the authenticator is composed by a View Model, that
handles all the data coming from the client side, and by a BLoC pattern that
separates all the business logic from the User Interface.
See the [example](https://github.com/aws-amplify/amplify-flutter/tree/main/packages/amplify_authenticator/example) which showcases many of the customizations available.

## Getting Started

TODO:
To get started, add the Authenticator to a project which has the [Auth category](https://docs.amplify.aws/lib/auth/getting-started/q/platform/flutter/) configured.

1. Refactor previous PoC into a library.
2. Migrate authenticator to NULL SAFETY.
3. SignUp & ConfirmSignUp screens implementation.
4. SignIn, ConfirmSignIn and Password screens implementation.
5. Integrate testing.
```yaml
dependencies:
amplify_auth_cognito: ^0.3.0
amplify_authenticator: ^0.1.0
amplify_flutter: ^0.3.0
```
Then, wrap your app's logged in component with an `Authenticator` widget, and you're good to go. You can use the `SignOutButton` to sign out the user from anywhere in your app.

> Remember to call `Amplify.configure` with your configuration - the Authenticator will not load until you call this method.

```dart
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_authenticator/amplify_authenticator.dart';
import 'package:amplify_flutter/amplify.dart';
import 'package:flutter/material.dart';
import 'amplifyconfiguration.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
_configureAmplify();
}
Future<void> _configureAmplify() async {
try {
await Amplify.addPlugin(AmplifyAuthCognito());
await Amplify.configure(amplifyconfig);
} on Exception catch (e) {
print('Could not configure Amplify: $e');
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
home: Authenticator(
child: const LoggedInScreen(),
),
);
}
}
class LoggedInScreen extends StatelessWidget {
const LoggedInScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
children: const [
Text('Logged In'),
SignOutButton(),
],
),
),
);
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
* permissions and limitations under the License.
*/

import 'package:amplify_authenticator/amplify_authenticator.dart';
import 'package:amplify_authenticator/src/keys.dart';
import 'package:amplify_authenticator/src/state/auth_viewmodel.dart';
import 'package:amplify_authenticator/src/state/inherited_auth_viewmodel.dart';
import 'package:amplify_flutter/amplify.dart';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// https://github.com/aws-amplify/amplify-ui/blob/main/packages/e2e/features/ui/components/authenticator/reset-password.feature
import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_authenticator/amplify_authenticator.dart';
import 'package:amplify_flutter/amplify.dart';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import 'dart:convert';
import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_authenticator/amplify_authenticator.dart';
import 'package:amplify_flutter/amplify.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_authenticator/amplify_authenticator.dart';
import 'package:amplify_flutter/amplify.dart';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_authenticator/amplify_authenticator.dart';
import 'package:amplify_flutter/amplify.dart';

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_authenticator/amplify_authenticator.dart';
import 'package:amplify_flutter/amplify.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
Expand Down
11 changes: 5 additions & 6 deletions packages/amplify_authenticator/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class _MyAppState extends State<MyApp> {
SignUpFormField.username(
validator: _validateUsername,
),
SignUpFormField.password(),
SignUpFormField.passwordConfirmation(),
SignUpFormField.familyName(),
SignUpFormField.address(
required: false,
),
],
),

Expand All @@ -100,8 +100,8 @@ class _MyAppState extends State<MyApp> {

return MaterialApp(
title: 'Authenticator Demo',
theme: ThemeData(brightness: Brightness.light),
darkTheme: ThemeData(brightness: Brightness.dark),
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
themeMode: ThemeMode.system,
debugShowCheckedModeBanner: false,

Expand All @@ -110,7 +110,6 @@ class _MyAppState extends State<MyApp> {
// in the Authenticator component.
localizationsDelegates: const [
AppLocalizations.delegate,
// GlobalMaterialLocalizations.delegate,
],
supportedLocales: const [
Locale('en'), // English
Expand Down
Loading

0 comments on commit fdd4788

Please sign in to comment.