This commit is contained in:
paritosh18
2025-11-14 16:58:57 +05:30
2 changed files with 14 additions and 8 deletions

View File

@@ -9,7 +9,8 @@ import { ROLE } from '@/common/utils/constants/common.constant';
const prisma = new PrismaClient();
interface DecodedToken {
id: number;
id?: number;
sub?: string | number;
role?: string;
iat: number;
exp: number;
@@ -36,15 +37,17 @@ export async function verifyMinglarAdminToken(token: string): Promise<{ id: numb
}
try {
const decoded = jwt.verify(token, config.jwt.secret) as DecodedToken;
const decoded = jwt.verify(token, config.jwt.secret) as unknown as DecodedToken;
if (!decoded?.id) {
const userId = decoded.id ?? (decoded.sub ? Number(decoded.sub) : null);
if (!userId) {
throw new ApiError(httpStatus.UNAUTHORIZED, 'Invalid token payload');
}
// ✅ Fetch user from Prisma (Host user only)
const user = await prisma.user.findUnique({
where: { id: decoded.id },
where: { id: userId },
include: { role: true },
});

View File

@@ -9,7 +9,8 @@ import { ROLE } from '@/common/utils/constants/common.constant';
const prisma = new PrismaClient();
interface DecodedToken {
id: number;
id?: number;
sub?: string | number;
role?: string;
iat: number;
exp: number;
@@ -36,15 +37,17 @@ export async function verifyUserToken(token: string): Promise<{ id: number; role
}
try {
const decoded = jwt.verify(token, config.jwt.secret) as DecodedToken;
const decoded = jwt.verify(token, config.jwt.secret) as unknown as DecodedToken;
if (!decoded?.id) {
const userId = decoded.id ?? (decoded.sub ? Number(decoded.sub) : null);
if (!userId) {
throw new ApiError(httpStatus.UNAUTHORIZED, 'Invalid token payload');
}
// ✅ Fetch user from Prisma (Host user only)
const user = await prisma.user.findUnique({
where: { id: decoded.id },
where: { id: userId },
include: { role: true },
});