From c6aa70ec205d85f263aec96d6a0a551db416b82e Mon Sep 17 00:00:00 2001 From: Dan Kiuna Date: Fri, 10 Mar 2023 20:19:23 -0600 Subject: [PATCH 1/7] how to add non-default admin actions --- src/pages/cli/auth/admin.mdx | 50 +++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/pages/cli/auth/admin.mdx b/src/pages/cli/auth/admin.mdx index a71796da6b2..f48cb5a43fe 100644 --- a/src/pages/cli/auth/admin.mdx +++ b/src/pages/cli/auth/admin.mdx @@ -263,4 +263,52 @@ class MyCustomInterceptor: URLRequestInterceptor { } ``` - \ No newline at end of file + + +## Adding Admin Actions + +To add additional admin actions that are not included by default but are enabled by Cognito, you will need to modify the Lambda function that is generated for you. The change will include adding a function for the action, and creating a route for it. You will then associate the function to the route within the express app. + +Below is an example of adding an admin action that will allow you to update a user's attributes. +```js +async function updateUserAttributes(username, attributes) { + + var params = { + Username: username, + UserAttributes: attributes, + UserPoolId: 'STRING_VALUE', + }; + + console.log(`Attempting to update ${username} attributes`); + + try { + await cognitoIdentityServiceProvider.adminUpdateUserAttributes(params).promise(); + console.log(`Success updating ${username} attributes`); + return { + message: `Success updating ${username} attributes`, + }; + } catch (err) { + console.log(err); + throw err; + } +} +``` +Once the function is defined, you will then add a route with the correct HTTP method to the express app and associate the function to the route. Be sure to make the route unique. + +Below is an example of how you can add a `POST` route named `/updateUserAttributes` and associate the above function to it. +```js +app.post('/updateUserAttributes', async (req, res, next) => { + if (!req.body.username || !req.body.attributes) { + const err = new Error('username and attributes are required'); + err.statusCode = 400; + return next(err); + } + + try { + const response = await updateUserAttributes(req.body.username, req.body.attributes); + res.status(200).json(response); + } catch (err) { + next(err); + } +}); +``` \ No newline at end of file From 1d42dada198d2729d923ad5feab0006c5c34c045 Mon Sep 17 00:00:00 2001 From: Dan Kiuna Date: Fri, 10 Mar 2023 20:30:12 -0600 Subject: [PATCH 2/7] how to add non-default admin actions - text changes --- src/pages/cli/auth/admin.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/cli/auth/admin.mdx b/src/pages/cli/auth/admin.mdx index f48cb5a43fe..e2b1c747e4e 100644 --- a/src/pages/cli/auth/admin.mdx +++ b/src/pages/cli/auth/admin.mdx @@ -267,9 +267,9 @@ class MyCustomInterceptor: URLRequestInterceptor { ## Adding Admin Actions -To add additional admin actions that are not included by default but are enabled by Cognito, you will need to modify the Lambda function that is generated for you. The change will include adding a function for the action, and creating a route for it. You will then associate the function to the route within the express app. +To add additional admin actions that are not included by default but are enabled by Amazon Cognito, you will need to update the Lambda function code that is generated for you. The change will include adding a procedure for the action and creating a route for it. You will then associate the procedure to the route within the express app. -Below is an example of adding an admin action that will allow you to update a user's attributes. +Below is an example of how to add an admin action that will allow you to update a user's attributes. ```js async function updateUserAttributes(username, attributes) { @@ -293,9 +293,9 @@ async function updateUserAttributes(username, attributes) { } } ``` -Once the function is defined, you will then add a route with the correct HTTP method to the express app and associate the function to the route. Be sure to make the route unique. +Once the procedure is defined, you will then add a route with the correct HTTP method to the express app and associate the procedure to the route. Be sure to make the route unique. -Below is an example of how you can add a `POST` route named `/updateUserAttributes` and associate the above function to it. +Below is an example of how you can add a `POST` route named `/updateUserAttributes` and associate the above procedure to it. ```js app.post('/updateUserAttributes', async (req, res, next) => { if (!req.body.username || !req.body.attributes) { From 5af11b79a4e2dfbe006a767f1ead2de11caee75c Mon Sep 17 00:00:00 2001 From: Dan Kiuna Date: Thu, 16 Mar 2023 16:45:33 -0500 Subject: [PATCH 3/7] Update link Co-authored-by: josef --- src/pages/cli/auth/admin.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/cli/auth/admin.mdx b/src/pages/cli/auth/admin.mdx index e2b1c747e4e..f75592da2c3 100644 --- a/src/pages/cli/auth/admin.mdx +++ b/src/pages/cli/auth/admin.mdx @@ -269,7 +269,7 @@ class MyCustomInterceptor: URLRequestInterceptor { To add additional admin actions that are not included by default but are enabled by Amazon Cognito, you will need to update the Lambda function code that is generated for you. The change will include adding a procedure for the action and creating a route for it. You will then associate the procedure to the route within the express app. -Below is an example of how to add an admin action that will allow you to update a user's attributes. +Below is an example of how to add an admin action that will allow you to [update a user's attributes](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminUpdateUserAttributes.html). ```js async function updateUserAttributes(username, attributes) { From 98a5c3e8bb6fbe30e4fdc035bd15c587634e9dfc Mon Sep 17 00:00:00 2001 From: Dan Kiuna Date: Thu, 16 Mar 2023 16:45:56 -0500 Subject: [PATCH 4/7] var to const Co-authored-by: josef --- src/pages/cli/auth/admin.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/cli/auth/admin.mdx b/src/pages/cli/auth/admin.mdx index f75592da2c3..820d640913f 100644 --- a/src/pages/cli/auth/admin.mdx +++ b/src/pages/cli/auth/admin.mdx @@ -273,7 +273,7 @@ Below is an example of how to add an admin action that will allow you to [update ```js async function updateUserAttributes(username, attributes) { - var params = { + const params = { Username: username, UserAttributes: attributes, UserPoolId: 'STRING_VALUE', From 725dcf83eef574e680e21b098142b82a13732dc4 Mon Sep 17 00:00:00 2001 From: Dan Kiuna Date: Thu, 16 Mar 2023 16:46:12 -0500 Subject: [PATCH 5/7] Link to Express Co-authored-by: josef --- src/pages/cli/auth/admin.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/cli/auth/admin.mdx b/src/pages/cli/auth/admin.mdx index 820d640913f..a787e93d289 100644 --- a/src/pages/cli/auth/admin.mdx +++ b/src/pages/cli/auth/admin.mdx @@ -267,7 +267,7 @@ class MyCustomInterceptor: URLRequestInterceptor { ## Adding Admin Actions -To add additional admin actions that are not included by default but are enabled by Amazon Cognito, you will need to update the Lambda function code that is generated for you. The change will include adding a procedure for the action and creating a route for it. You will then associate the procedure to the route within the express app. +To add additional admin actions that are not included by default but are enabled by Amazon Cognito, you will need to update the Lambda function code that is generated for you. The change will include adding a procedure for the action and creating a route for it. You will then associate the procedure to the route within the [Express](https://expressjs.com/) app. Below is an example of how to add an admin action that will allow you to [update a user's attributes](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminUpdateUserAttributes.html). ```js From 44dc0a17bb664a30d286c486450c6a7993e214dd Mon Sep 17 00:00:00 2001 From: Dan Kiuna Date: Thu, 16 Mar 2023 16:46:26 -0500 Subject: [PATCH 6/7] Express as noun Co-authored-by: josef --- src/pages/cli/auth/admin.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/cli/auth/admin.mdx b/src/pages/cli/auth/admin.mdx index a787e93d289..da4f61d7b6e 100644 --- a/src/pages/cli/auth/admin.mdx +++ b/src/pages/cli/auth/admin.mdx @@ -293,7 +293,7 @@ async function updateUserAttributes(username, attributes) { } } ``` -Once the procedure is defined, you will then add a route with the correct HTTP method to the express app and associate the procedure to the route. Be sure to make the route unique. +Once the procedure is defined, you will then add a route with the correct HTTP method to the Express app and associate the procedure to the route. Be sure to make the route unique. Below is an example of how you can add a `POST` route named `/updateUserAttributes` and associate the above procedure to it. ```js From 05ea7a30cb6060e4a12bd90712a1185db122a8b5 Mon Sep 17 00:00:00 2001 From: Dan Kiuna Date: Tue, 21 Mar 2023 21:37:40 -0500 Subject: [PATCH 7/7] changing "procedure" to "route handler" --- src/pages/cli/auth/admin.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/cli/auth/admin.mdx b/src/pages/cli/auth/admin.mdx index da4f61d7b6e..1603316ab90 100644 --- a/src/pages/cli/auth/admin.mdx +++ b/src/pages/cli/auth/admin.mdx @@ -267,7 +267,7 @@ class MyCustomInterceptor: URLRequestInterceptor { ## Adding Admin Actions -To add additional admin actions that are not included by default but are enabled by Amazon Cognito, you will need to update the Lambda function code that is generated for you. The change will include adding a procedure for the action and creating a route for it. You will then associate the procedure to the route within the [Express](https://expressjs.com/) app. +To add additional admin actions that are not included by default but are enabled by Amazon Cognito, you will need to update the Lambda function code that is generated for you. The change will include adding a route handler for the action and creating a route for it. You will then associate the route handler to the route within the [Express](https://expressjs.com/) app. Below is an example of how to add an admin action that will allow you to [update a user's attributes](https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminUpdateUserAttributes.html). ```js @@ -293,9 +293,9 @@ async function updateUserAttributes(username, attributes) { } } ``` -Once the procedure is defined, you will then add a route with the correct HTTP method to the Express app and associate the procedure to the route. Be sure to make the route unique. +Once the route handler is defined, you will then add a route with the correct HTTP method to the Express app and associate the route handler to the route. Be sure to make the route unique. -Below is an example of how you can add a `POST` route named `/updateUserAttributes` and associate the above procedure to it. +Below is an example of how you can add a `POST` route named `/updateUserAttributes` and associate the above route handler to it. ```js app.post('/updateUserAttributes', async (req, res, next) => { if (!req.body.username || !req.body.attributes) {