From ed1440e61d45a00758b8177c164e57e4d8ad1378 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Tue, 11 Jun 2024 15:57:53 -0700 Subject: [PATCH 01/27] chore: update mfa page to change flutter snippets from js to dart --- .../multi-factor-authentication/index.mdx | 241 +++++++++++++++++- 1 file changed, 228 insertions(+), 13 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/auth/concepts/multi-factor-authentication/index.mdx b/src/pages/[platform]/build-a-backend/auth/concepts/multi-factor-authentication/index.mdx index 810bc7c43f6..5dd66d1b4ab 100644 --- a/src/pages/[platform]/build-a-backend/auth/concepts/multi-factor-authentication/index.mdx +++ b/src/pages/[platform]/build-a-backend/auth/concepts/multi-factor-authentication/index.mdx @@ -117,7 +117,7 @@ Once you have setup SMS as your second layer of authentication with MFA as shown You will need to pass `phone_number` as a user attribute to enable SMS MFA for your users during sign-up. However, if the primary sign-in mechanism for your Cognito resource is `phone_number` (without enabling `username`), then you do not need to pass it as an attribute. - + ```ts import { signUp } from 'aws-amplify/auth'; @@ -133,6 +133,28 @@ await signUp({ }); ``` + + +```dart +Future signUpWithPhoneVerification( + String username, + String password, +) async { + await Amplify.Auth.signUp( + username: username, + password: password, + options: SignUpOptions( + userAttributes: { + // ... if required + AuthUserAttributeKey.email: 'test@example.com', + AuthUserAttributeKey.phoneNumber: '+18885551234', + }, + ), + ); +} +``` + + ```swift func signUp(username: String, password: String, email: String, phonenumber: String) async { @@ -161,7 +183,7 @@ func signUp(username: String, password: String, email: String, phonenumber: Stri By default, you have to verify a user account after they sign up using the `confirmSignUp` API, which will send a one-time password to the user's phone number or email, depending on your Amazon Cognito configuration. - + ```ts import { confirmSignUp } from 'aws-amplify/auth'; @@ -172,6 +194,20 @@ await confirmSignUp({ ``` + +```dart +Future confirmSignUpPhoneVerification( + String username, + String otpCode, +) async { + await Amplify.Auth.confirmSignUp( + username: username, + confirmationCode: otpCode, + ); +} +``` + + ```swift @@ -197,7 +233,7 @@ After a user signs in, if they have MFA enabled for their account, a challenge w If MFA is **ON** or enabled for the user, you must call `confirmSignIn` with the OTP sent to their phone. - + ```ts import { confirmSignIn } from 'aws-amplify/auth'; @@ -207,6 +243,15 @@ await confirmSignIn({ ``` + +```dart +Future confirmSignInPhoneVerification(String otpCode) async { + await Amplify.Auth.confirmSignIn( + confirmationValue: otpCode, + ); +} +``` + ```swift @@ -226,7 +271,7 @@ func confirmSignIn() async { After a user has been signed in, call `updateMFAPreference` to record the MFA type as enabled for the user and optionally set it as preferred so that subsequent logins default to using this MFA type. - + ```ts import { updateMFAPreference } from 'aws-amplify/auth'; @@ -234,6 +279,17 @@ await updateMFAPreference({ sms: 'PREFERRED' }); ``` + +```dart +Future updateMfaPreferences() async { + final cognitoPlugin = Amplify.Auth.getPlugin(AmplifyAuthCognito.pluginKey); + + await cognitoPlugin.updateMfaPreference( + sms: MfaPreference.enabled, // or .preferred + ); +} +``` + ```swift @@ -287,7 +343,7 @@ You can use Time-based One-Time Password (TOTP) for multi-factor authentication ### Set up TOTP for a user - + After you initiate a user sign in with the `signIn` API where a user is required to set up TOTP as an MFA method, the API call will return `CONTINUE_SIGN_IN_WITH_TOTP_SETUP` as a challenge and next step to handle in your app. You will get that challenge if the following conditions are met: @@ -321,6 +377,43 @@ switch (nextStep.signInStep) { ``` + +After you initiate a user sign in with the `signIn` API where a user is required to set up TOTP as an MFA method, the API call will return `CONTINUE_SIGN_IN_WITH_TOTP_SETUP` as a challenge and next step to handle in your app. You will get that challenge if the following conditions are met: + +- MFA is marked as **Required** in your user pool. +- TOTP is enabled in your user pool. +- User does not have TOTP MFA set up already. + +The `CONTINUE_SIGN_IN_WITH_TOTP_SETUP` step signifies that the user must set up TOTP before they can sign in. The step returns an associated value of type `TOTPSetupDetails` which must be used to configure an authenticator app like Microsoft Authenticator or Google Authenticator. `TOTPSetupDetails` provides a helper method called `getSetupURI` which generates a URI that can be used, for example, in a button to open the user's installed authenticator app. For more advanced use cases, `TOTPSetupDetails` also contains a `sharedSecret` which can be used to either generate a QR code or be manually entered into an authenticator app. + +Once the authenticator app is set up, the user can generate a TOTP code and provide it to the library to complete the sign in process. + +```dart +Future signInUser(String username, String password) async { + try { + final result = await Amplify.Auth.signIn( + username: username, + password: password, + ); + return _handleSignInResult(result); + } on AuthException catch (e) { + safePrint('Error signing in: ${e.message}'); + } +} + +Future _handleSignInResult(SignInResult result) async { + switch (result.nextStep.signInStep) { + // ··· + case AuthSignInStep.continueSignInWithTotpSetup: + final totpSetupDetails = result.nextStep.totpSetupDetails!; + final setupUri = totpSetupDetails.getSetupUri(appName: 'MyApp'); + safePrint('Open URI to complete setup: $setupUri'); + // ··· + } +} +``` + + After you initiate a user sign in with the `signIn` API where a user is required to set up TOTP as an MFA method, the API call will return `continueSignInWithTOTPSetup` as a challenge and next step to handle in your app. You will get that challenge if the following conditions are met: @@ -365,7 +458,7 @@ func signIn(username: String, password: String) async { The TOTP code can be obtained from the user via a text field or any other means. Once the user provides the TOTP code, call `confirmSignIn` with the TOTP code as the `challengeResponse` parameter. - + ```ts import { confirmSignIn } from 'aws-amplify/auth'; @@ -375,6 +468,21 @@ await confirmSignIn({ ``` + +```dart +Future confirmTotpUser(String totpCode) async { + try { + final result = await Amplify.Auth.confirmSignIn( + confirmationValue: totpCode, + ); + return _handleSignInResult(result); + } on AuthException catch (e) { + safePrint('Error confirming TOTP code: ${e.message}'); + } +} +``` + + ```swift func confirmSignIn() async { @@ -393,7 +501,7 @@ func confirmSignIn() async { After a user has been signed in, call `updateMFAPreference` to record the MFA type as enabled for the user and optionally set it as preferred so that subsequent logins default to using this MFA type. - + ```ts import { updateMFAPreference } from 'aws-amplify/auth'; @@ -401,6 +509,18 @@ await updateMFAPreference({ totp: 'PREFERRED' }); ``` + +```dart +Future updateMfaPreferences() async { + final cognitoPlugin = Amplify.Auth.getPlugin(AmplifyAuthCognito.pluginKey); + + await cognitoPlugin.updateMfaPreference( + totp: MfaPreference.preferred, + ); +} +``` + + ```swift func updateMFAPreferences() async throws { @@ -428,7 +548,7 @@ Invoke the `setUpTOTP` API to generate a `TOTPSetupDetails` object which should that contains the `sharedSecret` which will be used to either to generate a QR code or can be manually entered into an Authenticator app. - + ```ts import { setUpTOTP } from 'aws-amplify/auth'; @@ -439,6 +559,20 @@ const setupUri = totpSetupDetails.getSetupUri(appName); ``` + +```dart +Future setUpTotp() async { + try { + final totpSetupDetails = await Amplify.Auth.setUpTotp(); + final setupUri = totpSetupDetails.getSetupUri(appName: 'MyApp'); + safePrint('Open URI to complete setup: $setupUri'); + } on AuthException catch (e) { + safePrint('An error occurred setting up TOTP: $e'); + } +} +``` + + ```swift func setUpTOTP() async { @@ -464,7 +598,7 @@ func setUpTOTP() async { Once the Authenticator app is set up, the user must generate a TOTP code and provide it to the library. Pass the code to `verifyTOTPSetup` to complete the TOTP setup process. - + ```ts import { verifyTOTPSetup } from 'aws-amplify/auth'; @@ -472,6 +606,18 @@ await verifyTOTPSetup({ code: "123456" }); ``` + +```dart +Future verifyTotpSetup(String totpCode) async { + try { + await Amplify.Auth.verifyTotpSetup(totpCode); + } on AuthException catch (e) { + safePrint('An error occurred verifying TOTP: $e'); + } +} +``` + + ```swift func verifyTOTPSetup(totpCodeFromAuthenticatorApp: String) async { @@ -487,7 +633,7 @@ func verifyTOTPSetup(totpCodeFromAuthenticatorApp: String) async { After TOTP setup is complete, call `updateMFAPreference` to record the MFA type as enabled for the user and optionally set it as preferred so that subsequent logins default to using this MFA type. - + ```ts import { updateMFAPreference } from 'aws-amplify/auth'; @@ -495,6 +641,19 @@ await updateMFAPreference({ sms: 'ENABLED', totp: 'PREFERRED' }); ``` + +```dart +Future updateMfaPreferences() async { + final cognitoPlugin = Amplify.Auth.getPlugin(AmplifyAuthCognito.pluginKey); + + await cognitoPlugin.updateMfaPreference( + sms: MfaPreference.enabled, + totp: MfaPreference.preferred, + ); +} +``` + + ```swift func updateMFAPreferences() async throws { @@ -527,7 +686,7 @@ In a scenario where MFA is marked as "Required" in the Cognito User Pool and ano Invoke the following API to get the current MFA preference and enabled MFA types, if any, for the current user. - + ```ts import { fetchMFAPreference } from 'aws-amplify/auth'; @@ -535,6 +694,18 @@ const { enabled, preferred } = await fetchMFAPreference(); ``` + +```dart +Future getCurrentMfaPreference() async { + final cognitoPlugin = Amplify.Auth.getPlugin(AmplifyAuthCognito.pluginKey); + + final currentPreference = await cognitoPlugin.fetchMfaPreference(); + safePrint('Enabled MFA types for user: ${currentPreference.enabled}'); + safePrint('Preferred MFA type for user: ${currentPreference.preferred}'); +} +``` + + ```swift func getMFAPreferences() async throws { @@ -559,7 +730,7 @@ Only one MFA method can be marked as preferred at a time. If the user has multip - + ```ts import { updateMFAPreference } from 'aws-amplify/auth'; @@ -567,6 +738,19 @@ await updateMFAPreference({ sms: 'ENABLED', totp: 'PREFERRED' }); ``` + +```dart +Future updateMfaPreferences() async { + final cognitoPlugin = Amplify.Auth.getPlugin(AmplifyAuthCognito.pluginKey); + + await cognitoPlugin.updateMfaPreference( + sms: MfaPreference.enabled, + totp: MfaPreference.preferred, + ); +} +``` + + ```swift func updateMFAPreferences() async throws { @@ -583,7 +767,7 @@ func updateMFAPreferences() async throws { ``` - + If multiple MFA methods are enabled for the user, the `signIn` API will return `CONTINUE_SIGN_IN_WITH_MFA_SELECTION` as the next step in the auth flow. During this scenario, the user should be prompted to select the MFA method they want to use to sign in and their preference should be passed to `confirmSignIn`. ```ts @@ -625,6 +809,37 @@ async function handleMFASelection(mfaType: 'SMS' | 'TOTP') { ``` + +If multiple MFA methods are enabled for the user, the `signIn` API will return `continueSignInWithMFASelection` as the next step in the auth flow. During this scenario, the user should be prompted to select the MFA method they want to use to sign in and their preference should be passed to `confirmSignIn`. +```dart +Future _handleSignInResult(SignInResult result) async { + switch (result.nextStep.signInStep) { + // ··· + case AuthSignInStep.continueSignInWithMfaSelection: + final allowedMfaTypes = result.nextStep.allowedMfaTypes!; + final selection = await _promptUserPreference(allowedMfaTypes); + return _handleMfaSelection(selection); + // ··· + } +} + +Future _promptUserPreference(Set allowedTypes) async { + // ··· +} + +Future _handleMfaSelection(MfaType selection) async { + try { + final result = await Amplify.Auth.confirmSignIn( + confirmationValue: selection.confirmationValue, + ); + return _handleSignInResult(result); + } on AuthException catch (e) { + safePrint('Error resending code: ${e.message}'); + } +} +``` + + If multiple MFA methods are enabled for the user, the `signIn` API will return `continueSignInWithMFASelection` as the next step in the auth flow. During this scenario, the user should be prompted to select the MFA method they want to use to sign in and their preference should be passed to `confirmSignIn`. From 0dd901e4d701f55fe5fb20bb327eb8e85c551600 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Wed, 12 Jun 2024 10:50:40 -0700 Subject: [PATCH 02/27] chore: combine duplicate sms mfa text from swift and flutter --- .../multi-factor-authentication/index.mdx | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/auth/concepts/multi-factor-authentication/index.mdx b/src/pages/[platform]/build-a-backend/auth/concepts/multi-factor-authentication/index.mdx index 5dd66d1b4ab..fb326a52f93 100644 --- a/src/pages/[platform]/build-a-backend/auth/concepts/multi-factor-authentication/index.mdx +++ b/src/pages/[platform]/build-a-backend/auth/concepts/multi-factor-authentication/index.mdx @@ -377,16 +377,19 @@ switch (nextStep.signInStep) { ``` - -After you initiate a user sign in with the `signIn` API where a user is required to set up TOTP as an MFA method, the API call will return `CONTINUE_SIGN_IN_WITH_TOTP_SETUP` as a challenge and next step to handle in your app. You will get that challenge if the following conditions are met: + +After you initiate a user sign in with the `signIn` API where a user is required to set up TOTP as an MFA method, the API call will return `continueSignInWithTOTPSetup` as a challenge and next step to handle in your app. You will get that challenge if the following conditions are met: - MFA is marked as **Required** in your user pool. - TOTP is enabled in your user pool. - User does not have TOTP MFA set up already. -The `CONTINUE_SIGN_IN_WITH_TOTP_SETUP` step signifies that the user must set up TOTP before they can sign in. The step returns an associated value of type `TOTPSetupDetails` which must be used to configure an authenticator app like Microsoft Authenticator or Google Authenticator. `TOTPSetupDetails` provides a helper method called `getSetupURI` which generates a URI that can be used, for example, in a button to open the user's installed authenticator app. For more advanced use cases, `TOTPSetupDetails` also contains a `sharedSecret` which can be used to either generate a QR code or be manually entered into an authenticator app. +The `continueSignInWithTOTPSetup` step signifies that the user must set up TOTP before they can sign in. The step returns an associated value of type `TOTPSetupDetails` which must be used to configure an authenticator app like Microsoft Authenticator or Google Authenticator. `TOTPSetupDetails` provides a helper method called `getSetupURI` which generates a URI that can be used, for example, in a button to open the user's installed authenticator app. For more advanced use cases, `TOTPSetupDetails` also contains a `sharedSecret` which can be used to either generate a QR code or be manually entered into an authenticator app. Once the authenticator app is set up, the user can generate a TOTP code and provide it to the library to complete the sign in process. + + + ```dart Future signInUser(String username, String password) async { @@ -416,15 +419,6 @@ Future _handleSignInResult(SignInResult result) async { -After you initiate a user sign in with the `signIn` API where a user is required to set up TOTP as an MFA method, the API call will return `continueSignInWithTOTPSetup` as a challenge and next step to handle in your app. You will get that challenge if the following conditions are met: - -- MFA is marked as **Required** in your user pool. -- TOTP is enabled in your user pool. -- User does not have TOTP MFA set up already. - -The `continueSignInWithTOTPSetup` step signifies that the user must set up TOTP before they can sign in. The step returns an associated value of type `TOTPSetupDetails` which must be used to configure an authenticator app like Microsoft Authenticator or Google Authenticator. `TOTPSetupDetails` provides a helper method called `getSetupURI` which generates a URI that can be used, for example, in a button to open the user's installed authenticator app. For more advanced use cases, `TOTPSetupDetails` also contains a `sharedSecret` which can be used to either generate a QR code or be manually entered into an authenticator app. - -Once the authenticator app is set up, the user can generate a TOTP code and provide it to the library to complete the sign in process. ```swift func signIn(username: String, password: String) async { do { @@ -809,8 +803,12 @@ async function handleMFASelection(mfaType: 'SMS' | 'TOTP') { ``` - + If multiple MFA methods are enabled for the user, the `signIn` API will return `continueSignInWithMFASelection` as the next step in the auth flow. During this scenario, the user should be prompted to select the MFA method they want to use to sign in and their preference should be passed to `confirmSignIn`. + + + + ```dart Future _handleSignInResult(SignInResult result) async { switch (result.nextStep.signInStep) { @@ -842,8 +840,6 @@ Future _handleMfaSelection(MfaType selection) async { -If multiple MFA methods are enabled for the user, the `signIn` API will return `continueSignInWithMFASelection` as the next step in the auth flow. During this scenario, the user should be prompted to select the MFA method they want to use to sign in and their preference should be passed to `confirmSignIn`. - ```swift func signIn(username: String, password: String) async { do { From cbbfaa999b8fc544fc7625202cf68f97b92c37a0 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Wed, 12 Jun 2024 11:30:19 -0700 Subject: [PATCH 03/27] chore: added flutter snippet for global sign out --- .../auth/concepts/tokens-and-credentials/index.mdx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/auth/concepts/tokens-and-credentials/index.mdx b/src/pages/[platform]/build-a-backend/auth/concepts/tokens-and-credentials/index.mdx index ae211e998d3..f2b924c3f04 100644 --- a/src/pages/[platform]/build-a-backend/auth/concepts/tokens-and-credentials/index.mdx +++ b/src/pages/[platform]/build-a-backend/auth/concepts/tokens-and-credentials/index.mdx @@ -253,10 +253,14 @@ class InMemoryStorage implements SecureStorageInterface { ## Token Revocation - + Token revocation is enabled automatically in Amplify Auth. To revoke tokens you can set up global sign-out with `signOut({ global: true })` to globally sign out your user from all of their devices. + +Token revocation is enabled automatically in Amplify Auth. To revoke tokens you can invoke `await Amplify.Auth.signOut(options: const signOutOptions(globalSignOut: true))` to globally sign out your user from all of their devices. + + Token revocation is enabled automatically in Amplify Auth. To revoke tokens you can invoke `await Amplify.Auth.signOut(options: .init(globalSignOut: true))` to globally sign out your user from all of their devices. From a2e94d37cf4a8384219312ab1bdab4cc16cbe7b8 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Wed, 12 Jun 2024 13:28:52 -0700 Subject: [PATCH 04/27] chore: fix sign up next steps from enums to flutter --- .../auth/connect-your-frontend/sign-up/index.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/auth/connect-your-frontend/sign-up/index.mdx b/src/pages/[platform]/build-a-backend/auth/connect-your-frontend/sign-up/index.mdx index 45056d61d69..794d6b3ddf3 100644 --- a/src/pages/[platform]/build-a-backend/auth/connect-your-frontend/sign-up/index.mdx +++ b/src/pages/[platform]/build-a-backend/auth/connect-your-frontend/sign-up/index.mdx @@ -285,13 +285,13 @@ func signUp(username: String, password: String, email: String, phonenumber: Stri The `signUp` API response will include a `nextStep` property, which can be used to determine if further action is required. It may return the following next steps: - + - `CONFIRM_SIGN_UP` - The sign up needs to be confirmed by collecting a code from the user and calling `confirmSignUp`. - `DONE` - The sign up process has been fully completed. - `COMPLETE_AUTO_SIGN_IN` - The sign up process needs to complete by invoking the `autoSignIn` API. - + - `confirmUser` - The sign up needs to be confirmed by collecting a code from the user and calling `confirmSignUp` API. - `done` - The sign up process has been fully completed. From cc41aaed625c5a045a231140d9e29e6829962994 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Wed, 12 Jun 2024 14:00:16 -0700 Subject: [PATCH 05/27] chore: fix outputs to amplify config in _configureAmplify method --- src/pages/[platform]/build-a-backend/auth/set-up-auth/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/auth/set-up-auth/index.mdx b/src/pages/[platform]/build-a-backend/auth/set-up-auth/index.mdx index 6b3ba176d93..9df4b228568 100644 --- a/src/pages/[platform]/build-a-backend/auth/set-up-auth/index.mdx +++ b/src/pages/[platform]/build-a-backend/auth/set-up-auth/index.mdx @@ -410,7 +410,7 @@ Future main() async { Future _configureAmplify() async { try { await Amplify.addPlugin(AmplifyAuthCognito()); - await Amplify.configure(outputs); + await Amplify.configure(amplifyconfig); safePrint('Successfully configured'); } on Exception catch (e) { safePrint('Error configuring Amplify: $e'); From 41c906baf37072721abed9842101e4f49144951e Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Wed, 12 Jun 2024 14:00:40 -0700 Subject: [PATCH 06/27] chore: fix flutter sign in next steps from using enums --- .../auth/connect-your-frontend/sign-in/index.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/auth/connect-your-frontend/sign-in/index.mdx b/src/pages/[platform]/build-a-backend/auth/connect-your-frontend/sign-in/index.mdx index 34abae81352..5087c231df3 100644 --- a/src/pages/[platform]/build-a-backend/auth/connect-your-frontend/sign-in/index.mdx +++ b/src/pages/[platform]/build-a-backend/auth/connect-your-frontend/sign-in/index.mdx @@ -253,7 +253,7 @@ func signIn(username: String, password: String) -> AnyCancellable { The `signIn` API response will include a `nextStep` property, which can be used to determine if further action is required. It may return the following next steps: - + - `CONFIRM_SIGN_IN_WITH_NEW_PASSWORD_REQUIRED` - The user was created with a temporary password and must set a new one. Complete the process with `confirmSignIn`. - `CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE` - The sign-in must be confirmed with a custom challenge response. Complete the process with `confirmSignIn`. - `CONFIRM_SIGN_IN_WITH_TOTP_CODE` - The sign-in must be confirmed with a TOTP code from the user. Complete the process with `confirmSignIn`. @@ -265,7 +265,7 @@ The `signIn` API response will include a `nextStep` property, which can be used - `DONE` - The sign in process has been completed. - + - `confirmSignInWithNewPassword` - The user was created with a temporary password and must set a new one. Complete the process with `confirmSignIn`. - `confirmSignInWithCustomChallenge` - The sign-in must be confirmed with a custom challenge response. Complete the process with `confirmSignIn`. - `confirmSignInWithTOTPCode` - The sign-in must be confirmed with a TOTP code from the user. Complete the process with `confirmSignIn`. From 0f25283b5ec3ccf99d85e5a34c204e96b9c3f600 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Wed, 12 Jun 2024 14:40:39 -0700 Subject: [PATCH 07/27] chore: add APIPluginOptions --- .../[platform]/build-a-backend/data/set-up-data/index.mdx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/data/set-up-data/index.mdx b/src/pages/[platform]/build-a-backend/data/set-up-data/index.mdx index 55c396b77fb..69693dd36f0 100644 --- a/src/pages/[platform]/build-a-backend/data/set-up-data/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/set-up-data/index.mdx @@ -339,7 +339,11 @@ import 'models/ModelProvider.dart'; Future main() async { // highlight-start try { - final api = AmplifyAPI(modelProvider: ModelProvider.instance); + final api = AmplifyAPI( + options: APIPluginOptions( + modelRegistration: ModelProvider() + ) + ); await Amplify.addPlugins([api]); await Amplify.configure(outputs); From 19c6d404937d3c4adccf6389a598eaa2e6a88e33 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Wed, 12 Jun 2024 15:17:30 -0700 Subject: [PATCH 08/27] chore: add view analytics console --- .../add-aws-services/analytics/set-up-analytics/index.mdx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/analytics/set-up-analytics/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/analytics/set-up-analytics/index.mdx index 6c4d61a2d6f..28cf14b6e90 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/analytics/set-up-analytics/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/analytics/set-up-analytics/index.mdx @@ -520,6 +520,14 @@ public class MyAmplifyApp extends Application { +### View Analytics Console + +If you have not saved the link from before, you can still reach it from the terminal. Run the following command for opening the console. + +```sh +amplify console analytics +``` + Next Steps: Congratulations! Now that you have Analytics' backend provisioned and Analytics library installed. Check out the following links to see Amplify Analytics use cases: From 76c2f55d279dc565a0f0d59363c049f40fab26cd Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Wed, 12 Jun 2024 15:29:54 -0700 Subject: [PATCH 09/27] chore: add user agent back into json in analytics record event page --- .../add-aws-services/analytics/record-events/index.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/analytics/record-events/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/analytics/record-events/index.mdx index 3c7017249f0..ab3ab6d7acc 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/analytics/record-events/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/analytics/record-events/index.mdx @@ -309,6 +309,7 @@ Events have default configuration to flush out to the network every 30 seconds. ```json { + "UserAgent": "aws-amplify-cli/2.0", "Version": "1.0", "analytics": { "plugins": { From 162d8aa42d46ee7e5cdefca48415730470fece8d Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Thu, 13 Jun 2024 09:58:04 -0700 Subject: [PATCH 10/27] chore: fix automated reconnection snippet to use APIPluginOptions --- .../build-a-backend/data/subscribe-data/index.mdx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/subscribe-data/index.mdx b/src/pages/[platform]/build-a-backend/data/subscribe-data/index.mdx index 878624edb7d..b723dda2678 100644 --- a/src/pages/[platform]/build-a-backend/data/subscribe-data/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/subscribe-data/index.mdx @@ -554,11 +554,13 @@ Likewise, when disconnected from the internet unexpectedly, the subscription wil ```dart Future _configureAmplify() async { final apiPlugin = AmplifyAPI( - modelProvider: ModelProvider.instance, - // Optional config - subscriptionOptions: const GraphQLSubscriptionOptions( - retryOptions: RetryOptions(maxAttempts: 10), - ), + options: APIPluginOptions( + modelProvider: ModelProvider.instance, + // Optional config + subscriptionOptions: const GraphQLSubscriptionOptions( + retryOptions: RetryOptions(maxAttempts: 10), + ), + ) ); await Amplify.addPlugin(apiPlugin); From 4348e5d2a4d88526f12b8a49c946b4403f270179 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Thu, 13 Jun 2024 11:16:35 -0700 Subject: [PATCH 11/27] chore: remove next.js related page and snippets from data --- .../build-a-backend/data/connect-from-server-runtime/index.mdx | 1 - .../connect-from-server-runtime/nextjs-server-runtime/index.mdx | 1 - 2 files changed, 2 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/connect-from-server-runtime/index.mdx b/src/pages/[platform]/build-a-backend/data/connect-from-server-runtime/index.mdx index 5d855652f22..4d41899c858 100644 --- a/src/pages/[platform]/build-a-backend/data/connect-from-server-runtime/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/connect-from-server-runtime/index.mdx @@ -9,7 +9,6 @@ export const meta = { platforms: [ 'android', 'angular', - 'flutter', 'javascript', 'nextjs', 'react', diff --git a/src/pages/[platform]/build-a-backend/data/connect-from-server-runtime/nextjs-server-runtime/index.mdx b/src/pages/[platform]/build-a-backend/data/connect-from-server-runtime/nextjs-server-runtime/index.mdx index 8eefe009027..865e3835d7e 100644 --- a/src/pages/[platform]/build-a-backend/data/connect-from-server-runtime/nextjs-server-runtime/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/connect-from-server-runtime/nextjs-server-runtime/index.mdx @@ -7,7 +7,6 @@ export const meta = { platforms: [ 'android', 'angular', - 'flutter', 'javascript', 'nextjs', 'react', From 113c5d10f3bdbed3389dcf93eef24a45c40c21f8 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:16:47 -0700 Subject: [PATCH 12/27] chore: add flutter snippet to customize auth rules public data access --- .../public-data-access/index.mdx | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/public-data-access/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/public-data-access/index.mdx index cd07fbed6e9..f0e596d92c5 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/public-data-access/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/public-data-access/index.mdx @@ -45,7 +45,7 @@ const schema = a.schema({ }); ``` - + In your application, you can perform CRUD operations against the model using `client.models.` by specifying the `apiKey` auth mode. @@ -69,6 +69,31 @@ const { errors, data: newTodo } = await client.models.Todo.create( + +In your application, you can perform CRUD operations against the model by specifying the `apiKey` auth mode. + +```dart +try { + final todo = Todo(content: 'My new todo'); + final request = ModelMutations.create(todo); + final createdTodo = await Amplify.DataStore.save( + request: request, + authorizationMode: APIAuthorizationType.apiKey + ).response; + + if (createdTodo == null) { + safePrint('errors: ${response.errors}'); + return; + } + safePrint('Mutation result: ${createdTodo.name}'); + +} on APIException catch (e) { + safePrint('Failed to create todo', e); +} +``` + + + In your application, you can perform CRUD operations against the model by specifying the `apiKey` auth mode. @@ -149,6 +174,31 @@ const { errors, data: newTodo } = await client.models.Todo.create( + +In your application, you can perform CRUD operations against the model with the `awsIAM` auth mode. + +```dart +try { + final todo = Todo(content: 'My new todo'); + final request = ModelMutations.create(todo); + final createdTodo = await Amplify.DataStore.save( + request: request, + authorizationMode: APIAuthorizationType.iam + ).response; + + if (createdTodo == null) { + safePrint('errors: ${response.errors}'); + return; + } + safePrint('Mutation result: ${createdTodo.name}'); + +} on APIException catch (e) { + safePrint('Failed to create todo', e); +} +``` + + + In your application, you can perform CRUD operations against the model with the `awsIAM` auth mode. From eb12ead76222b5483d215b55a1da2d6287921c64 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:21:25 -0700 Subject: [PATCH 13/27] chore: remove duplicate lines of code between swift and --- .../data/customize-authz/public-data-access/index.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/public-data-access/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/public-data-access/index.mdx index f0e596d92c5..8fbed241c30 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/public-data-access/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/public-data-access/index.mdx @@ -69,8 +69,11 @@ const { errors, data: newTodo } = await client.models.Todo.create( - + In your application, you can perform CRUD operations against the model by specifying the `apiKey` auth mode. + + + ```dart try { @@ -96,8 +99,6 @@ try { -In your application, you can perform CRUD operations against the model by specifying the `apiKey` auth mode. - ```swift do { let todo = Todo(content: "My new todo") @@ -175,7 +176,7 @@ const { errors, data: newTodo } = await client.models.Todo.create( -In your application, you can perform CRUD operations against the model with the `awsIAM` auth mode. +In your application, you can perform CRUD operations against the model with the `iam` auth mode. ```dart try { @@ -200,7 +201,6 @@ try { - In your application, you can perform CRUD operations against the model with the `awsIAM` auth mode. ```swift From 377e72f83975c3b0a23d16d5352911e98445206f Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:27:21 -0700 Subject: [PATCH 14/27] chore: replace js code snippet with flutter for per user data access --- .../per-user-per-owner-data-access/index.mdx | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/per-user-per-owner-data-access/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/per-user-per-owner-data-access/index.mdx index f2305085277..80503ac1d21 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/per-user-per-owner-data-access/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/per-user-per-owner-data-access/index.mdx @@ -59,7 +59,7 @@ const schema = a.schema({ }); ``` - + In your application, you can perform CRUD operations against the model using `client.models.` with the `userPool` auth mode. @@ -82,6 +82,30 @@ const { errors, data: newTodo } = await client.models.Todo.create( ``` + +In your application, you can perform CRUD operations against the model with the `userPools` auth mode. + +```dart +try { + final todo = Todo(content: 'My new todo'); + final request = ModelMutations.create(todo); + final createdTodo = await Amplify.DataStore.save( + request: request, + authorizationMode: APIAuthorizationType.userPools + ).response; + + if (createdTodo == null) { + safePrint('errors: ${response.errors}'); + return; + } + safePrint('Mutation result: ${createdTodo.name}'); + +} on APIException catch (e) { + safePrint('Failed to create todo', e); +} +``` + + In your application, you can perform CRUD operations against the model with the `amazonCognitoUserPools` auth mode. From 418998a25dc7c26bbd36c95f82c36ce96a9c8dc8 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:42:49 -0700 Subject: [PATCH 15/27] chore: replace js snippets with flutter for multi-user data access --- .../multi-user-data-access/index.mdx | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/multi-user-data-access/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/multi-user-data-access/index.mdx index 9d3d1b8b416..96c67abe712 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/multi-user-data-access/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/multi-user-data-access/index.mdx @@ -47,7 +47,7 @@ const schema = a.schema({ }); ``` - + In your application, you can perform CRUD operations against the model using `client.models.` with the `userPool` auth mode. @@ -88,6 +88,43 @@ await client.models.Todo.update( + +In your application, you can perform CRUD operations against the model with the `userPools` auth mode. + +```dart +try { + final todo = Todo(content: 'My new todo'); + final request = ModelMutations.create(todo); + final createdTodo = await Amplify.DataStore.save( + request: request, + authorizationMode: APIAuthorizationType.userPools + ).response; + + if (createdTodo == null) { + safePrint('errors: ${response.errors}'); + return; + } + safePrint('Mutation result: ${createdTodo.name}'); + +} on APIException catch (e) { + safePrint('Failed to create todo', e); +} +``` + +Add another user as an owner + +```dart +try { + createdTodo.owners?.append(otherUserId); + let updatedTodo = await Amplify.API.mutate(request: .update( + createdTodo, + authMode: .userPools)).get() +} catch { + print("Failed to update todo", error) +} +``` + + In your application, you can perform CRUD operations against the model with the `amazonCognitoUserPools` auth mode. From 918b67fcc0011ef92edc6bfbbbe70078dce28ff2 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:51:38 -0700 Subject: [PATCH 16/27] chore: replaced js snippets in signed-in user data access with flutter snippets --- .../signed-in-user-data-access/index.mdx | 53 ++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/signed-in-user-data-access/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/signed-in-user-data-access/index.mdx index 55715c8152a..7c6c9662017 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/signed-in-user-data-access/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/signed-in-user-data-access/index.mdx @@ -51,7 +51,7 @@ const schema = a.schema({ }); ``` - + In your application, you can perform CRUD operations against the model using `client.models.` with the `userPool` auth mode. @@ -74,6 +74,30 @@ const { errors, data: newTodo } = await client.models.Todo.create( ``` + +In your application, you can perform CRUD operations against the model with the `userPools` auth mode. + +```dart +try { + final todo = Todo(content: 'My new todo'); + final request = ModelMutations.create(todo); + final createdTodo = await Amplify.DataStore.save( + request: request, + authorizationMode: APIAuthorizationType.userPools + ).response; + + if (createdTodo == null) { + safePrint('errors: ${response.errors}'); + return; + } + safePrint('Mutation result: ${createdTodo.name}'); + +} on APIException catch (e) { + safePrint('Failed to create todo', e); +} +``` + + In your application, you can perform CRUD operations against the model with the `amazonCognitoUserPools` auth mode. @@ -106,7 +130,7 @@ const schema = a.schema({ }); ``` - + In your application, you can perform CRUD operations against the model using `client.models.` with the `iam` auth mode. @@ -133,6 +157,31 @@ const { errors, data: newTodo } = await client.models.Todo.create( ``` + +In your application, you can perform CRUD operations against the model with the `iam` auth mode. + +```dart +try { + final todo = Todo(content: 'My new todo'); + final request = ModelMutations.create(todo); + final createdTodo = await Amplify.DataStore.save( + request: request, + authorizationMode: APIAuthorizationType.iam + ).response; + + if (createdTodo == null) { + safePrint('errors: ${response.errors}'); + return; + } + safePrint('Mutation result: ${createdTodo.name}'); + +} on APIException catch (e) { + safePrint('Failed to create todo', e); +} +``` + + + In your application, you can perform CRUD operations against the model with the `awsIAM` auth mode. From 7a6bcfcce3d9d1cd07d56d3d6d6ed5a2d4863a5e Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:52:57 -0700 Subject: [PATCH 17/27] chore: replace js snippets with flutter snippets in user group-based data access --- .../user-group-based-data-access/index.mdx | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/user-group-based-data-access/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/user-group-based-data-access/index.mdx index be25af69d33..1750641586b 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/user-group-based-data-access/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/user-group-based-data-access/index.mdx @@ -47,7 +47,7 @@ const schema = a.schema({ }); ``` - + In your application, you can perform CRUD operations against the model using `client.models.` with the `userPool` auth mode. @@ -73,6 +73,30 @@ const { errors, data: newSalary } = await client.models.Salary.create( + +In your application, you can perform CRUD operations against the model with the `userPools` auth mode. + +```dart +try { + final todo = Todo(content: 'My new todo'); + final request = ModelMutations.create(todo); + final createdTodo = await Amplify.DataStore.save( + request: request, + authorizationMode: APIAuthorizationType.userPools + ).response; + + if (createdTodo == null) { + safePrint('errors: ${response.errors}'); + return; + } + safePrint('Mutation result: ${createdTodo.name}'); + +} on APIException catch (e) { + safePrint('Failed to create todo', e); +} +``` + + In your application, you can perform CRUD operations against the model with the `amazonCognitoUserPools` auth mode. From 097a1d2806b25a153694dd909f6fd16ba42c358e Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:57:36 -0700 Subject: [PATCH 18/27] chore: replace js snippet with flutter snippets in custom data access using lambda functions page --- .../custom-data-access-patterns/index.mdx | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/custom-data-access-patterns/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/custom-data-access-patterns/index.mdx index 85f77707043..9c8fffbd886 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/custom-data-access-patterns/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/custom-data-access-patterns/index.mdx @@ -68,6 +68,7 @@ export const data = defineData({ }, }); ``` + In your application, you can perform CRUD operations against the model using `client.models.` with the `lambda` auth mode. @@ -89,6 +90,33 @@ const { errors, data: newTodo } = await client.models.Todo.create( ); ``` + + + +In your application, you can perform CRUD operations against the model with the `function` auth mode. + +```dart +try { + final todo = Todo(content: 'My new todo'); + final request = ModelMutations.create(todo); + final createdTodo = await Amplify.DataStore.save( + request: request, + authorizationMode: APIAuthorizationType.function + ).response; + + if (createdTodo == null) { + safePrint('errors: ${response.errors}'); + return; + } + safePrint('Mutation result: ${createdTodo.name}'); + +} on APIException catch (e) { + safePrint('Failed to create todo', e); +} +``` + + + The Lambda function of choice will receive an authorization token from the client and execute the desired authorization logic. The AppSync GraphQL API will receive a payload from Lambda after invocation to allow or deny the API call accordingly. To configure a Lambda function as the authorization mode, create a new file `amplify/data/custom-authorizer.ts`. You can use this Lambda function code template as a starting point for your authorization handler code: From bc89a52edde2676efd09cbb56abd93eb6f7ebd24 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Fri, 14 Jun 2024 09:22:36 -0700 Subject: [PATCH 19/27] chore: replaced js snippet with flutter snippet in use openID Connect as an authorization provider page --- .../index.mdx | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/using-oidc-authorization-provider/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/using-oidc-authorization-provider/index.mdx index 4fcf5fad7ef..1139843fccb 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/using-oidc-authorization-provider/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/using-oidc-authorization-provider/index.mdx @@ -68,6 +68,8 @@ export const data = defineData({ }); ``` + + In your application, you can perform CRUD operations against the model using `client.models.` by specifying the `oidc` auth mode. ```ts @@ -82,3 +84,30 @@ const { errors, data: todos } = await client.models.Todo.list({ // highlight-end }); ``` + + + + +In your application, you can perform CRUD operations against the model with the `oidc` auth mode. + +```dart +try { + final todo = Todo(content: 'My new todo'); + final request = ModelMutations.create(todo); + final createdTodo = await Amplify.DataStore.save( + request: request, + authorizationMode: APIAuthorizationType.oidc + ).response; + + if (createdTodo == null) { + safePrint('errors: ${response.errors}'); + return; + } + safePrint('Mutation result: ${createdTodo.name}'); + +} on APIException catch (e) { + safePrint('Failed to create todo', e); +} +``` + + From 938e5d165dcfc7a19d0f82f8fc901c3d2d6b14d1 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Fri, 14 Jun 2024 09:31:05 -0700 Subject: [PATCH 20/27] chore: replace js snippets with flutter snippets in configure custom identity and group claims page --- .../index.mdx | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/configure-custom-identity-and-group-claim/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/configure-custom-identity-and-group-claim/index.mdx index 6327f17611f..9f24d6d64c1 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/configure-custom-identity-and-group-claim/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/configure-custom-identity-and-group-claim/index.mdx @@ -56,6 +56,8 @@ export const data = defineData({ schema }); ``` + + In your application, you can perform CRUD operations against the model using `client.models.` with the `userPool` auth mode. ```ts @@ -76,3 +78,29 @@ const { errors, data: newTodo } = await client.models.Todo.create( // highlight-end ); ``` + + + + +In your application, you can perform CRUD operations against the model with the `userPools` auth mode. + +```dart +try { + final todo = Todo(content: 'My new todo'); + final request = ModelMutations.create(todo); + final createdTodo = await Amplify.DataStore.save( + request: request, + authorizationMode: APIAuthorizationType.userPools + ).response; + + if (createdTodo == null) { + safePrint('errors: ${response.errors}'); + return; + } + safePrint('Mutation result: ${createdTodo.name}'); + +} on APIException catch (e) { + safePrint('Failed to create todo', e); +} +``` + From 420ac5ceb5d5cbded71009da43d6aeae390e8ec5 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:36:10 -0700 Subject: [PATCH 21/27] chore: fixed amplifyconfig and replaced with ApmlifyConfig --- .../analytics/flutter/getting-started/30_initAnalytics.mdx | 4 ++-- .../[platform]/build-a-backend/auth/set-up-auth/index.mdx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fragments/lib/analytics/flutter/getting-started/30_initAnalytics.mdx b/src/fragments/lib/analytics/flutter/getting-started/30_initAnalytics.mdx index 5b4dfc96134..1f7f4cca75c 100644 --- a/src/fragments/lib/analytics/flutter/getting-started/30_initAnalytics.mdx +++ b/src/fragments/lib/analytics/flutter/getting-started/30_initAnalytics.mdx @@ -39,7 +39,7 @@ Future _configureAmplify() async { // Once Plugins are added, configure Amplify // Note: Amplify can only be configured once. try { - await Amplify.configure(amplifyconfig); + await Amplify.configure(amplifyConfig); } on AmplifyAlreadyConfiguredException { safePrint( 'Tried to reconfigure Amplify; this can occur when your app restarts on Android.', @@ -67,7 +67,7 @@ Future _configureAmplify() async { // Once Plugins are added, configure Amplify // Note: Amplify can only be configured once. try { - await Amplify.configure(amplifyconfig); + await Amplify.configure(amplifyConfig); } on AmplifyAlreadyConfiguredException { safePrint( 'Tried to reconfigure Amplify; this can occur when your app restarts on Android.', diff --git a/src/pages/[platform]/build-a-backend/auth/set-up-auth/index.mdx b/src/pages/[platform]/build-a-backend/auth/set-up-auth/index.mdx index 9df4b228568..211b0e429ab 100644 --- a/src/pages/[platform]/build-a-backend/auth/set-up-auth/index.mdx +++ b/src/pages/[platform]/build-a-backend/auth/set-up-auth/index.mdx @@ -410,7 +410,7 @@ Future main() async { Future _configureAmplify() async { try { await Amplify.addPlugin(AmplifyAuthCognito()); - await Amplify.configure(amplifyconfig); + await Amplify.configure(amplifyConfig); safePrint('Successfully configured'); } on Exception catch (e) { safePrint('Error configuring Amplify: $e'); From 7d2a9d497945d19192c78ab595976f14a0f608dd Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:39:58 -0700 Subject: [PATCH 22/27] Update src/pages/[platform]/build-a-backend/data/customize-authz/configure-custom-identity-and-group-claim/index.mdx Co-authored-by: Elijah Quartey --- .../index.mdx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/configure-custom-identity-and-group-claim/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/configure-custom-identity-and-group-claim/index.mdx index 9f24d6d64c1..9bd3bd7c66a 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/configure-custom-identity-and-group-claim/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/configure-custom-identity-and-group-claim/index.mdx @@ -86,12 +86,12 @@ In your application, you can perform CRUD operations against the model with the ```dart try { - final todo = Todo(content: 'My new todo'); - final request = ModelMutations.create(todo); - final createdTodo = await Amplify.DataStore.save( - request: request, - authorizationMode: APIAuthorizationType.userPools - ).response; +final todo = Todo(content: 'My new todo'); +final request = ModelMutations.create( + todo, + authorizationMode: APIAuthorizationType.userPools, +); +final createdTodo = await Amplify.API.mutations(request: request).response; if (createdTodo == null) { safePrint('errors: ${response.errors}'); From 88cc42408642eec413562c5588bc30b055a5522f Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Mon, 17 Jun 2024 11:20:41 -0700 Subject: [PATCH 23/27] chore: fix API code snippets --- .../index.mdx | 12 +++++------ .../custom-data-access-patterns/index.mdx | 10 +++++----- .../multi-user-data-access/index.mdx | 10 +++++----- .../per-user-per-owner-data-access/index.mdx | 10 +++++----- .../public-data-access/index.mdx | 20 +++++++++---------- .../signed-in-user-data-access/index.mdx | 20 +++++++++---------- .../user-group-based-data-access/index.mdx | 10 +++++----- .../index.mdx | 10 +++++----- 8 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/configure-custom-identity-and-group-claim/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/configure-custom-identity-and-group-claim/index.mdx index 9bd3bd7c66a..5c311e14155 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/configure-custom-identity-and-group-claim/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/configure-custom-identity-and-group-claim/index.mdx @@ -86,12 +86,12 @@ In your application, you can perform CRUD operations against the model with the ```dart try { -final todo = Todo(content: 'My new todo'); -final request = ModelMutations.create( - todo, - authorizationMode: APIAuthorizationType.userPools, -); -final createdTodo = await Amplify.API.mutations(request: request).response; + final todo = Todo(content: 'My new todo'); + final request = ModelMutations.create( + todo, + authorizationMode: APIAuthorizationType.userPools, + ); + final createdTodo = await Amplify.API.mutations(request: request).response; if (createdTodo == null) { safePrint('errors: ${response.errors}'); diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/custom-data-access-patterns/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/custom-data-access-patterns/index.mdx index 9c8fffbd886..dd17b9f71e8 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/custom-data-access-patterns/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/custom-data-access-patterns/index.mdx @@ -98,11 +98,11 @@ In your application, you can perform CRUD operations against the model with the ```dart try { final todo = Todo(content: 'My new todo'); - final request = ModelMutations.create(todo); - final createdTodo = await Amplify.DataStore.save( - request: request, - authorizationMode: APIAuthorizationType.function - ).response; + final request = ModelMutations.create( + todo, + authorizationMode: APIAuthorizationType.function, + ); + final createdTodo = await Amplify.API.mutations(request: request).response; if (createdTodo == null) { safePrint('errors: ${response.errors}'); diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/multi-user-data-access/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/multi-user-data-access/index.mdx index 96c67abe712..74831e5535c 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/multi-user-data-access/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/multi-user-data-access/index.mdx @@ -94,11 +94,11 @@ In your application, you can perform CRUD operations against the model with the ```dart try { final todo = Todo(content: 'My new todo'); - final request = ModelMutations.create(todo); - final createdTodo = await Amplify.DataStore.save( - request: request, - authorizationMode: APIAuthorizationType.userPools - ).response; + final request = ModelMutations.create( + todo, + authorizationMode: APIAuthorizationType.userPools, + ); + final createdTodo = await Amplify.API.mutations(request: request).response; if (createdTodo == null) { safePrint('errors: ${response.errors}'); diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/per-user-per-owner-data-access/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/per-user-per-owner-data-access/index.mdx index 80503ac1d21..1abb86bb0c7 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/per-user-per-owner-data-access/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/per-user-per-owner-data-access/index.mdx @@ -88,11 +88,11 @@ In your application, you can perform CRUD operations against the model with the ```dart try { final todo = Todo(content: 'My new todo'); - final request = ModelMutations.create(todo); - final createdTodo = await Amplify.DataStore.save( - request: request, - authorizationMode: APIAuthorizationType.userPools - ).response; + final request = ModelMutations.create( + todo, + authorizationMode: APIAuthorizationType.userPools, + ); + final createdTodo = await Amplify.API.mutations(request: request).response; if (createdTodo == null) { safePrint('errors: ${response.errors}'); diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/public-data-access/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/public-data-access/index.mdx index 8fbed241c30..df2beb9f9f6 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/public-data-access/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/public-data-access/index.mdx @@ -78,11 +78,11 @@ In your application, you can perform CRUD operations against the model by specif ```dart try { final todo = Todo(content: 'My new todo'); - final request = ModelMutations.create(todo); - final createdTodo = await Amplify.DataStore.save( - request: request, - authorizationMode: APIAuthorizationType.apiKey - ).response; + final request = ModelMutations.create( + todo, + authorizationMode: APIAuthorizationType.apiKey, + ); + final createdTodo = await Amplify.API.mutations(request: request).response; if (createdTodo == null) { safePrint('errors: ${response.errors}'); @@ -181,11 +181,11 @@ In your application, you can perform CRUD operations against the model with the ```dart try { final todo = Todo(content: 'My new todo'); - final request = ModelMutations.create(todo); - final createdTodo = await Amplify.DataStore.save( - request: request, - authorizationMode: APIAuthorizationType.iam - ).response; + final request = ModelMutations.create( + todo, + authorizationMode: APIAuthorizationType.iam, + ); + final createdTodo = await Amplify.API.mutations(request: request).response; if (createdTodo == null) { safePrint('errors: ${response.errors}'); diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/signed-in-user-data-access/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/signed-in-user-data-access/index.mdx index 7c6c9662017..3ad29a63f60 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/signed-in-user-data-access/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/signed-in-user-data-access/index.mdx @@ -80,11 +80,11 @@ In your application, you can perform CRUD operations against the model with the ```dart try { final todo = Todo(content: 'My new todo'); - final request = ModelMutations.create(todo); - final createdTodo = await Amplify.DataStore.save( - request: request, - authorizationMode: APIAuthorizationType.userPools - ).response; + final request = ModelMutations.create( + todo, + authorizationMode: APIAuthorizationType.userPools, + ); + final createdTodo = await Amplify.API.mutations(request: request).response; if (createdTodo == null) { safePrint('errors: ${response.errors}'); @@ -163,11 +163,11 @@ In your application, you can perform CRUD operations against the model with the ```dart try { final todo = Todo(content: 'My new todo'); - final request = ModelMutations.create(todo); - final createdTodo = await Amplify.DataStore.save( - request: request, - authorizationMode: APIAuthorizationType.iam - ).response; + final request = ModelMutations.create( + todo, + authorizationMode: APIAuthorizationType.iam, + ); + final createdTodo = await Amplify.API.mutations(request: request).response; if (createdTodo == null) { safePrint('errors: ${response.errors}'); diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/user-group-based-data-access/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/user-group-based-data-access/index.mdx index 1750641586b..934b3421718 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/user-group-based-data-access/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/user-group-based-data-access/index.mdx @@ -79,11 +79,11 @@ In your application, you can perform CRUD operations against the model with the ```dart try { final todo = Todo(content: 'My new todo'); - final request = ModelMutations.create(todo); - final createdTodo = await Amplify.DataStore.save( - request: request, - authorizationMode: APIAuthorizationType.userPools - ).response; + final request = ModelMutations.create( + todo, + authorizationMode: APIAuthorizationType.userPools, + ); + final createdTodo = await Amplify.API.mutations(request: request).response; if (createdTodo == null) { safePrint('errors: ${response.errors}'); diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/using-oidc-authorization-provider/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/using-oidc-authorization-provider/index.mdx index 1139843fccb..18493cb1302 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/using-oidc-authorization-provider/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/using-oidc-authorization-provider/index.mdx @@ -93,11 +93,11 @@ In your application, you can perform CRUD operations against the model with the ```dart try { final todo = Todo(content: 'My new todo'); - final request = ModelMutations.create(todo); - final createdTodo = await Amplify.DataStore.save( - request: request, - authorizationMode: APIAuthorizationType.oidc - ).response; + final request = ModelMutations.create( + todo, + authorizationMode: APIAuthorizationType.oidc, + ); + final createdTodo = await Amplify.API.mutations(request: request).response; if (createdTodo == null) { safePrint('errors: ${response.errors}'); From 7b0b28150a4a95fe12f8f735ac617d551b72cd1a Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Mon, 17 Jun 2024 11:20:57 -0700 Subject: [PATCH 24/27] Update src/pages/[platform]/build-a-backend/data/set-up-data/index.mdx Co-authored-by: Elijah Quartey --- src/pages/[platform]/build-a-backend/data/set-up-data/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/data/set-up-data/index.mdx b/src/pages/[platform]/build-a-backend/data/set-up-data/index.mdx index 69693dd36f0..f6f9f6b08bd 100644 --- a/src/pages/[platform]/build-a-backend/data/set-up-data/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/set-up-data/index.mdx @@ -341,7 +341,7 @@ Future main() async { try { final api = AmplifyAPI( options: APIPluginOptions( - modelRegistration: ModelProvider() + modelProvider: ModelProvider.instance ) ); await Amplify.addPlugins([api]); From 32c91b3065013ba4a246ff6623269938618d8db0 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Mon, 17 Jun 2024 11:52:25 -0700 Subject: [PATCH 25/27] chore: fixed multi-user-data-access code and replaced with flutter code --- .../multi-user-data-access/index.mdx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/customize-authz/multi-user-data-access/index.mdx b/src/pages/[platform]/build-a-backend/data/customize-authz/multi-user-data-access/index.mdx index 74831e5535c..5a29631b348 100644 --- a/src/pages/[platform]/build-a-backend/data/customize-authz/multi-user-data-access/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/customize-authz/multi-user-data-access/index.mdx @@ -115,12 +115,20 @@ Add another user as an owner ```dart try { - createdTodo.owners?.append(otherUserId); - let updatedTodo = await Amplify.API.mutate(request: .update( + createdTodo.owners!.add(otherUserId); + let updateRequest = ModelMutations.update( createdTodo, - authMode: .userPools)).get() + authorizationMode: APIAuthorizationType.userPools, + ); + final updatedTodo = await Amplify.API.mutations(request: updateRequest).response; + + if (updatedTodo == null) { + safePrint('errors: ${response.errors}'); + return; + } + } catch { - print("Failed to update todo", error) + safePrint("Failed to update todo", error) } ``` From 207147285fefe91a2ddc2f02bc1c66db10191674 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Mon, 17 Jun 2024 11:58:07 -0700 Subject: [PATCH 26/27] chore: revert changes in gen1 docs --- .../analytics/flutter/getting-started/30_initAnalytics.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fragments/lib/analytics/flutter/getting-started/30_initAnalytics.mdx b/src/fragments/lib/analytics/flutter/getting-started/30_initAnalytics.mdx index 1f7f4cca75c..5b4dfc96134 100644 --- a/src/fragments/lib/analytics/flutter/getting-started/30_initAnalytics.mdx +++ b/src/fragments/lib/analytics/flutter/getting-started/30_initAnalytics.mdx @@ -39,7 +39,7 @@ Future _configureAmplify() async { // Once Plugins are added, configure Amplify // Note: Amplify can only be configured once. try { - await Amplify.configure(amplifyConfig); + await Amplify.configure(amplifyconfig); } on AmplifyAlreadyConfiguredException { safePrint( 'Tried to reconfigure Amplify; this can occur when your app restarts on Android.', @@ -67,7 +67,7 @@ Future _configureAmplify() async { // Once Plugins are added, configure Amplify // Note: Amplify can only be configured once. try { - await Amplify.configure(amplifyConfig); + await Amplify.configure(amplifyconfig); } on AmplifyAlreadyConfiguredException { safePrint( 'Tried to reconfigure Amplify; this can occur when your app restarts on Android.', From a7e38b5dbbb0b6dbbe33d9302787da460f8265c3 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Tue, 18 Jun 2024 11:31:15 -0700 Subject: [PATCH 27/27] chore: remove gen1 remnants for analytics category --- .../add-aws-services/analytics/record-events/index.mdx | 1 - .../add-aws-services/analytics/set-up-analytics/index.mdx | 8 -------- 2 files changed, 9 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/analytics/record-events/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/analytics/record-events/index.mdx index ab3ab6d7acc..3c7017249f0 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/analytics/record-events/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/analytics/record-events/index.mdx @@ -309,7 +309,6 @@ Events have default configuration to flush out to the network every 30 seconds. ```json { - "UserAgent": "aws-amplify-cli/2.0", "Version": "1.0", "analytics": { "plugins": { diff --git a/src/pages/[platform]/build-a-backend/add-aws-services/analytics/set-up-analytics/index.mdx b/src/pages/[platform]/build-a-backend/add-aws-services/analytics/set-up-analytics/index.mdx index 28cf14b6e90..6c4d61a2d6f 100644 --- a/src/pages/[platform]/build-a-backend/add-aws-services/analytics/set-up-analytics/index.mdx +++ b/src/pages/[platform]/build-a-backend/add-aws-services/analytics/set-up-analytics/index.mdx @@ -520,14 +520,6 @@ public class MyAmplifyApp extends Application { -### View Analytics Console - -If you have not saved the link from before, you can still reach it from the terminal. Run the following command for opening the console. - -```sh -amplify console analytics -``` - Next Steps: Congratulations! Now that you have Analytics' backend provisioned and Analytics library installed. Check out the following links to see Amplify Analytics use cases: