Audit table with better data

This commit is contained in:
2026-01-28 13:28:05 -06:00
parent 936471542a
commit 13cc4528ff
5 changed files with 300 additions and 89 deletions

View File

@@ -1,10 +1,14 @@
import jwt, { JwtPayload, SignOptions, VerifyOptions } from 'jsonwebtoken';
import jwt, { SignOptions, VerifyOptions } from 'jsonwebtoken';
import config from '../config';
import logger from './logger';
import type { JwtPayload } from '../types';
interface TokenPayload {
id: string;
userId?: string;
email?: string;
roleId?: string;
roleName?: string;
id?: string;
role?: string;
[key: string]: unknown;
}
@@ -58,7 +62,7 @@ export const generateRefreshToken = (payload: TokenPayload): string => {
* @param token - JWT access token to verify
* @returns Decoded payload if valid, null if invalid or expired
*/
export const verifyAccessToken = (token: string): JwtPayload | null => {
export const verifyAccessToken = (token: string): any => {
const options: VerifyOptions = {
algorithms: ['HS256'],
};
@@ -68,7 +72,7 @@ export const verifyAccessToken = (token: string): JwtPayload | null => {
token,
config.jwt.accessTokenSecret,
options
) as JwtPayload;
);
return decoded;
} catch (error) {
if (error instanceof jwt.TokenExpiredError) {
@@ -91,7 +95,7 @@ export const verifyAccessToken = (token: string): JwtPayload | null => {
* @param token - JWT refresh token to verify
* @returns Decoded payload if valid, null if invalid or expired
*/
export const verifyRefreshToken = (token: string): JwtPayload | null => {
export const verifyRefreshToken = (token: string): any => {
const options: VerifyOptions = {
algorithms: ['HS256'],
};
@@ -101,7 +105,7 @@ export const verifyRefreshToken = (token: string): JwtPayload | null => {
token,
config.jwt.refreshTokenSecret,
options
) as JwtPayload;
);
return decoded;
} catch (error) {
if (error instanceof jwt.TokenExpiredError) {
@@ -124,9 +128,9 @@ export const verifyRefreshToken = (token: string): JwtPayload | null => {
* @param token - JWT token to decode
* @returns Decoded payload or null
*/
export const decodeToken = (token: string): JwtPayload | null => {
export const decodeToken = (token: string): any => {
try {
const decoded = jwt.decode(token) as JwtPayload | null;
const decoded = jwt.decode(token);
return decoded;
} catch (error) {
logger.error('Error decoding token', {