-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes
51 lines (43 loc) · 1.53 KB
/
notes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const authProvider =
event.requestContext.identity.cognitoAuthenticationProvider;
// Cognito authentication provider looks like:
// cognito-idp.us-east-1.amazonaws.com/us-east-1_xxxxxxxxx,cognito-idp.us-east-1.amazonaws.com/us-east-1_aaaaaaaaa:CognitoSignIn:qqqqqqqq-1111-2222-3333-rrrrrrrrrrrr
// Where us-east-1_aaaaaaaaa is the User Pool id
// And qqqqqqqq-1111-2222-3333-rrrrrrrrrrrr is the User Pool User Id
const parts = authProvider.split(":");
const userPoolIdParts = parts[parts.length - 3].split("/");
const userPoolId = userPoolIdParts[userPoolIdParts.length - 1];
const userPoolUsername = parts[parts.length - 1];
let cognitoUser = await getCognitoUser(userPoolUsername);
// PROMISES NOTES
const someFunction = () => {
return new Promise((resolve, reject) => {
thirdPartyAPI({ name: 'test' }, (error, response) => {
if (error) {
reject(error);
} else {
resolve(response);
}
});
});
};
// Assume this is in your code somewhere...
try {
someFunction().then((response) => {}).catch((error) => {});
} catch (error) {
console.warn(error);
}
const downloadTurkeyDinner = async () => {
try {
const response = await someFunction(); // unhandledPromiseRejection
} catch (exception) {
throw new Error(`[actionName.downloadTurkeyDinner] ${exception.message}`);
}
};
async function downloadTurkeyDinner() {
try {
const response = await someFunction(); // unhandledPromiseRejection
} catch (exception) {
throw new Error(`[actionName.downloadTurkeyDinner] ${exception.message}`);
}
}