Skip to content

Commit 3a9a818

Browse files
authored
refactor(auth)!: Remove intermediate request types (aws-amplify#2475)
With the introduction of generics for the multi-plugin architecture, the boxing and unboxing of request parameters has revealed issues in Dart's substandard support of generics. This should alleviate much of the pain at the category-plugin layer by removing a box/unbox sequence.
1 parent 79cfbf9 commit 3a9a818

File tree

49 files changed

+295
-2275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+295
-2275
lines changed

packages/amplify_core/lib/src/category/amplify_auth_category.dart

Lines changed: 81 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,12 @@ class AuthCategory<
288288
required String username,
289289
required String password,
290290
PluginSignUpOptions? options,
291-
}) {
292-
final request = SignUpRequest(
293-
username: username,
294-
password: password,
295-
options: options,
296-
);
297-
return plugin.signUp(request: request);
298-
}
291+
}) =>
292+
plugin.signUp(
293+
username: username,
294+
password: password,
295+
options: options,
296+
);
299297

300298
/// {@template amplify_core.amplify_auth_category.confirm_sign_up}
301299
/// Confirm the current sign up for [username] with the [confirmationCode]
@@ -305,14 +303,12 @@ class AuthCategory<
305303
required String username,
306304
required String confirmationCode,
307305
PluginConfirmSignUpOptions? options,
308-
}) {
309-
final request = ConfirmSignUpRequest(
310-
username: username,
311-
confirmationCode: confirmationCode,
312-
options: options,
313-
);
314-
return plugin.confirmSignUp(request: request);
315-
}
306+
}) =>
307+
plugin.confirmSignUp(
308+
username: username,
309+
confirmationCode: confirmationCode,
310+
options: options,
311+
);
316312

317313
/// {@template amplify_core.amplify_auth_category.resend_sign_up_code}
318314
/// Resends the code that is used to confirm the user's account after sign up
@@ -325,13 +321,11 @@ class AuthCategory<
325321
Future<PluginResendSignUpCodeResult> resendSignUpCode({
326322
required String username,
327323
PluginResendSignUpCodeOptions? options,
328-
}) {
329-
final request = ResendSignUpCodeRequest(
330-
username: username,
331-
options: options,
332-
);
333-
return plugin.resendSignUpCode(request: request);
334-
}
324+
}) =>
325+
plugin.resendSignUpCode(
326+
username: username,
327+
options: options,
328+
);
335329

336330
/// {@template amplify_core.amplify_auth_category.sign_in}
337331
/// Initiate sign in for user with [username] and optional [password].
@@ -343,14 +337,12 @@ class AuthCategory<
343337
required String username,
344338
String? password,
345339
PluginSignInOptions? options,
346-
}) {
347-
final request = SignInRequest(
348-
username: username,
349-
password: password,
350-
options: options,
351-
);
352-
return plugin.signIn(request: request);
353-
}
340+
}) =>
341+
plugin.signIn(
342+
username: username,
343+
password: password,
344+
options: options,
345+
);
354346

355347
/// {@template amplify_core.amplify_auth_category.confirm_sign_in}
356348
/// Confirm the current sign in with the [confirmationValue] provided by the
@@ -359,13 +351,11 @@ class AuthCategory<
359351
Future<PluginConfirmSignInResult> confirmSignIn({
360352
required String confirmationValue,
361353
PluginConfirmSignInOptions? options,
362-
}) {
363-
final request = ConfirmSignInRequest(
364-
confirmationValue: confirmationValue,
365-
options: options,
366-
);
367-
return plugin.confirmSignIn(request: request);
368-
}
354+
}) =>
355+
plugin.confirmSignIn(
356+
confirmationValue: confirmationValue,
357+
options: options,
358+
);
369359

