Skip to content

Drew-Kimberly/udagram-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Udagram Auth

An authentication lib for the Udagram app.

This packaged is maintained via the Udagram Monorepo

npm version

Usage

UdagramJWT

This module exports the class UdagramJWT<P extends UdagramJWTPayload> which is a small abstraction around JWT. The available API includes:

generateToken(payload: P): string

Generates a signed JWT token given a payload.

verifyToken(token: string, callback?: VerifyCallback): void

Verifies the provided JWT token. Verification logic is provided by the callback parameter, which is documented in the JWT library here.

requireAuth

This module exports an ExpressJS middleware handler:

const requireAuth = (
  jwt: UdagramJWT<UdagramJWTPayload>
): RequestHandler => (req: Request, res: Response, next: NextFunction);

This middleware will verify that incoming API requests have an Authorization header and that the provided token satisfies the given JWT. For example:

import express from 'express';
import {requireAuth, UdagramJWT} from '@drewkimberly/udagram-auth'

const app = express();
app.get('/', requireAuth(new UdagramJWT('my-secret')), async (req, res) => {
  res.send('JWT Token Verified!');
});

About

An authentication package for the Udagram app

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published