Pavan Kumar
12/02/2021, 12:21 PMcognitoArn
is null. How would I get around it or what is proper way to do it.
const preSignUpFunction = new sst.Function(this, 'PreSignUp', {
handler: 'users/auth/preSignUp.handler'
})
const userPool = new cognito.UserPool(this, "UserPool", {
lambdaTriggers: {
preSignUp: preSignUpFunction,
}
});
const userPoolClient = new cognito.UserPoolClient(this, "UserPoolClient", {
// ...
});
this.auth = new sst.Auth(this, 'Auth', {
cognito: {
userPool,
userPoolClient,
},
});
const cognitoArn = this.auth.cognitoUserPool?.userPoolArn;
if (cognitoArn) {
const permissions = [
new iam.PolicyStatement({
actions: [
"cognito-idp:AdminCreateUser",
"cognito-idp:AdminDeleteUser",
"cognito-idp:AdminSetUserPassword",
"cognito-idp:AdminDisableUser",
"cognito-idp:AdminEnableUser",
"cognito-idp:AdminUpdateUserAttributes",
],
effect: iam.Effect.ALLOW,
resources: [
cognitoArn
],
})
];
preSignUpFunction.attachPermissions(permissions);
}
Gabriel Araújo
12/02/2021, 1:02 PMGabriel Araújo
12/02/2021, 1:03 PMGabriel Araújo
12/02/2021, 1:03 PMPavan Kumar
12/02/2021, 2:09 PMthis.auth.cognitoUserPool?.userPoolArn
. Because when I use it, i get type script error that it may be null. But when I wrap it around if statement then if block won't get executed as this.auth.cognitoUserPool?.userPoolArn
is null/undefined at that time.Omi Chowdhury
12/02/2021, 2:44 PMuserPool.userPoolArn
directly?Pavan Kumar
12/02/2021, 2:48 PMresources: [
this.auth.cognitoUserPool!.userPoolArn!,
]
I get following error.
Rules with suggestions must set the `meta.hasSuggestions` property to `true`. `meta.docs.suggestion` is ignored by ESLint
Rule: "@typescript-eslint/no-non-null-assertion"
Omi Chowdhury
12/02/2021, 2:48 PMcognito.UserPool
Pavan Kumar
12/02/2021, 2:49 PM