370360
/// {@template amplify_core.amplify_auth_category.sign_out}
371361
/// Sign the user out of the current device.
@@ -375,10 +365,8 @@ class AuthCategory<
375365
/// {@endtemplate}
376366
Future<PluginSignOutResult> signOut({
377367
PluginSignOutOptions? options,
378-
}) {
379-
final request = SignOutRequest(options: options);
380-
return plugin.signOut(request: request);
381-
}
368+
}) =>
369+
plugin.signOut(options: options);
382370

383371
/// {@template amplify_core.amplify_auth_category.update_password}
384372
/// Update the password of the current user.
@@ -391,14 +379,12 @@ class AuthCategory<
391379
required String oldPassword,
392380
required String newPassword,
393381
PluginUpdatePasswordOptions? options,
394-
}) {
395-
final request = UpdatePasswordRequest(
396-
oldPassword: oldPassword,
397-
newPassword: newPassword,
398-
options: options,
399-
);
400-
return plugin.updatePassword(request: request);
401-
}
382+
}) =>
383+
plugin.updatePassword(
384+
oldPassword: oldPassword,
385+
newPassword: newPassword,
386+
options: options,
387+
);
402388

403389
/// {@template amplify_core.amplify_auth_category.reset_password}
404390
/// Initiates a password reset for the user with the given username.
@@ -411,13 +397,11 @@ class AuthCategory<
411397
Future<PluginResetPasswordResult> resetPassword({
412398
required String username,
413399
PluginResetPasswordOptions? options,
414-
}) {
415-
final request = ResetPasswordRequest(
416-
username: username,
417-
options: options,
418-
);
419-
return plugin.resetPassword(request: request);
420-
}
400+
}) =>
401+
plugin.resetPassword(
402+
username: username,
403+
options: options,
404+
);
421405

422406
/// {@template amplify_core.amplify_auth_category.confirm_reset_password}
423407
/// Completes the password reset process given a username, new password,
@@ -433,35 +417,29 @@ class AuthCategory<
433417
required String newPassword,
434418
required String confirmationCode,
435419
PluginConfirmResetPasswordOptions? options,
436-
}) {
437-
final request = ConfirmResetPasswordRequest(
438-
username: username,
439-
newPassword: newPassword,
440-
confirmationCode: confirmationCode,
441-
options: options,
442-
);
443-
return plugin.confirmResetPassword(request: request);
444-
}
420+
}) =>
421+
plugin.confirmResetPassword(
422+
username: username,
423+
newPassword: newPassword,
424+
confirmationCode: confirmationCode,
425+
options: options,
426+
);
445427

446428
/// {@template amplify_core.amplify_auth_category.get_current_user}
447429
/// Retrieve the current active user.
448430
/// {@endtemplate}
449431
Future<PluginAuthUser> getCurrentUser({
450432
PluginAuthUserOptions? options,
451-
}) {
452-
final request = AuthUserRequest(options: options);
453-
return plugin.getCurrentUser(request: request);
454-
}
433+
}) =>
434+
plugin.getCurrentUser(options: options);
455435

456436
/// {@template amplify_core.amplify_auth_category.fetch_user_attributes}
457437
/// Fetch all user attributes associated with the current user.
458438
/// {@endtemplate}
459439
Future<List<PluginAuthUserAttribute>> fetchUserAttributes({
460440
PluginFetchUserAttributeOptions? options,
461-
}) {
462-
final request = FetchUserAttributesRequest(options: options);
463-
return plugin.fetchUserAttributes(request: request);
464-
}
441+
}) =>
442+
plugin.fetchUserAttributes(options: options);
465443

466444
/// {@template amplify_core.amplify_auth_category.fetch_auth_session}
467445
/// Fetch the current auth session.
@@ -472,24 +450,20 @@ class AuthCategory<
472450
/// {@endtemplate}
473451
Future<PluginAuthSession> fetchAuthSession({
474452
PluginAuthSessionOptions? options,
475-
}) {
476-
final request = AuthSessionRequest(options: options);
477-
return plugin.fetchAuthSession(request: request);
478-
}
453+
}) =>
454+
plugin.fetchAuthSession(options: options);
479455

