mirror of
https://github.com/complexcaresolutions/telegram-media-bot.git
synced 2026-03-17 16:13:42 +00:00
17 lines
566 B
TypeScript
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();
|
|
}
|