mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-27 16:18:10 +03:00
22 lines
720 B
TypeScript
22 lines
720 B
TypeScript
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
|
import { TelegrafExecutionContext } from '../../../lib/execution-context/telegraf-execution-context';
|
|
import { Context } from '../../interfaces/context.interface';
|
|
import { TelegrafException } from '../../../lib/errors';
|
|
|
|
@Injectable()
|
|
export class AdminGuard implements CanActivate {
|
|
private readonly ADMIN_IDS = [];
|
|
|
|
canActivate(context: ExecutionContext): boolean {
|
|
const ctx = TelegrafExecutionContext.create(context);
|
|
const { from } = ctx.getContext<Context>();
|
|
|
|
const isAdmin = this.ADMIN_IDS.includes(from.id);
|
|
if (!isAdmin) {
|
|
throw new TelegrafException('You are not admin >:(');
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|