first commit

This commit is contained in:
NAME
2026-05-14 08:42:03 +00:00
commit 5f16ed135d
167 changed files with 29178 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
// auth.guard.ts
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { TelegrafExecutionContext } from 'nestjs-telegraf';
@Injectable()
export class AuthGuard implements CanActivate {
// Danh sách ID được phép (có thể để trong file .env)
private readonly allowedIds =(process.env.TELEGRAM_ALLOW_CHAT_IDS || '').split(',');
canActivate(context: ExecutionContext): boolean {
console.log('AuthGuard');
const ctx = TelegrafExecutionContext.create(context);
const { chat } = ctx.getContext();
// Kiểm tra nếu chat_id nằm trong danh sách cho phép
const isAllowed = this.allowedIds.includes(chat.id);
if (!isAllowed) {
console.warn(`Truy cập trái phép từ ID: ${chat.id}`);
}
return isAllowed;
}
}