feat: add sample endpoint to test JWT

This commit is contained in:
2026-01-03 04:37:20 +01:00
parent ec5cedce5a
commit c19a098b1c
8 changed files with 173 additions and 15 deletions

View File

@@ -2,7 +2,7 @@
// https://github.com/TomDoesTech/REST-API-Tutorial-Updated/blob/7b5f040e1acd94d267df585516b33ee7e3b75f70/src/middleware/deserializeUser.ts
import { get } from 'lodash';
import { Request, Response, NextFunction } from 'express';
import { verifyJwt } from '../tools/jwt';
import * as jwt from '../tools/jwt';
const inferUser = async (
req: Request,
@@ -17,12 +17,9 @@ const inferUser = async (
if (!accessToken) return next();
const { decoded } = verifyJwt(accessToken, 'accessTokenPublicKey');
// console.log('decoded user:', decoded);
if (decoded) {
res.locals.user = decoded;
const token = jwt.verifyJwt(accessToken, 'accessTokenPrivateKey');
if (token) {
res.locals.user = token;
return next();
}