diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index 162adeb..9c06a7d 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -21,7 +21,7 @@ const Navbar: React.FC = ({ title }) => { ); } else if (sessionStatus === "unauthenticated") { return ( - ); @@ -40,40 +40,40 @@ const Navbar: React.FC = ({ title }) => { className="md:mr-2" src="/logo.webp" alt="Nav Logo" - width={ 32 } - height={ 32 } + width={32} + height={32} priority /> - { title } - { env.NEXT_PUBLIC_APP_ENV === "development" && " >> Staging" } + {title} + {env.NEXT_PUBLIC_APP_ENV === "development" && " >> Staging"} - { sessionStatus === "loading" ? ( + {sessionStatus === "loading" ? (
) : ( navigationMenu() - ) } + )} - { sessionData?.user.image && ( + {sessionData?.user.image && (
-
- ) } + )} ); }; diff --git a/src/server/ably.ts b/src/server/ably.ts index 986581e..3016f88 100644 --- a/src/server/ably.ts +++ b/src/server/ably.ts @@ -2,16 +2,12 @@ import Ably from "ably"; import { env } from "~/env.mjs"; import type { EventType } from "../utils/types"; -const ablyRest = new Ably.Rest(env.ABLY_PRIVATE_KEY); - -export const publishToChannel = ( +export const publishToChannel = async ( channel: string, event: EventType, message: string ) => { - try { - ablyRest.channels.get(`${env.APP_ENV}-${channel}`).publish(event, message); - } catch (error) { - console.log(`❌❌❌ Failed to send message!`); - } + const ably = new Ably.Rest.Promise(env.ABLY_PRIVATE_KEY); + const ablyChannel = ably.channels.get(`${env.APP_ENV}-${channel}`); + await ablyChannel.publish(event, message, { quickAck: true }); }; diff --git a/src/server/api/routers/room.ts b/src/server/api/routers/room.ts index d978278..abbfa9a 100644 --- a/src/server/api/routers/room.ts +++ b/src/server/api/routers/room.ts @@ -27,7 +27,7 @@ export const roomRouter = createTRPCRouter({ await invalidateCache(`kv_roomcount_admin`); await invalidateCache(`kv_roomlist_${ctx.session.user.id}`); - publishToChannel( + await publishToChannel( `${ctx.session.user.id}`, "ROOM_LIST_UPDATE", "CREATE" @@ -201,7 +201,7 @@ export const roomRouter = createTRPCRouter({ }); if (newRoom) { - publishToChannel(`${newRoom.id}`, "ROOM_UPDATE", "UPDATE"); + await publishToChannel(`${newRoom.id}`, "ROOM_UPDATE", "UPDATE"); } return !!newRoom; @@ -222,13 +222,13 @@ export const roomRouter = createTRPCRouter({ await invalidateCache(`kv_votecount_admin`); await invalidateCache(`kv_roomlist_${ctx.session.user.id}`); - publishToChannel( + await publishToChannel( `${ctx.session.user.id}`, "ROOM_LIST_UPDATE", "DELETE" ); - publishToChannel(`${deletedRoom.id}`, "ROOM_UPDATE", "DELETE"); + await publishToChannel(`${deletedRoom.id}`, "ROOM_UPDATE", "DELETE"); } return !!deletedRoom; diff --git a/src/server/api/routers/vote.ts b/src/server/api/routers/vote.ts index 6f48387..388d1f9 100644 --- a/src/server/api/routers/vote.ts +++ b/src/server/api/routers/vote.ts @@ -100,7 +100,7 @@ export const voteRouter = createTRPCRouter({ await invalidateCache(`kv_votecount_admin`); await invalidateCache(`kv_votes_${input.roomId}`); - publishToChannel(`${vote.roomId}`, "VOTE_UPDATE", "UPDATE"); + await publishToChannel(`${vote.roomId}`, "VOTE_UPDATE", "UPDATE"); } return !!vote; diff --git a/src/server/api/trpc.ts b/src/server/api/trpc.ts index 48e063b..79a7f16 100644 --- a/src/server/api/trpc.ts +++ b/src/server/api/trpc.ts @@ -118,7 +118,7 @@ const enforceRouteProtection = t.middleware(async ({ ctx, next }) => { const { success } = await rateLimit.limit( `${env.APP_ENV}_${ctx.session.user.id}` ); - console.log(success); + if (!success) throw new TRPCError({ code: "TOO_MANY_REQUESTS" }); return next({