Implementing SMS panel in Super Admin

This commit is contained in:
2026-08-05 14:13:44 +03:30
parent b66e47c3b3
commit 14d9c5d143
8 changed files with 338 additions and 3 deletions
+8
View File
@@ -0,0 +1,8 @@
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
export const RemoteTenant = createParamDecorator(
(_data: unknown, ctx: ExecutionContext) => {
const req = ctx.switchToHttp().getRequest();
return req.remoteTenant;
},
);
+44
View File
@@ -0,0 +1,44 @@
import {
CanActivate,
ExecutionContext,
Injectable,
UnauthorizedException,
} from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
@Injectable()
export class RemoteTokenGuard implements CanActivate {
constructor(private readonly prisma: PrismaService) {}
async canActivate(context: ExecutionContext): Promise<boolean> {
const req = context.switchToHttp().getRequest();
const header = String(req.headers?.authorization || '');
const match = /^Bearer\s+(.+)$/i.exec(header.trim());
const token = match?.[1]?.trim();
if (!token || token.length < 16) {
throw new UnauthorizedException('توکن نسخه نامعتبر است');
}
const tenant = await this.prisma.tenant.findFirst({
where: {
remoteApiToken: token,
isActive: true,
},
select: {
id: true,
nameFa: true,
domain: true,
product: true,
isActive: true,
},
});
if (!tenant) {
throw new UnauthorizedException('توکن نسخه نامعتبر است');
}
req.remoteTenant = tenant;
return true;
}
}