fix: use auth.users UUID for trade role matching

telegram-auth now returns auth_user_id alongside public.users data.
TradeView uses authUserId (auth.users UUID) to match buyer_id/seller_id,
fixing missing action buttons (mark paid, confirm, cancel).
This commit is contained in:
2026-02-27 01:51:14 +03:00
parent 8c36b832b8
commit 556b850ec2
2 changed files with 8 additions and 4 deletions
+4 -4
View File
@@ -36,7 +36,7 @@ const STATUS_CONFIG: Record<string, { color: string; icon: typeof Clock }> = {
}; };
export function TradeView({ tradeId, onBack }: TradeViewProps) { export function TradeView({ tradeId, onBack }: TradeViewProps) {
const { sessionToken, user } = useAuth(); const { sessionToken, authUserId } = useAuth();
const { t, isRTL } = useTranslation(); const { t, isRTL } = useTranslation();
const { hapticImpact, hapticNotification } = useTelegram(); const { hapticImpact, hapticNotification } = useTelegram();
@@ -47,9 +47,9 @@ export function TradeView({ tradeId, onBack }: TradeViewProps) {
const [showDispute, setShowDispute] = useState(false); const [showDispute, setShowDispute] = useState(false);
const [error, setError] = useState(''); const [error, setError] = useState('');
const userId = user?.id; // authUserId = auth.users UUID (matches trade.buyer_id / trade.seller_id)
const isBuyer = trade?.buyer_id === userId; const isBuyer = trade?.buyer_id === authUserId;
const isSeller = trade?.seller_id === userId; const isSeller = trade?.seller_id === authUserId;
const fetchTrade = useCallback(async () => { const fetchTrade = useCallback(async () => {
if (!sessionToken || !tradeId) return; if (!sessionToken || !tradeId) return;
+4
View File
@@ -12,6 +12,7 @@ import type { User } from '@/hooks/useSupabase';
interface AuthContextType { interface AuthContextType {
user: User | null; user: User | null;
authUserId: string | null;
sessionToken: string | null; sessionToken: string | null;
isLoading: boolean; isLoading: boolean;
isAuthenticated: boolean; isAuthenticated: boolean;
@@ -49,6 +50,7 @@ function waitForInitData(maxAttempts = 25, intervalMs = 200): Promise<string | n
export function AuthProvider({ children }: { children: ReactNode }) { export function AuthProvider({ children }: { children: ReactNode }) {
const [user, setUser] = useState<User | null>(null); const [user, setUser] = useState<User | null>(null);
const [authUserId, setAuthUserId] = useState<string | null>(null);
const [sessionToken, setSessionToken] = useState<string | null>(null); const [sessionToken, setSessionToken] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [authError, setAuthError] = useState<string | null>(null); const [authError, setAuthError] = useState<string | null>(null);
@@ -70,6 +72,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
const result = await signInWithTelegram(initData); const result = await signInWithTelegram(initData);
if (result?.user) { if (result?.user) {
setUser(result.user); setUser(result.user);
setAuthUserId(result.auth_user_id || null);
setAuthError(null); setAuthError(null);
} else { } else {
setAuthError('No user returned from auth'); setAuthError('No user returned from auth');
@@ -98,6 +101,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
<AuthContext.Provider <AuthContext.Provider
value={{ value={{
user, user,
authUserId,
sessionToken, sessionToken,
isLoading, isLoading,
isAuthenticated: !!user, isAuthenticated: !!user,