added ban redirect correctly
All checks were successful
Build Frontend / Build Frontend (push) Successful in 17s

This commit is contained in:
2026-01-11 03:42:35 +00:00
parent aca0aca310
commit 5846541329
2 changed files with 49 additions and 0 deletions

View File

@@ -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;

View File

@@ -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