Skip to content

Commit

Permalink
chore(auth): More TOTP cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Dillon Nys committed Jul 10, 2023
1 parent d06e6b0 commit 403c387
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ final class UserMfaPreference
AWSDebuggable {
/// {@macro amplify_core.auth.user_mfa_preference}
const UserMfaPreference({
Set<MfaType>? enabled,
this.enabled = const {},
this.preferred,
}) : enabled = enabled ?? const {};
});

/// The enabled MFA methods for the user.
final Set<MfaType> enabled;
Expand All @@ -35,7 +35,7 @@ final class UserMfaPreference

@override
Map<String, Object?> toJson() => {
'enabled': enabled.map((typ) => typ.name.toUpperCase()).toList(),
'enabled': enabled.map((type) => type.name.toUpperCase()).toList(),
'preferred': preferred?.name.toUpperCase(),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void main() {
because: 'MFA is optional',
).equals(AuthSignInStep.done);

await setUpTotp();
await setUpTotp(deviceName: friendlyDeviceName);

await cognitoPlugin.updateMfaPreference(
totp: MfaPreference.preferred,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Future<int> get _nextTotpTime async {
}

String? _sharedSecret;
Future<void> setUpTotp() async {
Future<void> setUpTotp({String? deviceName = friendlyDeviceName}) async {
if (_sharedSecret != null) {
throw StateError('Cannot reconfigure TOTP');
}
Expand All @@ -52,9 +52,9 @@ Future<void> setUpTotp() async {
_sharedSecret = totpSetupResult.sharedSecret;
await Amplify.Auth.verifyTotpSetup(
await generateTotpCode(),
options: const VerifyTotpSetupOptions(
options: VerifyTotpSetupOptions(
pluginOptions: CognitoVerifyTotpSetupPluginOptions(
friendlyDeviceName: friendlyDeviceName,
friendlyDeviceName: deviceName,
),
),
);
Expand Down

0 comments on commit 403c387

Please sign in to comment.