import * as cdk from 'aws-cdk-lib';
import * as cognito from 'aws-cdk-lib/aws-cognito';
import { Construct } from 'constructs';
export class AuthConstruct extends Construct {
readonly userPool: cognito.UserPool;
readonly userPoolClient: cognito.UserPoolClient;
constructor(scope: Construct, id: string) {
super(scope, id);
this.userPool = new cognito.UserPool(this, 'UserPool', {
selfSignUpEnabled: true,
signInAliases: { email: true },
autoVerify: { email: true },
standardAttributes: {
email: { required: true, mutable: true },
},
passwordPolicy: {
minLength: 8,
requireLowercase: true,
requireUppercase: true,
requireDigits: true,
requireSymbols: false,
},
accountRecovery: cognito.AccountRecovery.EMAIL_ONLY,
removalPolicy: cdk.RemovalPolicy.DESTROY,
});
this.userPoolClient = this.userPool.addClient('WebClient', {
authFlows: {
userSrp: true,
userPassword: false,
},
preventUserExistenceErrors: true,
});
new cdk.CfnOutput(this, 'UserPoolId', { value: this.userPool.userPoolId });
new cdk.CfnOutput(this, 'UserPoolClientId', { value: this.userPoolClient.userPoolClientId });
}
}