telegram-media-bot/src/middleware/auth.ts
2026-03-01 09:19:31 +00:00

17 lines
566 B
TypeScript

import { type Context, type NextFunction } from 'grammy';
import { config } from '../config.js';
import { createLogger } from '../utils/logger.js';
const log = createLogger('Auth');
export async function authMiddleware(ctx: Context, next: NextFunction): Promise<void> {
const userId = ctx.from?.id;
if (!userId || !config.telegram.allowedUserIds.includes(userId)) {
log.warn(`Unauthorized access attempt from user ${userId || 'unknown'}`);
await ctx.reply('⛔ Du bist nicht autorisiert, diesen Bot zu verwenden.');
return;
}
await next();
}