diff --git a/frontend/src/stores/websocket.js b/frontend/src/stores/websocket.js index 82900b7..dc59759 100644 --- a/frontend/src/stores/websocket.js +++ b/frontend/src/stores/websocket.js @@ -220,6 +220,28 @@ export const useWebSocketStore = defineStore("websocket", () => { authStore.fetchUser(); break; + case "account_banned": + console.log("🔨 User account has been banned:", payload); + // Update the auth store - router guard will handle redirect + authStore.fetchUser().then(() => { + // Disconnect WebSocket since user is banned + disconnect(); + // The router guard will automatically redirect to /banned page + // because authStore.isBanned will now be true + window.location.href = "/banned"; + }); + break; + + case "account_unbanned": + console.log("✅ User account has been unbanned:", payload); + // Update the auth store to reflect unbanned status + authStore.fetchUser().then(() => { + // Redirect to home page + window.location.href = "/"; + toast.success("Your account has been unbanned. Welcome back!"); + }); + break; + case "pong": // Heartbeat response break; diff --git a/routes/admin-management.js b/routes/admin-management.js index 7044e3c..ce4e9f9 100644 --- a/routes/admin-management.js +++ b/routes/admin-management.js @@ -4,6 +4,7 @@ import Transaction from "../models/Transaction.js"; import SiteConfig from "../models/SiteConfig.js"; import PromoUsage from "../models/PromoUsage.js"; import { v4 as uuidv4 } from "uuid"; +import wsManager from "../utils/websocket.js"; /** * Admin management routes for user administration and site configuration @@ -414,6 +415,32 @@ export default async function adminManagementRoutes(fastify, options) { }` ); + // Send WebSocket notification to the user if they're connected + if (wsManager.isUserConnected(user.steamId)) { + if (banned) { + wsManager.sendToUser(user.steamId, { + type: "account_banned", + data: { + banned: true, + reason: user.ban.reason, + bannedAt: new Date(), + bannedUntil: user.ban.expires, + }, + timestamp: Date.now(), + }); + console.log(`📡 Sent ban notification to user ${user.username}`); + } else { + wsManager.sendToUser(user.steamId, { + type: "account_unbanned", + data: { + banned: false, + }, + timestamp: Date.now(), + }); + console.log(`📡 Sent unban notification to user ${user.username}`); + } + } + return reply.send({ success: true, message: banned