Skip to content

Commit

Permalink
feat(authenticator): default dial code (#3354)
Browse files Browse the repository at this point in the history
* parent b12c326
author Kha Truong <[email protected]> 1687902177 -0700
committer Kha Truong <[email protected]> 1690235526 -0700

parent b12c326
author Kha Truong <[email protected]> 1687902177 -0700
committer Kha Truong <[email protected]> 1690235203 -0700

parent b12c326
author Kha Truong <[email protected]> 1687902177 -0700
committer Kha Truong <[email protected]> 1690234697 -0700

parent b12c326
author Kha Truong <[email protected]> 1687902177 -0700
committer Kha Truong <[email protected]> 1690234586 -0700

included a parameter to let the developer set a default country code to the authenticator. still need to audit country codes and test for phone username

changed variable names to make them more consistent throughout files

removed a line of commented code

removed default dial code from the example file

rename the Country class to CountryCode to reduce confusion

Changed the CountryCode Class on the country_code.dart file

switch name of the class from CountryCode to DialCode

change country_code file name to dial code

additional countryCode -> dialCode changes

fixed imports in other files and made the constructor for dialCode private

removed the mention of country from dial_code.dart file, made defaultDialCode the second layer under dialCodeOptions for future additions, deprecated country resolver class

ci(canaries): More improvements (#3320)

- Switches to `macos-13` for iOS canaries (seems to be more reliable)
- Adds pre-build to Android to prevent timeouts
- Adds cache removal for iOS launcher action to improve flakiness

ci(dependabot): Ignore patch versions (#3373)

It's too noisy currently and since we support ranges in our constraints only a minor/major version bump could potentially impact our customers. And if a patch bump does fix a security concern, we would expect that to be handled through the dependabot security advisories which is separate from this configuration.

ci(dependabot): Fix kotlin name (#3385)

Should be `kotlin_version` I think given recent dependabot PRs

fix(codegen): Mark Cognito map as sparse (#3386)

* fix(codegen): Mark Cognito map as `sparse`

Cognito incorrectly labels the challenge parameters response type as `Map<String, String>` but returns `null` for values in certain instances. We introduce a workaround to mark the type as `sparse` until the service model is fixed.

* chore(auth): Regenerate SDK

chore(deps): Bump pigeon to `^10.0.0` (#3250)

chore(deps): Bump pigeon to `^10.1.2`

chore(repo): Improve analysis speed (#3387)

ci(dependabot): Ignore Kotlin gradle plugin (#3402)

For the same reason we ignore the Kotlin version itself

chore(api): Improve WS logging (#3401)

Improves logging in the WebSocketBloc so that events have metadata logged as well. Since this is currently done with `debug` log level, there should be no new information exposed in production logs.

Update packages/authenticator/amplify_authenticator/lib/amplify_authenticator.dart

Co-authored-by: Dillon Nys <[email protected]>

Update packages/authenticator/amplify_authenticator/lib/src/mixins/authenticator_phone_field.dart

Co-authored-by: Dillon Nys <[email protected]>

changed _countriesResolver name to _dialCodeResolver and fixed references

added deprecation and typedef to avoid breaking change with Country Resolver class name change

added template and macro for dialCodeOptions comment

chore: deprecated use of the word country and fixed references in example app and dial_code.dart files

chore: removed initialDialCode variable. It is already set in the constructor

fix: changed areas to dialCode name to more accurately represent variable

fix: changed oldCountry to oldDialCode to remove country

fix: changed country to dialCode for consistency

fix: changed dialCode to an enum and modified variables to support that

Update packages/authenticator/amplify_authenticator/lib/src/utils/dial_code.dart

Co-authored-by: Jordan Nelson <[email protected]>

fix: changed American Samoa dial code to match dial code resolver key

fix: removed areas in favor of dialCodes and fixed cascading

fix: change country to dialCode and change sort to sortedBy

fix: made this.defaultDialCode required in authenticator state. Also removed two unnecessary instances of setting defaultDialCode (already set in the DialCodeOptions constructor)

Update packages/authenticator/amplify_authenticator/lib/src/state/authenticator_state.dart

Co-authored-by: Dillon Nys <[email protected]>

fix: remove sortedBy cascade and remove necessary toList operation

Update packages/authenticator/amplify_authenticator/lib/src/l10n/auth_strings_resolver.dart

Co-authored-by: Dillon Nys <[email protected]>

included a parameter to let the developer set a default country code to the authenticator. still need to audit country codes and test for phone username

removed default dial code from the example file

Changed the CountryCode Class on the country_code.dart file

change country_code file name to dial code

added template and macro for dialCodeOptions comment

fix: changed American Samoa dial code to match dial code resolver key

fix: change country to dialCode and change sort to sortedBy

fix: made this.defaultDialCode required in authenticator state. Also removed two unnecessary instances of setting defaultDialCode (already set in the DialCodeOptions constructor)

Update packages/authenticator/amplify_authenticator/lib/src/state/authenticator_state.dart

Co-authored-by: Dillon Nys <[email protected]>

fix: remove sortedBy cascade and remove necessary toList operation

Update packages/authenticator/amplify_authenticator/lib/src/l10n/auth_strings_resolver.dart

Co-authored-by: Dillon Nys <[email protected]>

* chore: squashed commits from previous work

* Revert "Merge branch 'feat/auth/countrycode' of https://github.com/khatruong2009/amplify-flutter into feat/auth/countrycode"

This reverts commit a3bcd71, reversing
changes made to 21c4656.

---------

Co-authored-by: Dillon Nys <[email protected]>
  • Loading branch information
2 people authored and Dillon Nys committed Jul 27, 2023
1 parent 0b0a0cf commit f81b380
Show file tree
Hide file tree
Showing 14 changed files with 639 additions and 592 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_authenticator/amplify_authenticator.dart';
import 'package:amplify_authenticator_example/resolvers/localized_button_resolver.dart';
import 'package:amplify_authenticator_example/resolvers/localized_country_resolver.dart';
import 'package:amplify_authenticator_example/resolvers/localized_dial_code_resolver.dart';
import 'package:amplify_authenticator_example/resolvers/localized_input_resolver.dart';
import 'package:amplify_authenticator_example/resolvers/localized_title_resolver.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
Expand Down Expand Up @@ -83,7 +83,7 @@ class _MyAppState extends State<MyApp> {
// automatically configures the default for the others.
const stringResolver = AuthStringResolver(
buttons: LocalizedButtonResolver(),
countries: LocalizedCountryResolver(),
dialCodes: LocalizedDialResolver(),
titles: LocalizedTitleResolver(),
inputs: LocalizedInputResolver(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

/// Our custom country string resolver which calls into our localizations class.
class LocalizedCountryResolver extends CountryResolver {
const LocalizedCountryResolver();
class LocalizedDialResolver extends DialCodeResolver {
const LocalizedDialResolver();

@override
String us(BuildContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import 'package:amplify_authenticator/src/state/inherited_authenticator_state.da
import 'package:amplify_authenticator/src/state/inherited_config.dart';
import 'package:amplify_authenticator/src/state/inherited_forms.dart';
import 'package:amplify_authenticator/src/state/inherited_strings.dart';
import 'package:amplify_authenticator/src/utils/dial_code.dart';
import 'package:amplify_authenticator/src/utils/dial_code_options.dart';
import 'package:amplify_authenticator/src/widgets/authenticator_banner.dart';
import 'package:amplify_authenticator/src/widgets/form.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
Expand All @@ -35,6 +37,9 @@ import 'package:flutter/material.dart';

export 'package:amplify_auth_cognito/amplify_auth_cognito.dart'
show AuthProvider;
export 'package:amplify_authenticator/src/utils/dial_code.dart' show DialCode;
export 'package:amplify_authenticator/src/utils/dial_code_options.dart'
show DialCodeOptions;
export 'package:amplify_flutter/amplify_flutter.dart'
show PasswordProtectionSettings, PasswordPolicyCharacters;

Expand Down Expand Up @@ -303,6 +308,7 @@ class Authenticator extends StatefulWidget {
this.initialStep = AuthenticatorStep.signIn,
this.authenticatorBuilder,
this.padding = const EdgeInsets.all(32),
this.dialCodeOptions = const DialCodeOptions(),
}) :
// ignore: prefer_asserts_with_message
assert(() {
Expand Down Expand Up @@ -419,6 +425,9 @@ class Authenticator extends StatefulWidget {
/// method.
final AuthenticatorStep initialStep;

/// {@macro amplify_authenticator_dial_code_options}
final DialCodeOptions dialCodeOptions;

@override
State<Authenticator> createState() => _AuthenticatorState();

Expand Down Expand Up @@ -454,7 +463,19 @@ class Authenticator extends StatefulWidget {
authenticatorBuilder,
),
)
..add(DiagnosticsProperty<EdgeInsets>('padding', padding));
..add(DiagnosticsProperty<EdgeInsets>('padding', padding))
..add(
DiagnosticsProperty<DialCode>(
'defaultDialCode',
dialCodeOptions.defaultDialCode,
),
)
..add(
DiagnosticsProperty<DialCodeOptions>(
'dialCodeOptions',
dialCodeOptions,
),
);
}
}

Expand All @@ -481,7 +502,10 @@ class _AuthenticatorState extends State<Authenticator> {
preferPrivateSession: widget.preferPrivateSession,
initialStep: widget.initialStep,
)..add(const AuthLoad());
_authenticatorState = AuthenticatorState(_stateMachineBloc);
_authenticatorState = AuthenticatorState(
_stateMachineBloc,
defaultDialCode: widget.dialCodeOptions.defaultDialCode,
);
_subscribeToExceptions();
_subscribeToInfoMessages();
_subscribeToSuccessEvents();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import 'package:amplify_authenticator/src/l10n/button_resolver.dart';
import 'package:amplify_authenticator/src/l10n/country_resolver.dart';
import 'package:amplify_authenticator/src/l10n/input_resolver.dart';
import 'package:amplify_authenticator/src/l10n/message_resolver.dart';
import 'package:amplify_authenticator/src/l10n/title_resolver.dart';
import 'package:amplify_authenticator/amplify_authenticator.dart';
import 'package:flutter/material.dart';

export 'button_resolver.dart';
export 'country_resolver.dart';
export 'dial_code_resolver.dart';
export 'input_resolver.dart';
export 'message_resolver.dart';
export 'title_resolver.dart';
Expand All @@ -25,21 +21,27 @@ class AuthStringResolver {
/// {@macro amplify_authenticator.auth_string_resolver}
const AuthStringResolver({
ButtonResolver? buttons,
CountryResolver? countries,
// ignore: deprecated_member_use_from_same_package
@Deprecated('Use dialCodes instead') CountryResolver? countries,
DialCodeResolver? dialCodes,
InputResolver? inputs,
MessageResolver? messages,
TitleResolver? titles,
}) : buttons = buttons ?? const ButtonResolver(),
countries = countries ?? const CountryResolver(),
dialCodes = dialCodes ?? countries ?? const DialCodeResolver(),
inputs = inputs ?? const InputResolver(),
titles = titles ?? const TitleResolver(),
messages = messages ?? const MessageResolver();

/// The resolver class for shared button Widgets
final ButtonResolver buttons;

/// The resolver class for countries
final CountryResolver countries;
/// The resolver class for area codes
final DialCodeResolver dialCodes;

/// The resolver class for area codes
@Deprecated('Use dialCodes instead')
DialCodeResolver get countries => dialCodes;

/// The resolver class for shared input Widgets
final InputResolver inputs;
Expand All @@ -54,7 +56,7 @@ class AuthStringResolver {
bool operator ==(Object other) =>
other is AuthStringResolver &&
buttons == other.buttons &&
countries == other.countries &&
dialCodes == other.dialCodes &&
inputs == other.inputs &&
titles == other.titles;

Expand Down
Loading

0 comments on commit f81b380

Please sign in to comment.