sse bug fix
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
||||
import { ChangeEvent, dbEvents } from "../realtime";
|
||||
import { hasValidClaims } from "../auth";
|
||||
import { Claim } from "../utils/claims";
|
||||
|
||||
export async function realTimeRoutes(fastify: FastifyInstance) {
|
||||
fastify.get("/events", async (req: FastifyRequest, res: FastifyReply) => {
|
||||
@@ -13,9 +14,8 @@ export async function realTimeRoutes(fastify: FastifyInstance) {
|
||||
res.raw.setHeader("Connection", "keep-alive");
|
||||
res.raw.flushHeaders();
|
||||
|
||||
dbEvents.on("change", (event: ChangeEvent) => {
|
||||
if (hasValidClaims(req.user, event.requiredClaims)) {
|
||||
delete event.requiredClaims;
|
||||
dbEvents.on("change", (event: ChangeEvent, requiredClaims: Claim[]) => {
|
||||
if (hasValidClaims(req.user, requiredClaims)) {
|
||||
res.raw.write(JSON.stringify(event));
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user