Skip to content

Commit d86881d

Browse files
authored
docs: update custom message with admincreateuser specifics (#8314)
1 parent 58cae8d commit d86881d

File tree

1 file changed

+12
-1
lines changed
  • src/pages/[platform]/build-a-backend/functions/examples/custom-message

1 file changed

+12
-1
lines changed

src/pages/[platform]/build-a-backend/functions/examples/custom-message/index.mdx

+12-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ npm add --save-dev @types/aws-lambda
3838
```
3939

4040

41-
Next, create a new directory and a resource file, `amplify/auth/custom-message/resource.ts`. Then, define the function with defineFunction:
41+
Next, create a new directory and a resource file, `amplify/auth/custom-message/resource.ts`. Then, define the function with `defineFunction`:
4242

4343
```ts title="amplify/auth/custom-message/resource.ts"
4444
import { defineFunction } from '@aws-amplify/backend';
@@ -51,6 +51,10 @@ export const customMessage = defineFunction({
5151

5252
Next, create the corresponding handler file, `amplify/auth/custom-message/handler.ts`, file with the following contents:
5353

54+
<Callout>
55+
The input event for the `CustomMessage_AdminCreateUser` trigger source includes both a username and verification code. Admin-created users must receive both their username and code in order to sign in and thus you must include both the `usernameParameter` and `codeParameter` in your message template.
56+
</Callout>
57+
5458
{/* spell-checker: disable */}
5559
```ts title="amplify/auth/custom-message/handler.ts"
5660
import type { CustomMessageTriggerHandler } from "aws-lambda";
@@ -67,12 +71,19 @@ export const handler: CustomMessageTriggerHandler = async (event) => {
6771
}
6872
}
6973

74+
if (event.triggerSource === "CustomMessage_AdminCreateUser") {
75+
event.response.emailMessage = `Your username is ${event.request.usernameParameter} and your temporary password is ${event.request.codeParameter}`;
76+
event.response.emailSubject = 'Welcome to Example App';
77+
}
78+
7079
return event;
7180
};
7281
```
7382
{/* spellchecker: enable */}
7483

7584

85+
86+
7687
Lastly, set the newly created function resource on your auth resource:
7788

7889
```ts title="amplify/auth/resource.ts"

0 commit comments

Comments
 (0)