mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 18:31:11 -05:00
Add ban reason to profiles
This commit is contained in:
@@ -104,6 +104,31 @@ export default function Auth() {
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
// CRITICAL: Check ban status immediately after successful authentication
|
||||
const { data: profile } = await supabase
|
||||
.from('profiles')
|
||||
.select('banned, ban_reason')
|
||||
.eq('user_id', data.user.id)
|
||||
.single();
|
||||
|
||||
if (profile?.banned) {
|
||||
// Sign out immediately
|
||||
await supabase.auth.signOut();
|
||||
|
||||
const reason = profile.ban_reason
|
||||
? `Reason: ${profile.ban_reason}`
|
||||
: 'Contact support for assistance.';
|
||||
|
||||
toast({
|
||||
variant: "destructive",
|
||||
title: "Account Suspended",
|
||||
description: `Your account has been suspended. ${reason}`,
|
||||
duration: 10000
|
||||
});
|
||||
setLoading(false);
|
||||
return; // Stop authentication flow
|
||||
}
|
||||
|
||||
// Check if MFA is required (user exists but no session)
|
||||
if (data.user && !data.session) {
|
||||
const totpFactor = data.user.factors?.find(f => f.factor_type === 'totp' && f.status === 'verified');
|
||||
|
||||
@@ -51,6 +51,31 @@ export default function AuthCallback() {
|
||||
|
||||
const user = session.user;
|
||||
|
||||
// CRITICAL: Check ban status immediately after getting session
|
||||
const { data: banProfile } = await supabase
|
||||
.from('profiles')
|
||||
.select('banned, ban_reason')
|
||||
.eq('user_id', user.id)
|
||||
.single();
|
||||
|
||||
if (banProfile?.banned) {
|
||||
await supabase.auth.signOut();
|
||||
|
||||
const reason = banProfile.ban_reason
|
||||
? `Reason: ${banProfile.ban_reason}`
|
||||
: 'Contact support for assistance.';
|
||||
|
||||
toast({
|
||||
variant: 'destructive',
|
||||
title: 'Account Suspended',
|
||||
description: `Your account has been suspended. ${reason}`,
|
||||
duration: 10000
|
||||
});
|
||||
|
||||
navigate('/auth');
|
||||
return; // Stop OAuth processing
|
||||
}
|
||||
|
||||
// Check if this is a new OAuth user (created within last minute)
|
||||
const createdAt = new Date(user.created_at);
|
||||
const now = new Date();
|
||||
|
||||
Reference in New Issue
Block a user