From 203d2768779c77c1892b8089f21d01ae09170678 Mon Sep 17 00:00:00 2001 From: josefaidt Date: Mon, 7 Oct 2024 16:08:28 -0700 Subject: [PATCH 1/2] update auth example for "moving to production" email with `senders` --- .../auth/moving-to-production/index.mdx | 65 ++++++++++++------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/auth/moving-to-production/index.mdx b/src/pages/[platform]/build-a-backend/auth/moving-to-production/index.mdx index 3f03ffceaba..99c3b821237 100644 --- a/src/pages/[platform]/build-a-backend/auth/moving-to-production/index.mdx +++ b/src/pages/[platform]/build-a-backend/auth/moving-to-production/index.mdx @@ -44,33 +44,50 @@ To get started with Amazon SES in production, you must first [request production After you have configured your account for production access and have verified your _sender_ email, you can configure your Cognito user pool to send emails using the verified sender: -```ts title="amplify/backend.ts" -import { Stack } from "aws-cdk-lib/core" -import { EmailIdentity } from "aws-cdk-lib/aws-ses" -import { defineBackend } from "@aws-amplify/backend" -import { auth } from "./auth/resource" - -const backend = defineBackend({ - auth, +```ts title="amplify/auth/resource.ts" +import { defineAuth } from "@aws-amplify/backend" + +/** + * Define and configure your auth resource + * @see https://docs.amplify.aws/gen2/build-a-backend/auth + */ +export const auth = defineAuth({ + loginWith: { + email: true, + }, + senders: { + email: { + // configure using the email registered and verified in Amazon SES + fromEmail: "registrations@example.com", + }, + }, }) - -const { cfnUserPool } = backend.auth.resources.cfnResources -const authStack = Stack.of(cfnUserPool) - -const email = EmailIdentity.fromEmailIdentityName( - authStack, - "EmailIdentity", - // your email configured for use in SES - process.env.EMAIL -) - -cfnUserPool.emailConfiguration = { - emailSendingAccount: "DEVELOPER", - sourceArn: email.emailIdentityArn, -} ``` -Now when emails are sent on new user sign-ups, password resets, etc., the sending account will be your verified email. +Now when emails are sent on new user sign-ups, password resets, etc., the sending account will be your verified email! To customize further, you can change the display name of the sender, or optionally apply a custom address for your users to reply. + +```ts title="amplify/auth/resource.ts" +import { defineAuth } from "@aws-amplify/backend" + +/** + * Define and configure your auth resource + * @see https://docs.amplify.aws/gen2/build-a-backend/auth + */ +export const auth = defineAuth({ + loginWith: { + email: true, + }, + senders: { + email: { + fromEmail: "registrations@example.com", + // highlight-start + fromName: "MyApp", + replyTo: "inquiries@example.com" + // highlight-end + }, + }, +}) +``` ## SMS From ddfb4a4cf4b7101e79b79b8ab41c6eed5a22e46d Mon Sep 17 00:00:00 2001 From: josefaidt Date: Mon, 7 Oct 2024 16:12:04 -0700 Subject: [PATCH 2/2] update jsdoc links --- .../build-a-backend/auth/moving-to-production/index.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/auth/moving-to-production/index.mdx b/src/pages/[platform]/build-a-backend/auth/moving-to-production/index.mdx index 99c3b821237..cf624701280 100644 --- a/src/pages/[platform]/build-a-backend/auth/moving-to-production/index.mdx +++ b/src/pages/[platform]/build-a-backend/auth/moving-to-production/index.mdx @@ -49,7 +49,7 @@ import { defineAuth } from "@aws-amplify/backend" /** * Define and configure your auth resource - * @see https://docs.amplify.aws/gen2/build-a-backend/auth + * @see https://docs.amplify.aws/react/build-a-backend/auth */ export const auth = defineAuth({ loginWith: { @@ -71,7 +71,7 @@ import { defineAuth } from "@aws-amplify/backend" /** * Define and configure your auth resource - * @see https://docs.amplify.aws/gen2/build-a-backend/auth + * @see https://docs.amplify.aws/react/build-a-backend/auth */ export const auth = defineAuth({ loginWith: {