Init
Build and Push Telemt Panel Docker Image / build-and-push (push) Failing after 38s
Build and Push Telemt Panel Docker Image / create-release (push) Skipped

This commit is contained in:
Denozordec
2026-08-04 18:33:48 +07:00
commit b5f31c1083
227 changed files with 31375 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
import type { FastifyReply, FastifyRequest } from 'fastify'
import { eq } from 'drizzle-orm'
import { operators } from '@telemt/db'
export interface AuthOperator {
id: string
username: string
role: string
}
declare module '@fastify/jwt' {
interface FastifyJWT {
payload: { sub: string; username: string; role: string }
user: { sub: string; username: string; role: string }
}
}
export async function requireAuth(request: FastifyRequest, reply: FastifyReply) {
try {
await request.jwtVerify()
} catch {
return reply.code(401).send({ error: { code: 'unauthorized', message: 'Требуется вход' } })
}
const row = request.server.db
.select()
.from(operators)
.where(eq(operators.id, request.user.sub))
.get()
if (!row || row.disabled) {
return reply.code(401).send({ error: { code: 'unauthorized', message: 'Оператор недоступен' } })
}
;(request as FastifyRequest & { operator: AuthOperator }).operator = {
id: row.id,
username: row.username,
role: row.role,
}
}
export function getOperator(request: FastifyRequest): AuthOperator {
return (request as FastifyRequest & { operator: AuthOperator }).operator
}