mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 22:51:14 -05:00
Implement unban functionality
This commit is contained in:
@@ -107,7 +107,12 @@ export function ProfileManager() {
|
||||
|
||||
if (logError) logger.error('Failed to log admin action', { error: getErrorMessage(logError) });
|
||||
|
||||
handleSuccess('Success', `User ${ban ? 'banned' : 'unbanned'} successfully.`);
|
||||
handleSuccess(
|
||||
'Success',
|
||||
ban
|
||||
? 'User banned successfully. They have been signed out and cannot access the application.'
|
||||
: 'User unbanned successfully. They can now access the application normally.'
|
||||
);
|
||||
|
||||
// Refresh profiles
|
||||
fetchProfiles();
|
||||
|
||||
@@ -46,7 +46,7 @@ export function useBanCheck() {
|
||||
|
||||
checkBan();
|
||||
|
||||
// Subscribe to profile changes (real-time ban detection)
|
||||
// Subscribe to profile changes (real-time ban/unban detection)
|
||||
const channel = supabase
|
||||
.channel('ban-check')
|
||||
.on(
|
||||
@@ -58,7 +58,10 @@ export function useBanCheck() {
|
||||
filter: `user_id=eq.${user.id}`
|
||||
},
|
||||
(payload) => {
|
||||
if (payload.new && (payload.new as { banned: boolean }).banned) {
|
||||
const newProfile = payload.new as { banned: boolean };
|
||||
|
||||
// Handle BAN event
|
||||
if (newProfile.banned && !isBanned) {
|
||||
setIsBanned(true);
|
||||
toast({
|
||||
title: 'Account Suspended',
|
||||
@@ -69,6 +72,17 @@ export function useBanCheck() {
|
||||
supabase.auth.signOut();
|
||||
navigate('/');
|
||||
}
|
||||
|
||||
// Handle UNBAN event
|
||||
if (!newProfile.banned && isBanned) {
|
||||
setIsBanned(false);
|
||||
toast({
|
||||
title: 'Account Restored',
|
||||
description: 'Your account has been unbanned. You can now use the application normally.',
|
||||
variant: 'default',
|
||||
duration: 8000
|
||||
});
|
||||
}
|
||||
}
|
||||
)
|
||||
.subscribe();
|
||||
|
||||
Reference in New Issue
Block a user