Skip to content

Commit 59432ba

Browse files
Add Docs for Email Invitation Customization (#7891)
* add email invite template docs * Update src/pages/[platform]/build-a-backend/auth/customize-auth-lifecycle/email-customization/index.mdx Co-authored-by: josef <[email protected]> --------- Co-authored-by: josef <[email protected]>
1 parent 9e6e755 commit 59432ba

File tree

1 file changed

+32
-1
lines changed
  • src/pages/[platform]/build-a-backend/auth/customize-auth-lifecycle/email-customization

1 file changed

+32
-1
lines changed

src/pages/[platform]/build-a-backend/auth/customize-auth-lifecycle/email-customization/index.mdx

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,32 @@ export function getStaticProps() {
3131
{/* verification email (basic) */}
3232
{/* verification email with react.email/jsx.email */}
3333

34+
## Customize the Verification Email
35+
3436
By default, Amplify Auth resources are scaffolded with email as the default method for your users to sign in. When you users sign up they receive a verification email to confirm their ownership of the email they specified during sign-up. Emails such as the verification email can be customized with your app's brand identity.
3537

36-
To get started, modify `email: true` to an object to begin customizing its default behavior:
38+
To get started, change the `email` attribute of `loginWith` from `true` to an object to begin customizing its default behavior:
39+
40+
```diff title="amplify/auth/resource.ts"
41+
import { defineAuth } from "@aws-amplify/backend"
42+
43+
export const auth = defineAuth({
44+
loginWith: {
45+
- email: true,
46+
+ email: {
47+
+ verificationEmailStyle: "CODE",
48+
+ verificationEmailSubject: "Welcome to my app!",
49+
+ verificationEmailBody: (createCode) => `Use this code to confirm your account: ${createCode()}`,
50+
+ },
51+
},
52+
})
53+
```
54+
55+
## Customize the Invitation Email
56+
57+
In some cases, you may [set up a user account on behalf of a user in the Amplify console](/[platform]/build-a-backend/auth/manage-users/with-amplify-console/). In this case, Amplify Auth will send an invitation email to the user welcoming them to your application. This email includes a brief welcome message, along with the email address they can log in with and the temporary password you've set up for them.
58+
59+
If you'd like to customize that email, you can override the `userInvitation` attribute of the `email` object:
3760

3861
```diff title="amplify/auth/resource.ts"
3962
import { defineAuth } from "@aws-amplify/backend"
@@ -42,14 +65,22 @@ export const auth = defineAuth({
4265
loginWith: {
4366
- email: true,
4467
+ email: {
68+
+ // can be used in conjunction with a customized welcome email as well
4569
+ verificationEmailStyle: "CODE",
4670
+ verificationEmailSubject: "Welcome to my app!",
4771
+ verificationEmailBody: (createCode) => `Use this code to confirm your account: ${createCode()}`,
72+
+ userInvitation: {
73+
+ emailSubject: "Welcome to my app!",
74+
+ emailBody: (user, code) =>
75+
+ `We're happy to have you! You can now login with username ${user()} and temporary password ${code()}`,
76+
+ },
4877
+ },
4978
},
5079
})
5180
```
5281

82+
Note that when using the `user` and `code` arguments of the `emailBody` function, `user` and `code` are **functions** which must be called. Failure to call them will result in an error when your sandbox deploys.
83+
5384
{/* ## With react.email */}
5485

5586
{/* ## With jsx.email */}

0 commit comments

Comments
 (0)