A short and easy boilerplate showcasing JWT auth with Nodejs, the Serverless framework, MongoDB and AWS Lambda.
- The
authfolder has aVerifyToken.jsfile which is the base of the authorizer function. - The
VerifyToken.authmethod is added to the authorizer field in theserverless.ymlfor API Gateway routes you wish to keep private. See themefunction.AuthHandler.meusesevent.requestContext.authorizer.principalIdto access theuserIdof the user accessing the resource if the JWT is valid. Otherwise returns'Unauthorized'.
Note: The concept of middlewares can be applied to this for understanding it easily.