diff options
Diffstat (limited to 'src/middleware.ts')
| -rw-r--r-- | src/middleware.ts | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/middleware.ts b/src/middleware.ts index bdc006a..e2814e0 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -1,5 +1,18 @@ -import { NextFunction, Request, Response } from "@tinyhttp/app"; +import { Context } from "telegraf"; +import config from "./config"; -export const auth = async (_req: Request, _res: Response, next: NextFunction): Promise<void> => { - await next(); +const auth = async (ctx: Context, next: () => Promise<void>): Promise<void> => { + const userId = ctx.message?.from.id; + + if (!userId || !config.tgUserIds.includes(userId)) { + ctx.reply("Käyttäjälläsi ei ole oikeuksia startata HommaBottia."); + } else { + await next(); + } +}; + +export const tgMiddleware = { + auth, }; + +export const httpMiddleware = {}; |
