Once you have added the middleware to your route, use authenticatedRequestHandler to provide
type-safe access to req.user in your downstream RequestHandler functions.
// Define an authenticated route handler constgetUserProfile = async (req: ExpressAuthHelpers['AuthenticatedRequest'], res: Response) => { // Access authenticated user information const { pkpAddress } = req.user;
// Fetch and return user data constuserData = awaituserRepository.findByAddress(pkpAddress); res.json(userData); };
// Use in Express route with authentication app.get('/profile', authenticateUser, authenticatedRequestHandler(getUserProfile));
You can see the source for getAuthenticateUserExpressHandler() below; use this as a reference to implement
your own midddleware/authentication for other frameworks! Pull requests are welcome.
expressAuthHelpers are used to add a VincentJWT-specific authentication to your Express.js server routes
req.user
in your downstream RequestHandler functions.Example
You can see the source for
getAuthenticateUserExpressHandler()
below; use this as a reference to implement your own midddleware/authentication for other frameworks! Pull requests are welcome.