480456
/// {@template amplify_core.amplify_auth_category.sign_in_with_web_ui}
481457
/// Initiate sign in for a web-based flow, e.g. a social provider.
482458
/// {@endtemplate}
483459
Future<PluginSignInWithWebUIResult> signInWithWebUI({
484460
AuthProvider? provider,
485461
PluginSignInWithWebUIOptions? options,
486-
}) {
487-
final request = SignInWithWebUIRequest(
488-
provider: provider,
489-
options: options,
490-
);
491-
return plugin.signInWithWebUI(request: request);
492-
}
462+
}) =>
463+
plugin.signInWithWebUI(
464+
provider: provider,
465+
options: options,
466+
);
493467

494468
/// {@template amplify_core.amplify_auth_category.update_user_attribute}
495469
/// Updates a single user attribute and returns a [UpdateUserAttributeResult].
@@ -500,14 +474,12 @@ class AuthCategory<
500474
required PluginUserAttributeKey userAttributeKey,
501475
required String value,
502476
PluginUpdateUserAttributeOptions? options,
503-
}) {
504-
final request = UpdateUserAttributeRequest(
505-
userAttributeKey: userAttributeKey,
506-
value: value,
507-
options: options,
508-
);
509-
return plugin.updateUserAttribute(request: request);
510-
}
477+
}) =>
478+
plugin.updateUserAttribute(
479+
userAttributeKey: userAttributeKey,
480+
value: value,
481+
options: options,
482+
);
511483

512484
/// {@template amplify_core.amplify_auth_category.update_user_attributes}
513485
/// Updates multiple user attributes and returns a map of
@@ -519,13 +491,11 @@ class AuthCategory<
519491
updateUserAttributes({
520492
required List<PluginAuthUserAttribute> attributes,
521493
PluginUpdateUserAttributesOptions? options,
522-
}) {
523-
final request = UpdateUserAttributesRequest(
524-
attributes: attributes,
525-
options: options,
526-
);
527-
return plugin.updateUserAttributes(request: request);
528-
}
494+
}) =>
495+
plugin.updateUserAttributes(
496+
attributes: attributes,
497+
options: options,
498+
);
529499

530500
/// {@template amplify_core.amplify_auth_category.confirm_user_attribute}
531501
/// Confirms a user attribute update and returns a
@@ -535,14 +505,12 @@ class AuthCategory<
535505
required PluginUserAttributeKey userAttributeKey,
536506
required String confirmationCode,
537507
PluginConfirmUserAttributeOptions? options,
538-
}) {
539-
final request = ConfirmUserAttributeRequest(
540-
userAttributeKey: userAttributeKey,
541-
confirmationCode: confirmationCode,
542-
options: options,
543-
);
544-
return plugin.confirmUserAttribute(request: request);
545-
}
508+
}) =>
509+
plugin.confirmUserAttribute(
510+
userAttributeKey: userAttributeKey,
511+
confirmationCode: confirmationCode,
512+
options: options,
513+
);
546514

547515
/// {@template amplify_core.amplify_auth_category.resend_user_attribute_confirmation_code}
548516
/// Resends a confirmation code for the given attribute and returns a
@@ -554,13 +522,11 @@ class AuthCategory<
554522
resendUserAttributeConfirmationCode({
555523
required PluginUserAttributeKey userAttributeKey,
556524
PluginResendUserAttributeConfirmationCodeOptions? options,
557-
}) {
558-
final request = ResendUserAttributeConfirmationCodeRequest(
559-
userAttributeKey: userAttributeKey,
560-
options: options,
561-
);
562-
return plugin.resendUserAttributeConfirmationCode(request: request);
563-
}
525+
}) =>
526+
plugin.resendUserAttributeConfirmationCode(
527+
userAttributeKey: userAttributeKey,
528+
options: options,
529+
);
564530

565531
/// {@template amplify_core.amplify_auth_category.remember_device}
566532
/// Remembers the current device.

0 commit comments

Comments
 (0)