npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@vizmedia/cognito-nest-api

v0.1.3

Published

Easily configurable NestJS API module to connect to AWS Cognito

Downloads

11

Readme

Cognito Nest API Module

npm version

Description

Cognito Nest API Module is a NestJS module designed to integrate with AWS Cognito, providing support for managing JWT tokens on the server-side API. The module is built with security in mind, minimizing the exposure of sensitive tokens to the frontend.

Key Features

  • AWS Cognito Integration: Easily connect to AWS Cognito for user authentication and session management.
  • Secure JWT Management: The module securely stores all three tokens (Access, ID, Refresh) returned by AWS Cognito in a server-side repository, inaccessible to the frontend client. Except IdToken.
  • ID Token Handling: To enhance security, only the JWT ID Token is sent to the frontend, while the Access Token is kept server-side, protecting access to AWS resources.
  • Refresh Token Support: The module automatically handles token refreshing. When a token expires, the first request after expiration is processed, and a new token is returned in the X-Refresh-Token-Updated header. The client can seamlessly update the ID Token without the need to manually refresh or handle errors due to token expiration.
  • flow control: the response from the API provides a list of form windows that should be active in the current session state.

The module provides the following endpoints:

/cognito/register

/cognito/confirm-registration

/cognito/signin

/cognito/signinsession

/cognito/userinfo

/cognito/enablemfa

/cognito/addphonenumber

/cognito/addemail

/cognito/verifyproperty

/cognito/disablemfa

/cognito/signout

/cognito/initiate-password-reset

/cognito/confirm-password-reset

/cognito/change-password

Installation

Install the package via npm:

npm install @vizmedia/cognito-nest-api


## Usage

```typescript
...
import { CognitoModule } from '@vizmedia/cognito-nest-api';

@Module({
  imports: [
  VizCognitoModule.forRoot({
      region: process.env.REGION,
      userPoolId: process.env.COGNITO_USER_POOL_ID,
      clientId: process.env.COGNITO_USER_POOL_CLIENT_ID,
      identityPoolId: process.env.COGNITO_IDENTITY_POOL_ID,
      clientSecret: process.env.COGNITO_USER_POOL_CLIENT_SECRET,
      dbConfig: {
        type: "mongodb",
        host: process.env.DB_HOST,
        //port: parseInt(process.env.DB_PORT, 10),
        port: 3010,
        username: process.env.DB_USERNAME,
        password: process.env.DB_PASSWORD,
        database: process.env.DB_DATABASE,
      },
    }),
    ...
    ],
})
export class AppModule {}

you must use guard on every endpoint that requires token verification


@UseGuards(VizCognitoGuard)