Nerdy Pun Mavens

    @reapit/api-key-verify

    0.0.3 • Public • Published

    Api-key-verify

    Install

    $ yarn add @reapit/api-key-verify

    Get the api key

    import { getApiKey } from '@reapit/api-key-verify'
    import { DynamoDB } from 'aws-sdk'
    import { DataMapper } from '@aws/dynamodb-data-mapper'
    
    const dynamoMapper = new DataMapper({
      client: new DynamoDB(),
    })
    
    const apiKey = getApiKey(dynamoMapper)('x-api-key-from-your-header')
    
    console.log(apiKey) // undefined || ApiKeyModel

    validating apiKey

    this function will return the api key or throw an exception

    import { resolveApiKey } from '@reapit/api-key-verify'
    import { DynamoDB } from 'aws-sdk'
    import { DataMapper } from '@aws/dynamodb-data-mapper'
    
    const dynamoMapper = new DataMapper({
      client: new DynamoDB(),
    })
    
    export const myLambda = (req, res) => {
    
      try {
        const apiKey = resolveApiKey(dynamoMapper)(req.headers['x-api-key'])
      } catch(e: ApiKeyExpiredException | ApiKeyNotFoundException) {
        res.statusCode(401)
        res.send(e.message) // not found || expired
      }
    }

    Keywords

    none

    Install

    npm i @reapit/api-key-verify

    DownloadsWeekly Downloads

    2

    Version

    0.0.3

    License

    MIT

    Unpacked Size

    62 kB

    Total Files

    24

    Last publish

    Collaborators

    • wmcvayreapit
    • dawsonscott