@simple-cdk/cognito
v4.2.4
Published
simple-cdk adapter: Cognito user pool with auto-discovered Lambda triggers and app client.
Downloads
1,311
Maintainers
Readme
@simple-cdk/cognito
simple-cdk adapter that creates a Cognito user pool, an app client, and auto-discovers Lambda triggers from the filesystem.
Install
npm install @simple-cdk/cognito @simple-cdk/core aws-cdk-lib constructsConvention
Each Cognito trigger is a folder under backend/triggers/<trigger-name>/:
backend/triggers/
├── pre-token-generation/
│ └── handler.ts
├── post-confirmation/
│ └── handler.ts
└── pre-sign-up/
└── handler.tsFolder names must match a known Cognito trigger:
pre-sign-up, post-confirmation, pre-authentication, post-authentication,
pre-token-generation, custom-message, define-auth-challenge,
create-auth-challenge, verify-auth-challenge, user-migration.
Usage
import { defineConfig } from '@simple-cdk/core';
import { cognitoAdapter } from '@simple-cdk/cognito';
export default defineConfig({
app: 'my-app',
stages: { dev: { region: 'us-east-1' } },
adapters: [
cognitoAdapter({
// userPoolName: 'my-pool', // default: '<app>-<stage>-users'
triggersDir: 'backend/triggers', // default
stackName: 'auth',
signInAlias: 'email',
selfSignUp: true,
mfa: 'off', // 'off' | 'optional' | 'required'
// mfaSecondFactor: { sms: true, otp: true }, // second factors when MFA on
// userVerification: { emailSubject: '...', emailBody: '...' },
// clientAuthFlows: { custom: true }, // for define/create/verify-auth-challenge OTP flow
passwordPolicy: { minLength: 12, requireSymbols: true },
}),
],
});Cross-adapter lookup
import { getUserPool, getUserPoolClient } from '@simple-cdk/cognito';
// inside another adapter's wire():
const pool = getUserPool(ctx);
const client = getUserPoolClient(ctx);Full docs at the main repo.
