An authentication lib for the Udagram app.
This packaged is maintained via the Udagram Monorepo
This module exports the class UdagramJWT<P extends UdagramJWTPayload>
which is a small abstraction
around JWT. The available API includes:
Generates a signed JWT token given a payload.
Verifies the provided JWT token. Verification logic is provided by the callback
parameter, which is documented in the JWT library here.
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!');
});